List of usage examples for java.io PrintStream close
public void close()
From source file:net.morphbank.mbsvc3.webservices.RestServiceExcelUpload.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // /*from w w w.ja va 2s . c o m*/ String method = request.getParameter(RequestParams.PARAM_METHOD); if ("remoteupdate".equals(method)) { UpdateRemote.update(request, response); } else { // TODO turn over to processrequest response.setContentType("text/xml"); PrintStream out = new PrintStream(response.getOutputStream()); out.println("<html><body>Here I am</body></html>"); out.close(); } }
From source file:com.meetingninja.csse.database.UserDatabaseAdapter.java
public static String login(String email, String pass) throws IOException { // Server URL setup String _url = getBaseUri().appendPath("Login").build().toString(); // Establish connection URL url = new URL(_url); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // add request header conn.setRequestMethod(IRequest.POST); addRequestHeader(conn, true);//from w ww. jav a2 s . co m // prepare POST payload ByteArrayOutputStream json = new ByteArrayOutputStream(); // this type of print stream allows us to get a string easily PrintStream ps = new PrintStream(json); // Create a generator to build the JSON string JsonGenerator jgen = JFACTORY.createGenerator(ps, JsonEncoding.UTF8); try { // hash the password pass = Utilities.computeHash(pass); } catch (NoSuchAlgorithmException e) { Log.e(TAG, e.getLocalizedMessage()); } // Build JSON Object jgen.writeStartObject(); jgen.writeStringField(Keys.User.EMAIL, email); jgen.writeStringField("password", pass); jgen.writeEndObject(); jgen.close(); // Get JSON Object payload from print stream String payload = json.toString("UTF8"); ps.close(); // Send payload int responseCode = sendPostPayload(conn, payload); String response = getServerResponse(conn); /* * result should get valid={"userID":"##"} * invalid={"errorID":"3","errorMessage":"invalid username or password"} */ String result = ""; if (!response.isEmpty()) { JsonNode tree = MAPPER.readTree(response); if (!tree.has(Keys.User.ID)) { logError(TAG, tree); result = "invalid username or password"; } else result = tree.get(Keys.User.ID).asText(); } conn.disconnect(); return result; }
From source file:com.oltpbenchmark.util.ResultUploader.java
public void uploadResult(List<TransactionType> activeTXTypes) throws ParseException { try {/*from w ww. ja v a 2 s. c o m*/ File expConfigFile = File.createTempFile("expconfig", ".tmp"); File samplesFile = File.createTempFile("samples", ".tmp"); File summaryFile = File.createTempFile("summary", ".tmp"); File paramsFile = File.createTempFile("params", ".tmp"); File metricsFile = File.createTempFile("metrics", ".tmp"); File csvDataFile = File.createTempFile("csv", ".gz"); PrintStream confOut = new PrintStream(new FileOutputStream(expConfigFile)); writeBenchmarkConf(confOut); confOut.close(); confOut = new PrintStream(new FileOutputStream(paramsFile)); writeDBParameters(confOut); confOut.close(); confOut = new PrintStream(new FileOutputStream(metricsFile)); writeDBMetrics(confOut); confOut.close(); confOut = new PrintStream(new FileOutputStream(samplesFile)); results.writeCSV2(confOut); confOut.close(); confOut = new PrintStream(new FileOutputStream(summaryFile)); writeSummary(confOut); confOut.close(); confOut = new PrintStream(new GZIPOutputStream(new FileOutputStream(csvDataFile))); results.writeAllCSVAbsoluteTiming(activeTXTypes, confOut); confOut.close(); CloseableHttpClient httpclient = HttpClients.createDefault(); HttpPost httppost = new HttpPost(uploadUrl); HttpEntity reqEntity = MultipartEntityBuilder.create().addTextBody("upload_code", uploadCode) .addPart("sample_data", new FileBody(samplesFile)) .addPart("raw_data", new FileBody(csvDataFile)) .addPart("db_parameters_data", new FileBody(paramsFile)) .addPart("db_metrics_data", new FileBody(metricsFile)) .addPart("benchmark_conf_data", new FileBody(expConfigFile)) .addPart("summary_data", new FileBody(summaryFile)).build(); httppost.setEntity(reqEntity); LOG.info("executing request " + httppost.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httppost); try { HttpEntity resEntity = response.getEntity(); LOG.info(IOUtils.toString(resEntity.getContent())); EntityUtils.consume(resEntity); } finally { response.close(); } } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (ConfigurationException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } }
From source file:uk.org.openeyes.oink.itest.karaf.OinkCommandIT.java
@Test public void testOinkEnableCommandIsAvailableOnShellOnAFreshCopyOfCustomDistro() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream err = new ByteArrayOutputStream(); PrintStream psout = new PrintStream(out); PrintStream pser = new PrintStream(err); CommandSession cs = commandProcessor.createSession(System.in, psout, pser); cs.execute("help oink:enable"); cs.close();//from w w w. j a v a 2 s . com psout.close(); pser.close(); assertTrue(err.toString().isEmpty()); assertFalse(out.toString().contains("COMMANDS")); }
From source file:uk.org.openeyes.oink.itest.karaf.OinkCommandIT.java
@Test public void testOinkDisableCommandIsAvailableOnShellOnAFreshCopyOfCustomDistro() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream err = new ByteArrayOutputStream(); PrintStream psout = new PrintStream(out); PrintStream pser = new PrintStream(err); CommandSession cs = commandProcessor.createSession(System.in, psout, pser); cs.execute("help oink:disable"); cs.close();/*from w w w. jav a 2s.c om*/ psout.close(); pser.close(); assertTrue(err.toString().isEmpty()); assertFalse(out.toString().contains("COMMANDS")); }
From source file:org.apache.kylin.tool.KylinConfigCLITest.java
@Test public void testGetProperty() throws IOException { PrintStream o = System.out; File f = File.createTempFile("cfg", ".tmp"); PrintStream tmpOut = new PrintStream(new FileOutputStream(f)); System.setOut(tmpOut);/*from w w w . java2s .c o m*/ KylinConfigCLI.main(new String[] { "kylin.storage.url" }); String val = FileUtils.readFileToString(f, Charset.defaultCharset()).trim(); assertEquals("hbase", val); tmpOut.close(); FileUtils.forceDelete(f); System.setOut(o); }
From source file:com.sangupta.jerry.print.ConsoleTableWriter.java
/** * Output the data of the table as a CSV * /*from w w w . ja va2 s . c om*/ * @param table * the {@link ConsoleTable} to output * * @param out * the {@link PrintWriter} to write to */ public void writeCsv(ConsoleTable table, PrintWriter writer) { OutputStream os = new WriterOutputStream(writer); PrintStream ps = new PrintStream(os); try { writeCsv(table, ps); } finally { ps.close(); } }
From source file:com.sangupta.jerry.print.ConsoleTableWriter.java
/** * Output the data of the table as a JSON * /*from w w w . jav a2 s . c om*/ * @param table * the {@link ConsoleTable} to output * * @param out * the {@link PrintWriter} to write to */ public void writeJson(ConsoleTable table, PrintWriter writer) { OutputStream os = new WriterOutputStream(writer); PrintStream ps = new PrintStream(os); try { writeJson(table, ps); } finally { ps.close(); } }
From source file:com.sangupta.jerry.print.ConsoleTableWriter.java
/** * Output the data as an XML./*from w w w .j a v a 2 s . c o m*/ * * @param table * the {@link ConsoleTable} to output * * @param out * the {@link PrintStream} to write to * * @param parentXmlTag * the uber XML tag to wrap items into * * @param rowTag * the tag to use for wrapping each row of data */ public void writeXml(ConsoleTable table, PrintWriter writer, String parentXmlTag, String rowTag) { OutputStream os = new WriterOutputStream(writer); PrintStream ps = new PrintStream(os); try { writeJson(table, ps); } finally { ps.close(); } }
From source file:net.morphbank.mbsvc3.webservices.RestfulService.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Turn over work to RequestProcessor! response.setContentType("text/xml"); PrintStream out = new PrintStream(response.getOutputStream()); out.println("<html><body>Here I am</body></html>"); out.close(); }