List of usage examples for java.io PrintStream close
public void close()
From source file:com.moscona.dataSpace.ExportHelper.java
public void csvExportAll(INameSpace ns, String dirName, boolean includeMetaData) throws DataSpaceException, FileNotFoundException { File dir = new File(dirName); if (!dir.exists()) { dir.mkdirs();//from ww w . j av a 2 s .c o m } HashMap<String, IScalar> scalars = new HashMap<String, IScalar>(); for (String name : ns.getAssignedVariableNames()) { try { IDataElement var = ns.get(name); if (IScalar.class.isAssignableFrom(var.getClass())) { scalars.put(name, (IScalar) var); } if (DataFrame.class.isAssignableFrom(var.getClass())) { DataFrame df = (DataFrame) var; csvExport(df, dirName + "/" + name + ".dataFrame.csv", includeMetaData); } if (AbstractVector.class.isAssignableFrom(var.getClass())) { AbstractVector vector = (AbstractVector) var; csvExport(vector, dirName + "/" + name + ".vector.csv", includeMetaData); } } catch (DataSpaceException e) { throw new DataSpaceException("Error while exporting " + ns.get(name).getClass().getSimpleName() + " \"" + name + "\": " + e, e); } } if (scalars.size() == 0) { return; } String filename = dirName + "/scalars.csv"; PrintStream out = new PrintStream(new File(filename)); try { for (String name : scalars.keySet()) { csvOut(out, name, toCsvString(scalars.get(name))); } } finally { out.close(); } }
From source file:edu.oregonstate.eecs.mcplan.ml.LinearDiscriminantAnalysis.java
public void writeModel(final File directory) { try {/*from ww w .ja v a 2s . c o m*/ final PrintStream eigenvectors_out = new PrintStream( new FileOutputStream(new File(directory, "lda-eigenvectors.csv"))); Csv.write(eigenvectors_out, eigenvectors); eigenvectors_out.close(); final PrintStream eigenvalues_out = new PrintStream( new FileOutputStream(new File(directory, "lda-eigenvalues.csv"))); Csv.write(eigenvalues_out, eigenvalues); eigenvalues_out.close(); } catch (final Exception ex) { throw new RuntimeException(ex); } }
From source file:org.LexGrid.LexBIG.caCore.test.rest.RESTTest.java
private String callRestfulService(String putString) throws Exception { URL url = new URL(serviceEndPoint + putString); URLConnection urlc = url.openConnection(); urlc.setDoInput(true);// ww w . j a v a 2 s . c o m urlc.setDoOutput(true); PrintStream ps = new PrintStream(urlc.getOutputStream()); ps.close(); //retrieve result BufferedReader br = new BufferedReader(new InputStreamReader(urlc.getInputStream())); String str; StringBuffer sb = new StringBuffer(); while ((str = br.readLine()) != null) { sb.append(str); sb.append("\n"); } br.close(); return sb.toString(); }
From source file:com.meetingninja.csse.database.MeetingDatabaseAdapter.java
public static Meeting createMeeting(String userID, Meeting m) throws IOException, MalformedURLException { // Server URL setup String _url = getBaseUri().appendPath(userID).build().toString(); // establish connection URL url = new URL(_url); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); addRequestHeader(conn, true);/*from ww w . j av a 2 s . c o 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); // Build JSON Object jgen.writeStartObject(); jgen.writeStringField(Keys.User.ID, userID); jgen.writeStringField(Keys.Meeting.TITLE, m.getTitle()); jgen.writeStringField(Keys.Meeting.LOCATION, m.getLocation()); jgen.writeStringField(Keys.Meeting.DATETIME, m.getStartTime()); jgen.writeStringField(Keys.Meeting.OTHEREND, m.getEndTime()); jgen.writeStringField(Keys.Meeting.DESC, m.getDescription()); jgen.writeArrayFieldStart(Keys.Meeting.ATTEND); // TODO: Add attendees to meeting // for (String attendee : m.getAttendance()) { // if (attendee.isAttending()) { jgen.writeStartObject(); jgen.writeStringField(Keys.User.ID, userID); jgen.writeEndObject(); // } // } jgen.writeEndArray(); 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); // prepare to get the id of the created Meeting JsonNode responseMap; m.setID(404); Meeting created = new Meeting(m); /* * result should get valid={"meetingID":"##"} */ // String result = new String(); if (!response.isEmpty()) { responseMap = MAPPER.readTree(response); if (responseMap.has(Keys.Meeting.ID)) created.setID(responseMap.get(Keys.Meeting.ID).asText()); } // if (!result.equalsIgnoreCase("invalid")) // created.setID(result); conn.disconnect(); return created; }
From source file:avantssar.aslanpp.testing.BackendTask.java
public void run() { //int idx = 0; synchronized (nextIndex) { //idx = nextIndex; nextIndex++;// www . j ava 2s. co m } System.out.print("+"); String runnerPrefix = FilenameUtils.removeExtension(aslanFile.getAbsolutePath()) + "." + runner.getName().replaceAll("[^a-zA-Z0-9]", "").toLowerCase(); File outputFile = new File(runnerPrefix + ".output.txt"); File errorsFile = new File(runnerPrefix + ".errors.txt"); try { PrintStream captureOutput = new PrintStream(outputFile); PrintStream captureErrors = new PrintStream(errorsFile); // runner.purgeParameters(); // for (String p : parameters) { // runner.addParameter(p); // } Verdict v = runner.analyze(aslanFile, parameters, captureOutput, captureErrors); captureOutput.close(); captureErrors.close(); outputFile = Tester.deleteIfZero(outputFile); errorsFile = Tester.deleteIfZero(errorsFile); ti.putVerdict(runner, v, outputFile, errorsFile); } catch (FileNotFoundException e) { ti.putVerdict(runner, Verdict.Error, null, null); } System.out.print("-"); }
From source file:org.apache.pig.test.TestFilterOpNumeric.java
@Test public void testNestedBinCond() throws Throwable { File tmpFile = File.createTempFile("test", "txt"); PrintStream ps = new PrintStream(new FileOutputStream(tmpFile)); for (int i = 0; i < LOOP_COUNT; i++) { ps.println(i + "\t" + i + "\t1"); }/* w ww. ja va 2 s.c om*/ ps.close(); pig.registerQuery( "A=load '" + Util.encodeEscape(Util.generateURI(tmpFile.toString(), pig.getPigContext())) + "';"); String query = "A = foreach A generate (($0 < 10 or $0 < 9)?(($1 >= 5 and $1 >= 4) ? 2: 1) : 0);"; log.info(query); pig.registerQuery(query); Iterator<Tuple> it = pig.openIterator("A"); tmpFile.delete(); int count = 0; while (it.hasNext()) { Tuple t = it.next(); Integer first = (Integer) t.get(0); count += first; assertTrue(first == 1 || first == 2 || first == 0); } assertEquals("expected count of 15", 15, count); }
From source file:htsjdk.samtools.tabix.IndexingFeatureWriterNGTest.java
@Test public void blockCompressFile() throws FileNotFoundException { String file = "/home/sol/Downloads/test.chain.gff"; String out = "/home/sol/Downloads/t.bgz"; BlockCompressedOutputStream bcos = new BlockCompressedOutputStream(new File(out)); PrintStream ps = new PrintStream(bcos); Scanner scan = new Scanner(new File(file)); while (scan.hasNext()) { ps.println(scan.nextLine());/*from ww w . j av a 2 s .c om*/ } ps.close(); }
From source file:org.apache.pig.test.TestFilterOpNumeric.java
@Test public void testBinCond() throws Throwable { File tmpFile = File.createTempFile("test", "txt"); PrintStream ps = new PrintStream(new FileOutputStream(tmpFile)); for (int i = 0; i < LOOP_COUNT; i++) { ps.println(i + "\t" + i + "\t1"); }//from w ww. ja v a 2 s . c o m ps.close(); pig.registerQuery( "A=load '" + Util.encodeEscape(Util.generateURI(tmpFile.toString(), pig.getPigContext())) + "';"); String query = "A = foreach A generate ($1 >= " + LOOP_COUNT + "-10?'1':'0');"; log.info(query); pig.registerQuery(query); Iterator<Tuple> it = pig.openIterator("A"); tmpFile.delete(); int count = 0; while (it.hasNext()) { Tuple t = it.next(); Double first = Double.valueOf(t.get(0).toString()); if (first == 1) count++; else assertTrue(first == 0); } assertEquals("expected count of 10", 10, count); }
From source file:io.appium.java_client.service.local.AppiumServiceBuilder.java
@Override protected File findDefaultExecutable() { validateNodeJSVersion();// w w w .j a v a 2 s . c om Runtime rt = Runtime.getRuntime(); Process p; try { p = rt.exec(NODE_COMMAND_PREFIX + " node"); } catch (IOException e) { throw new RuntimeException(e); } try { OutputStream outputStream = p.getOutputStream(); PrintStream out = new PrintStream(outputStream); out.println("console.log(process.execPath);"); out.close(); return new File(getProcessOutput(p.getInputStream())); } catch (Throwable t) { throw new RuntimeException(t); } finally { p.destroy(); } }
From source file:com.amazonaws.eclipse.sdk.ui.wizard.NewAwsJavaProjectWizard.java
private void addSamplesToProject() throws CoreException, IOException { IProject project = pageTwo.getJavaProject().getProject(); IPath workspaceRoot = project.getWorkspace().getRoot().getRawLocation(); IPath srcPath = workspaceRoot.append(project.getFullPath()).append("src"); AccountInfo selectedAccount = pageOne.getSelectedAccount(); for (SdkSample sample : pageOne.getSelectedSamples()) { for (File sampleSourceFile : sample.getPath().toFile() .listFiles(new FilenameFilters.JavaSourceFilenameFilter())) { String sampleContent = FileUtils.readFileToString(sampleSourceFile); if (selectedAccount != null) { sampleContent = updateSampleContentWithConfiguredProfile(sampleContent, selectedAccount); }/*from w ww . j a v a 2 s . c o m*/ IFileStore projectSourceFolderDestination = EFS.getLocalFileSystem() .fromLocalFile(srcPath.append(sampleSourceFile.getName()).toFile()); PrintStream ps = new PrintStream( projectSourceFolderDestination.openOutputStream(EFS.OVERWRITE, null)); ps.print(sampleContent); ps.close(); } } }