List of usage examples for java.io PrintWriter close
public void close()
From source file:net.bashtech.geobot.BotManager.java
public static String postCoebotConfig(String postData, String channel) { if (BotManager.getInstance().CoeBotTVAPIKey.length() > 4) { URL url;/* www .j av a2 s . c o m*/ HttpURLConnection conn; try { url = new URL("http://coebot.tv/api/v1/channel/update/config/" + channel.toLowerCase() + "$" + BotManager.getInstance().CoeBotTVAPIKey + "$" + BotManager.getInstance().nick); conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "CoeBot"); conn.setRequestProperty("Content-Type", "application/json"); 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 = ""; Scanner inStream = new Scanner(conn.getInputStream()); while (inStream.hasNextLine()) response += (inStream.nextLine()); inStream.close(); return response; } catch (MalformedURLException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } return ""; } else return ""; }
From source file:net.bashtech.geobot.BotManager.java
public static String postCoebotVars(String postData, String requestURL) { if (BotManager.getInstance().CoeBotTVAPIKey.length() > 4) { URL url;/*from w ww .ja va 2s . c o m*/ HttpURLConnection conn; try { url = new URL(requestURL + "$" + BotManager.getInstance().CoeBotTVAPIKey + "$" + BotManager.getInstance().nick); conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "CoeBot"); conn.setRequestProperty("Content-Type", "application/json"); 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 = ""; Scanner inStream = new Scanner(conn.getInputStream()); while (inStream.hasNextLine()) response += (inStream.nextLine()); inStream.close(); return response; } catch (MalformedURLException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } return ""; } else return ""; }
From source file:gate.termraider.output.CsvGenerator.java
public void generateAndSaveCsv(AbstractTermbank termbank, double threshold, File outputFile) throws GateException { this.termbank = termbank; this.debugMode = termbank.getDebugMode(); this.scorePropertyName = termbank.getScoreProperty(); PrintWriter writer = initializeWriter(outputFile); generateCsv(writer, threshold);/*from w w w . j a v a 2s. co m*/ writer.flush(); writer.close(); if (debugMode) { System.out.println("Termbank: saved CSV in " + outputFile.getAbsolutePath()); } }
From source file:ob.servlet.gettaskinfo.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from www .j a v a 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 { outinfo = null; String loginedUserName = (String) request.getSession().getAttribute("username"); if (loginedUserName != null && !loginedUserName.equals("")) { int loginedUserid = (Integer) request.getSession().getAttribute("userid"); String tid = request.getParameter("tid"); if (tid != null) { po = dao.getTask(tid); if (po != null && po.getUid() == loginedUserid) { FilterProvider filters = new SimpleFilterProvider().addFilter("taskFilter", SimpleBeanPropertyFilter.filterOutAllExcept("tid", "taskname", "thistype", "thattype", "thisstr1", "thistext", "thisstr2", "thatusername", "thattext"));//?password outinfo = mapper.writer(filters).writeValueAsString(po);//JSON } } } response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { out.print(outinfo); } finally { out.close(); } }
From source file:com.gemstone.gemfire.internal.logging.log4j.Log4J2PerformanceTest.java
protected void writeConfigFile(final File file) throws FileNotFoundException { final PrintWriter pw = new PrintWriter(new FileOutputStream(file)); pw.println();// w w w. j a v a2 s . com pw.close(); }
From source file:de.avanux.livetracker.mobile.ConfigurationProvider.java
/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) *//*www . java 2 s . c om*/ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.debug("Configuration request received."); response.setContentType("text/plain"); PrintWriter out = response.getWriter(); Properties configuration = buildConfiguration(); configuration.store(out, null); out.close(); log.debug("Configuration returned."); }
From source file:fr.putnami.pwt.plugin.ajaxbot.filter.AjaxPageFilter.java
private InputStream extractHtml(HttpServletRequest request) throws IOException { AjaxPageRenderer crowler = new AjaxPageRenderer(serverUrl); String pageData = crowler.crawlPage(AjaxPageFilter.rewriteQueryString(request.getQueryString())); String cacheFileName = this.getCacheFileName(request.getParameter(QUERY_PARAM_ESCAPED_FRAGMENT)); if (cacheFileName != null) { File cacheFile = new File(cacheFileName); cacheFile.getParentFile().mkdirs(); PrintWriter out = new PrintWriter(cacheFile); out.print(pageData);/*from w w w .jav a 2 s .c o m*/ out.close(); return new FileInputStream(cacheFile); } return new StringInputStream(pageData); }
From source file:de.undercouch.gradle.tasks.download.ContentLengthTest.java
@Override protected Handler[] makeHandlers() throws IOException { ContextHandler contentLengthHandler = new ContextHandler("/" + CONTENT_LENGTH) { @Override/*from w w w .j av a 2 s . c o m*/ public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException { response.setStatus(200); if (contentLength != null) { response.setHeader("Content-Length", contentLength); } PrintWriter rw = response.getWriter(); rw.write("cl: " + String.valueOf(contentLength)); rw.close(); } }; return new Handler[] { contentLengthHandler }; }
From source file:model.settings.ReadSettings.java
/** * Writes text _text to path _path. //from ww w .j av a2s .c om * @param _path location of file. * @param _text text to be written into the file. * * @throws IOException is thrown in case of error. */ private static void writeToFile(final String _path, final String _text) throws IOException { //create writer PrintWriter pWriter = new PrintWriter(new FileWriter(_path)); //print text pWriter.println(_text); pWriter.flush(); //close writer pWriter.close(); }
From source file:in.raster.oviyam.servlet.SeriesServlet.java
/** * Handles the HTTP <code>GET</code> method. * @param request servlet request//w w w . j a v a 2 s. c o m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String patID = request.getParameter("patientID"); String studyUID = request.getParameter("studyUID"); String dcmURL = request.getParameter("dcmURL"); SeriesInfo series = new SeriesInfo(); series.callFindWithQuery(patID, studyUID, dcmURL); ArrayList<SeriesModel> seriesList = series.getSeriesList(); Collections.sort(seriesList, new SeriesComparator()); JSONArray jsonArray = new JSONArray(); JSONObject jsonObj = null; try { for (int i = 0; i < seriesList.size(); i++) { SeriesModel sm = (SeriesModel) seriesList.get(i); jsonObj = new JSONObject(); jsonObj.put("seriesUID", sm.getSeriesIUID()); jsonObj.put("seriesNumber", sm.getSeriesNumber()); jsonObj.put("modality", sm.getModality()); jsonObj.put("seriesDesc", sm.getSeriesDescription()); jsonObj.put("bodyPart", sm.getBodyPartExamined()); jsonObj.put("totalInstances", sm.getNumberOfInstances()); jsonObj.put("patientId", patID); jsonObj.put("studyUID", studyUID); jsonArray.put(jsonObj); } PrintWriter out = response.getWriter(); out.print(jsonArray); out.close(); } catch (Exception ex) { log.error(ex); } }