List of usage examples for java.io PrintStream close
public void close()
From source file:org.apache.carbondata.tool.CarbonCli.java
private static void runCli(PrintStream out, Options options, CommandLine line) { if (outPuts == null) { outPuts = new ArrayList<>(); }/* w w w . j a v a2 s . c o m*/ if (line.hasOption("h")) { collectHelpInfo(options); for (String output : outPuts) { out.println(output); } return; } String path = ""; if (line.hasOption("p")) { path = line.getOptionValue("path"); } outPuts.add("Input Folder: " + path); String cmd = line.getOptionValue("cmd"); Command command; if (cmd.equalsIgnoreCase("summary")) { command = new DataSummary(path, outPuts); } else if (cmd.equalsIgnoreCase("benchmark")) { command = new ScanBenchmark(path, outPuts); } else { out.println("command " + cmd + " is not supported"); outPuts.add("command " + cmd + " is not supported"); collectHelpInfo(options); for (String output : outPuts) { out.println(output); } return; } try { command.run(line); if (isPrintInConsole) { for (String output : outPuts) { out.println(output); } } out.flush(); } catch (IOException | MemoryException e) { e.printStackTrace(); } finally { out.close(); } }
From source file:uk.ac.ebi.intact.editor.controller.misc.ErrorController.java
private String createIssueContent() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); ps.println("<b>Reporter:</b> " + userSessionController.getCurrentUser().getLogin() + " <br/>"); ps.println("<b>ViewId:</b> " + viewId + "<br/>"); ps.println("<b>Referer:</b> " + referer + "<br/>"); ps.println("<b>Exception message:</b> " + throwable.getMessage() + "<br/>"); ps.println("<p>" + explanation + "</p>"); ps.close(); return baos.toString(); }
From source file:net.morphbank.mbsvc3.webservices.Uploader.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // //from www . j a va 2 s .c om String method = request.getParameter(RequestParams.PARAM_METHOD); if ("remoteupdate".equals(method)) { UpdateRemote.update(request, response); } else { // TODO turn over to process request response.setContentType("text/xml"); PrintStream out = new PrintStream(response.getOutputStream()); out.println("<html><body>Here I am</body></html>"); out.close(); } }
From source file:org.apache.accumulo.test.randomwalk.shard.BulkInsert.java
private void sort(State state, FileSystem fs, String tableName, String seqFile, String outputDir, String workDir, int maxSplits) throws Exception { PrintStream out = new PrintStream(new BufferedOutputStream(fs.create(new Path(workDir + "/splits.txt"))), false, Constants.UTF8.name()); Connector conn = state.getConnector(); Collection<Text> splits = conn.tableOperations().listSplits(tableName, maxSplits); for (Text split : splits) out.println(new String(Base64.encodeBase64(TextUtil.getBytes(split)), Constants.UTF8)); out.close(); SortTool sortTool = new SortTool(seqFile, outputDir, workDir + "/splits.txt", splits); String[] args = new String[2]; args[0] = "-libjars"; args[1] = state.getMapReduceJars();/*from ww w . j av a 2s .c o m*/ if (ToolRunner.run(CachedConfiguration.getInstance(), sortTool, args) != 0) { throw new Exception("Failed to run map/red verify"); } }
From source file:org.apache.oodt.cas.filemgr.cli.action.TestIngestProductCliAction.java
private File createHierarchicalReference() throws IOException { File reference = new File(tmpDir, HIER_REF_NAME); reference.mkdirs();/*from w w w. j av a 2s. c o m*/ PrintStream ps = null; for (String subRef : Lists.newArrayList(SUB_REF_1, SUB_REF_2)) { try { ps = new PrintStream(new FileOutputStream(new File(reference, subRef))); ps.println("This is a test sub-reference file"); } finally { ps.close(); } } return reference; }
From source file:client.communication.SocketClient.java
/** * Envia a mensagem para o servidor e retorna a resposta * /*from w w w. j av a 2 s.c om*/ * @param message * @return */ public String sendMessage(String message) { Socket socket = null; PrintStream stream = null; try { socket = new Socket(serverAddress, serverPort); stream = new PrintStream(socket.getOutputStream()); // Envia requisiao stream.println(message); // L resposta socket.getInputStream().read(response); } catch (IOException e) { System.out.println("Problem connecting server!"); } finally { try { // Fecha stream if (stream != null) stream.close(); if (socket != null) socket.close(); } catch (IOException e) { System.err.println("Problem closing socket: " + e.getMessage()); } } // Decodifica resposta em base 64 String _reply = new String(Base64.decodeBase64(response)); // Remove o espao nas extremidades da string de resposta return _reply.trim(); }
From source file:me.openMap.ApplicationSettings.java
public void save() { StringBuilder fileName = new StringBuilder(); fileName.append(System.getProperty("user.home")); fileName.append(File.separator); fileName.append("."); fileName.append(getClass().getSimpleName()); fileName.append(".xml"); System.out.println("write: " + fileName.toString()); try {/*ww w. j ava 2 s .co m*/ PrintStream ps = new PrintStream(new FileOutputStream(fileName.toString())); XStream stream = new XStream(); stream.processAnnotations(getClass()); stream.processAnnotations(GradientParameters.class); ps.println(stream.toXML(this)); ps.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:org.matsim.contrib.freight.usecases.analysis.LegHistogram.java
/** * Writes the gathered data tab-separated into a text file. * * @param filename The name of a file where to write the gathered data. *//*from ww w. ja va2s. c om*/ public void write(final String filename) { PrintStream stream; try { stream = new PrintStream(new File(filename)); } catch (FileNotFoundException e) { e.printStackTrace(); return; } write(stream); stream.close(); }
From source file:edu.umn.cs.spatialHadoop.core.RectangleNN.java
public static long spatialJoinLocal(Path[] inFiles, Path outFile, OperationsParams params) throws IOException, InterruptedException { // Read the inputs and store them in memory List<Shape>[] datasets = new List[inFiles.length]; final SpatialInputFormat3<Rectangle, Shape> inputFormat = new SpatialInputFormat3<Rectangle, Shape>(); for (int i = 0; i < inFiles.length; i++) { datasets[i] = new ArrayList<Shape>(); FileSystem inFs = inFiles[i].getFileSystem(params); Job job = Job.getInstance(params); SpatialInputFormat3.addInputPath(job, inFiles[i]); for (InputSplit split : inputFormat.getSplits(job)) { FileSplit fsplit = (FileSplit) split; RecordReader<Rectangle, Iterable<Shape>> reader = inputFormat.createRecordReader(fsplit, null); if (reader instanceof SpatialRecordReader3) { ((SpatialRecordReader3) reader).initialize(fsplit, params); } else if (reader instanceof RTreeRecordReader3) { ((RTreeRecordReader3) reader).initialize(fsplit, params); } else if (reader instanceof HDFRecordReader) { ((HDFRecordReader) reader).initialize(fsplit, params); } else { throw new RuntimeException("Unknown record reader"); }/*w w w .j a v a 2 s .c o m*/ while (reader.nextKeyValue()) { Iterable<Shape> shapes = reader.getCurrentValue(); for (Shape shape : shapes) { datasets[i].add(shape.clone()); } } reader.close(); } } // Apply the spatial join algorithm ResultCollector2<Shape, Shape> output = null; PrintStream out = null; if (outFile != null) { FileSystem outFS = outFile.getFileSystem(params); out = new PrintStream(outFS.create(outFile)); final PrintStream outout = out; output = new ResultCollector2<Shape, Shape>() { @Override public void collect(Shape r, Shape s) { outout.println(r.toText(new Text()) + "," + s.toText(new Text())); } }; } long resultCount = SpatialJoin_planeSweep(datasets[0], datasets[1], output, null); if (out != null) out.close(); return resultCount; }
From source file:org.apache.pig.test.TestLocal.java
License:asdf
@Test public void testBigGroupAll() throws Throwable { int LOOP_COUNT = 4 * 1024; File tmpFile = File.createTempFile(this.getClass().getName(), ".txt"); PrintStream ps = new PrintStream(new FileOutputStream(tmpFile)); for (int i = 0; i < LOOP_COUNT; i++) { ps.println(i);//from www.j av a 2 s . c o m } ps.close(); assertEquals(new Double(LOOP_COUNT), bigGroupAll(tmpFile)); tmpFile.delete(); }