List of usage examples for java.io PrintWriter print
public void print(Object obj)
From source file:es.eucm.mokap.backend.server.MokapBackend.java
/** * Method: GET Processes get requests to perform a search. It performs an * index search with the keyword in that header. Requires a valid api key to * work./*from w ww . j a v a 2s . co m*/ */ @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) { MokapSearchController sCont = new MokapSearchController(); // Check api key try { if (!ApiKeyVerifier.checkApiKey(req, resp)) { PrintWriter out = resp.getWriter(); out.print("Wrong API key."); out.flush(); out.close(); } else { PrintWriter out = resp.getWriter(); // Get the parameters from the header / parameter SearchParams sp = SearchParamsFactory.create(req); String str = sCont.performSearch(sp); // Set the response encoding resp.setCharacterEncoding("UTF-8"); resp.setContentType("application/json"); out.print(str); out.flush(); out.close(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:net.mohatu.bloocoin.miner.RegisterClass.java
private void saveBloostamp() { try {//from ww w . j a va2 s . co m PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("bloostamp"))); out.print(addr + ":" + key); out.close(); MainView.loadDataPub(); } catch (IOException e) { System.out.println("Saving of bloostamp file failed, check permissions."); } }
From source file:cc.kune.core.server.rack.filters.rest.CORSServiceFilter.java
@Override protected void customDoFilter(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws IOException, ServletException { final boolean cors = (Boolean) request.getAttribute("cors.isCorsRequest"); // This part is similar to RESTServiceFilter final String methodName = RackHelper.getMethodName(request, pattern); final ParametersAdapter parameters = new ParametersAdapter(request); LOG.debug((cors ? "" : "NO ") + "CORS METHOD: '" + methodName + "' on: " + serviceClass.getSimpleName()); response.setCharacterEncoding("utf-8"); // See: http://software.dzhuvinov.com/cors-filter-tips.html response.setContentType("text/plain"); final RESTResult result = transactionalFilter.doService(serviceClass, methodName, parameters, getInstance(serviceClass));//from w w w. jav a2 s.c om if (result != null) { final Exception exception = result.getException(); if (exception != null) { if (exception instanceof InvocationTargetException && ((InvocationTargetException) exception) .getTargetException() instanceof ContentNotFoundException) { printMessage(response, HttpServletResponse.SC_NOT_FOUND, result.getException().getMessage()); } else { printMessage(response, HttpServletResponse.SC_BAD_REQUEST, result.getException().getMessage()); } } else { final String output = result.getOutput(); if (output != null) { final PrintWriter writer = response.getWriter(); writer.print(output); writer.flush(); } else { // Is not for us!!! } } } }
From source file:com.linuxbox.enkive.message.AbstractMessage.java
protected String getUnpatchedEmail() throws IOException { StringWriter out = new StringWriter(); PrintWriter writer = new PrintWriter(out); writer.print(originalHeaders); writer.flush();/*from w w w. ja v a2 s . com*/ contentHeader.pushReconstitutedEmail(writer); return out.toString(); }
From source file:net.bashtech.geobot.BotManager.java
public static String postRemoteDataSongRequest(String urlString, String channel, String requester) { if (BotManager.getInstance().CoeBotTVAPIKey.length() > 4) { URL url;/*from w ww .j a v a 2 s. c o m*/ HttpURLConnection conn; try { url = new URL("http://coebot.tv/api/v1/reqsongs/add/" + channel.toLowerCase() + "$" + BotManager.getInstance().CoeBotTVAPIKey + "$" + BotManager.getInstance().nick); String postData = "url=" + URLEncoder.encode(urlString, "UTF-8") + "&requestedBy=" + URLEncoder.encode(requester, "UTF-8"); conn = (HttpURLConnection) url.openConnection(); System.out.println(postData); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "CoeBot"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); conn.setRequestProperty("Content-Length", "" + Integer.toString(postData.getBytes().length)); // conn.setConnectTimeout(5 * 1000); // conn.setReadTimeout(5 * 1000); PrintWriter out = new PrintWriter(conn.getOutputStream()); out.print(postData); out.close(); String response = ""; if (conn.getResponseCode() < 400) { Scanner inStream = new Scanner(conn.getInputStream()); while (inStream.hasNextLine()) { response += (inStream.nextLine()); } inStream.close(); } else { Scanner inStream = new Scanner(conn.getErrorStream()); while (inStream.hasNextLine()) { response += (inStream.nextLine()); } inStream.close(); } System.out.println(response); return response; } catch (MalformedURLException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } return null; } else { return null; } }
From source file:com.linuxbox.enkive.message.AbstractMessage.java
@Override public void pushReconstitutedEmail(Writer output) throws IOException { PrintWriter writer = new PrintWriter(output); writer.print(getReconstitutedEmail()); writer.flush();/*ww w . ja va 2 s. c o m*/ }
From source file:de.mpg.escidoc.services.syndication.presentation.RestServlet.java
/** * Take care on an incoming exception./*from w w w. j a v a 2s .co m*/ * * @param e * exception * @param resp * response stream * @throws IOException * @throws Exception * if the handling went wrong on any reason */ private void handleException(final Exception e, final HttpServletResponse resp) throws IOException { logger.error(e.getMessage(), e); PrintWriter pw; pw = resp.getWriter(); pw.print("Error: "); e.printStackTrace(pw); pw.close(); }
From source file:es.eucm.mokap.backend.server.MokapBackend.java
/** * Method: POST Processes post requests. * // w ww . j a va 2 s.co m * <pre> * - Requests must be multipart/form-data. * - The field with the file must be named "file". * - The file must be a .zip compressed file with the structure * defined in {@link UploadZipStructure}. * </pre> */ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { MokapInsertController iCont = new MokapInsertController(); // Check api key if (!ApiKeyVerifier.checkApiKey(req, resp)) { return; } else { try { // Get the uploaded file stream FileItemStream fis = getUploadedFile(req); if (fis != null) { // Actually process the uploaded resource String str = iCont.processUploadedResource(fis); // Send the response PrintWriter out = resp.getWriter(); out.print(str); out.flush(); out.close(); } else { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, ServerReturnMessages.INVALID_UPLOAD_FILENOTFOUND); } } catch (Exception e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ServerReturnMessages.m(ServerReturnMessages.GENERIC_INTERNAL_ERROR, e.getMessage())); } } }
From source file:it.cilea.osd.jdyna.utils.ClassificationExportUtils.java
/** * Metodo di supporto per scrivere il DOCTYPE e il bean per il custom editor dell'albero classificatore * /*from www .j ava2 s.c om*/ * @param writer * @param albero * l'albero da esportare */ public void writeDocTypeANDCustomEditorAlberoClassificatore(PrintWriter writer) { writer.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN//EN\"\n" + "\"http://www.springframework.org/dtd/spring-beans.dtd\">\n\n\n"); writer.print("<beans>\n"); writer.print(" <!-- Configurazioni per il tool di import (NON MODIFICARE) -->\n"); writer.print( " <bean id=\"customEditorConfigurer\" class=\"org.springframework.beans.factory.config.CustomEditorConfigurer\">\n"); writer.print(" <property name=\"customEditors\">\n"); writer.print(" <map>\n"); writer.print(" <entry key=\"it.cilea.osd.jdyna.model.AlberoClassificatorio\">\n"); writer.print(" <ref bean=\"configurazioneAlberoClassificatorioEditor\"/>\n"); writer.print(" </entry>\n"); writer.print(" <entry key=\"it.cilea.osd.jdyna.model.Classificazione\">\n"); writer.print(" <ref bean=\"configurazioneClassificazioneEditor\"/>\n"); writer.print(" </entry>\n"); writer.print(" </map>\n"); writer.print(" </property>\n"); writer.print(" </bean>\n"); }
From source file:bookUtilities.HomePageBooksServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w w w . j a va 2 s . c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); //Get the top four most recently added books JSONArray newestBooks = getNewestBooks(); //Gets the top four most checked out books getPopularBooks(newestBooks); //Returns the data to the front end PrintWriter printout = response.getWriter(); printout.print(newestBooks); printout.flush(); }