List of usage examples for java.io PrintStream close
public void close()
From source file:org.apache.pig.test.TestFilterOpString.java
@Test public void testStringLt() throws Throwable { File tmpFile = File.createTempFile("test", "txt"); PrintStream ps = new PrintStream(new FileOutputStream(tmpFile)); int expectedCount = 0; for (int i = 0; i < LOOP_COUNT; i++) { if (i % 5 == 0) { ps.println("b:a"); // test with nulls ps.println("a:"); ps.println(":b"); ps.println(":"); } else {//from w ww . j av a 2s. c o m ps.println("a:b"); expectedCount++; } } ps.close(); pig.registerQuery("A=load '" + Util.encodeEscape(Util.generateURI(tmpFile.toString(), pig.getPigContext())) + "' using " + PigStorage.class.getName() + "(':');"); String query = "A = filter A by $0 lt $1;"; log.info(query); pig.registerQuery(query); Iterator<Tuple> it = pig.openIterator("A"); tmpFile.delete(); int count = 0; while (it.hasNext()) { Tuple t = it.next(); String first = t.get(0).toString(); String second = t.get(1).toString(); assertTrue(first.compareTo(second) < 0); count++; } assertEquals(expectedCount, count); }
From source file:org.apache.pig.test.TestFilterOpString.java
@Test public void testStringGt() throws Throwable { File tmpFile = File.createTempFile("test", "txt"); PrintStream ps = new PrintStream(new FileOutputStream(tmpFile)); int expectedCount = 0; for (int i = 0; i < LOOP_COUNT; i++) { if (i % 5 == 0) { ps.println("b:a"); expectedCount++;//w w w . j av a 2s. c o m } else { ps.println("a:b"); // test with nulls ps.println("a:"); ps.println(":b"); ps.println(":"); } } ps.close(); pig.registerQuery("A=load '" + Util.encodeEscape(Util.generateURI(tmpFile.toString(), pig.getPigContext())) + "' using " + PigStorage.class.getName() + "(':');"); String query = "A = filter A by $0 gt $1;"; log.info(query); pig.registerQuery(query); Iterator<Tuple> it = pig.openIterator("A"); tmpFile.delete(); int count = 0; while (it.hasNext()) { Tuple t = it.next(); String first = t.get(0).toString(); String second = t.get(1).toString(); assertTrue(first.compareTo(second) > 0); count++; } assertEquals(expectedCount, count); }
From source file:de.uni_koblenz.jgralab.utilities.tg2dot.Tg2Dot.java
public void pipeToGraphViz(GraphVizProgram prog) throws IOException { String executionString = String.format("%s%s -T%s -o%s", prog.path, prog.layouter, prog.outputFormat, outputName);/*w w w .j av a 2 s. c o m*/ final Process process = Runtime.getRuntime().exec(executionString); new Thread() { @Override public void run() { PrintStream ps = new PrintStream(process.getOutputStream()); convert(ps); ps.flush(); ps.close(); }; }.start(); try { int retVal = process.waitFor(); if (retVal != 0) { throw new RuntimeException("GraphViz process failed! Error code = " + retVal); } } catch (InterruptedException e) { throw new RuntimeException(e); } }
From source file:org.apache.pig.test.TestFilterOpString.java
@Test public void testStringEq() throws Throwable { File tmpFile = File.createTempFile("test", "txt"); PrintStream ps = new PrintStream(new FileOutputStream(tmpFile)); int expectedCount = 0; for (int i = 0; i < LOOP_COUNT; i++) { if (i % 5 == 0) { ps.println("a:" + i); // test with nulls ps.println("a:"); ps.println(":a"); ps.println(":"); } else {/*ww w. j a v a 2s . co m*/ ps.println("ab:ab"); expectedCount++; } } ps.close(); pig.registerQuery("A=load '" + Util.encodeEscape(Util.generateURI(tmpFile.toString(), pig.getPigContext())) + "' using " + PigStorage.class.getName() + "(':');"); String query = "A = filter A by $0 eq $1;"; log.info(query); pig.registerQuery(query); Iterator<Tuple> it = pig.openIterator("A"); tmpFile.delete(); int count = 0; while (it.hasNext()) { Tuple t = it.next(); String first = t.get(0).toString(); String second = t.get(1).toString(); count++; assertEquals(first, second); } assertEquals(expectedCount, count); }
From source file:org.apache.pig.test.TestLocal.java
License:asdf
@Test public void testQualifiedFunctionsWithNulls() throws Throwable { //create file File tmpFile = File.createTempFile("test", ".txt"); PrintStream ps = new PrintStream(new FileOutputStream(tmpFile)); for (int i = 0; i < 1; i++) { if (i % 10 == 0) { ps.println(""); } else {/*from w w w . j a v a 2s. c om*/ ps.println(i); } } ps.close(); // execute query String query = "foreach (group (load '" + Util.generateURI(tmpFile.toString(), pig.getPigContext()) + "' using " + MyStorage.class.getName() + "()) by " + MyGroup.class.getName() + "('all')) generate flatten(" + MyApply.class.getName() + "($1)) ;"; System.out.println(query); pig.registerQuery("asdf_id = " + query); //Verfiy query Iterator it = pig.openIterator("asdf_id"); Tuple t; int count = 0; while (it.hasNext()) { t = (Tuple) it.next(); assertEquals(t.get(0).toString(), "Got"); Integer.parseInt(t.get(1).toString()); count++; } assertEquals(MyStorage.COUNT, count); tmpFile.delete(); }
From source file:com.jrummyapps.busybox.signing.ZipSigner.java
/** * Write a .SF file with a digest the specified manifest. *///w w w. j a v a 2 s . c om private static byte[] writeSignatureFile(Manifest manifest, OutputStream out) throws IOException, GeneralSecurityException { final Manifest sf = new Manifest(); final Attributes main = sf.getMainAttributes(); main.putValue("Manifest-Version", MANIFEST_VERSION); main.putValue("Created-By", CREATED_BY); final MessageDigest md = MessageDigest.getInstance("SHA1"); final PrintStream print = new PrintStream(new DigestOutputStream(new ByteArrayOutputStream(), md), true, "UTF-8"); // Digest of the entire manifest manifest.write(print); print.flush(); main.putValue("SHA1-Digest-Manifest", base64encode(md.digest())); final Map<String, Attributes> entries = manifest.getEntries(); for (final Map.Entry<String, Attributes> entry : entries.entrySet()) { // Digest of the manifest stanza for this entry. print.print("Name: " + entry.getKey() + "\r\n"); for (final Map.Entry<Object, Object> att : entry.getValue().entrySet()) { print.print(att.getKey() + ": " + att.getValue() + "\r\n"); } print.print("\r\n"); print.flush(); final Attributes sfAttr = new Attributes(); sfAttr.putValue("SHA1-Digest", base64encode(md.digest())); sf.getEntries().put(entry.getKey(), sfAttr); } final ByteArrayOutputStream sos = new ByteArrayOutputStream(); sf.write(sos); String value = sos.toString(); String done = value.replace("Manifest-Version", "Signature-Version"); out.write(done.getBytes()); print.close(); sos.close(); return done.getBytes(); }
From source file:fr.inrialpes.exmo.align.cli.ExtGroupEval.java
/** * This does not only print the results but compute the average as well * * @param result: the vector of vector result to be printed *///from w w w .j a va2 s. c o m public void print(Vector<Vector<Object>> result) { PrintStream writer = null; try { if (outputfilename == null) { writer = System.out; } else { writer = new PrintStream(new FileOutputStream(outputfilename)); } printHTML(result, writer); } catch (Exception ex) { logger.debug("IGNORED Exception", ex); } finally { writer.close(); } }
From source file:edu.emory.mathcs.nlp.zzz.CSVSentiment.java
public void categorize(String inputFile) throws Exception { CSVParser parser = new CSVParser(IOUtils.createBufferedReader(inputFile), CSVFormat.DEFAULT); List<CSVRecord> records = parser.getRecords(); List<NLPNode[]> document; String outputDir;/*from www . ja va 2 s . c o m*/ PrintStream fout; CSVRecord record; System.out.println(inputFile); for (int i = 0; i < records.size(); i++) { if (i == 0) continue; record = records.get(i); document = decode.decodeDocument(record.get(6)); document.get(0)[1].putFeat("sent", record.get(0)); outputDir = inputFile.substring(0, inputFile.length() - 4); fout = IOUtils.createBufferedPrintStream( outputDir + "/" + FileUtils.getBaseName(outputDir) + "_" + i + ".nlp"); for (NLPNode[] nodes : document) fout.println(decode.toString(nodes) + "\n"); fout.close(); } parser.close(); }
From source file:com.eviware.loadui.launcher.LoadUILauncher.java
/** * Initiates and starts the OSGi runtime. *//*ww w. jav a 2s . c o m*/ public LoadUILauncher(String[] args) { argv = args; //Fix for Protection! String username = System.getProperty("user.name"); System.setProperty("user.name.original", username); System.setProperty("user.name", username.toLowerCase()); File externalFile = new File(WORKING_DIR, "res/buildinfo.txt"); //Workaround for some versions of Java 6 which have a known SSL issue String versionString = System.getProperty("java.version", "0.0.0_00"); try { if (versionString.startsWith("1.6") && versionString.contains("_")) { int updateVersion = Integer.parseInt(versionString.split("_", 2)[1]); if (updateVersion > 27) { log.info("Detected Java version " + versionString + ", disabling CBC Protection."); System.setProperty("jsse.enableCBCProtection", "false"); } } } catch (Exception e) { e.printStackTrace(); } if (externalFile.exists()) { try (InputStream is = new FileInputStream(externalFile)) { Properties buildinfo = new Properties(); buildinfo.load(is); System.setProperty(LOADUI_BUILD_NUMBER, buildinfo.getProperty("build.number")); System.setProperty(LOADUI_BUILD_DATE, buildinfo.getProperty("build.date")); System.setProperty(LOADUI_NAME, buildinfo.getProperty(LOADUI_NAME, "loadUI")); } catch (IOException e) { e.printStackTrace(); } } else { System.setProperty(LOADUI_BUILD_NUMBER, "unknown"); System.setProperty(LOADUI_BUILD_DATE, "unknown"); System.setProperty(LOADUI_NAME, "loadUI"); } options = createOptions(); CommandLineParser parser = new PosixParser(); try { cmd = parser.parse(options, argv); } catch (ParseException e) { System.err.print("Error parsing commandline args: " + e.getMessage() + "\n"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("", options); exitInError(); throw new RuntimeException(); } if (cmd.hasOption(SYSTEM_PROPERTY_OPTION)) { parseSystemProperties(); } initSystemProperties(); String sysOutFilePath = System.getProperty("system.out.file"); if (sysOutFilePath != null) { File sysOutFile = new File(sysOutFilePath); if (!sysOutFile.exists()) { try { sysOutFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } try { System.err.println("Writing stdout and stderr to file:" + sysOutFile.getAbsolutePath()); final PrintStream outStream = new PrintStream(sysOutFile); System.setOut(outStream); System.setErr(outStream); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { outStream.close(); } })); } catch (FileNotFoundException e) { throw new RuntimeException(e); } } System.out.println("Launching " + System.getProperty(LOADUI_NAME) + " Build: " + System.getProperty(LOADUI_BUILD_NUMBER, "[internal]") + " " + System.getProperty(LOADUI_BUILD_DATE, "")); Main.loadSystemProperties(); configProps = Main.loadConfigProperties(); if (configProps == null) { System.err.println("There was an error loading the OSGi configuration!"); exitInError(); } Main.copySystemProperties(configProps); }
From source file:org.apache.pig.test.TestFilterOpString.java
@Test public void testStringNeq() throws Throwable { File tmpFile = File.createTempFile("test", "txt"); PrintStream ps = new PrintStream(new FileOutputStream(tmpFile)); int expectedCount = 0; for (int i = 0; i < LOOP_COUNT; i++) { if (i % 5 == 0) { ps.println("ab:ab"); } else if (i % 3 == 0) { ps.println("ab:abc"); expectedCount++;//from ww w. j a v a 2 s. c o m } else { // test with nulls ps.println(":"); ps.println("ab:"); ps.println(":ab"); } } ps.close(); pig.registerQuery("A=load '" + Util.encodeEscape(Util.generateURI(tmpFile.toString(), pig.getPigContext())) + "' using " + PigStorage.class.getName() + "(':');"); String query = "A = filter A by $0 neq $1;"; log.info(query); pig.registerQuery(query); Iterator<Tuple> it = pig.openIterator("A"); tmpFile.delete(); int count = 0; while (it.hasNext()) { Tuple t = it.next(); String first = t.get(0).toString(); String second = t.get(1).toString(); assertFalse(first.equals(second)); count++; } assertEquals(expectedCount, count); }