List of usage examples for java.io PrintStream flush
public void flush()
From source file:org.openspaces.test.client.executor.ExecutorUtils.java
/** * Writes desired string data to appropriate file. * * @param context String context./*from ww w .jav a2 s . c o m*/ * @param fileName file name path. * @param append if <code>true</code>, then bytes will be written to the end of the file * rather than the beginning * @throws IOException Failed to write data-context to file. */ synchronized public static void toFile(String context, String fileName, boolean append) throws IOException { PrintStream ps = new PrintStream(new FileOutputStream(fileName, append)); ps.println(context); ps.flush(); ps.close(); }
From source file:com.jrummyapps.busybox.signing.ZipSigner.java
/** * Write a .SF file with a digest the specified manifest. *///from w w w . java2s .co m 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:com.bigdata.dastor.tools.SSTableExport.java
/** * Enumerate row keys from an SSTableReader and write the result to a PrintStream. * /*from w w w.j av a 2 s.c o m*/ * @param ssTableFile the file to export the rows from * @param outs PrintStream to write the output to * @throws IOException on failure to read/write input/output */ public static void enumeratekeys(String ssTableFile, PrintStream outs) throws IOException { IPartitioner partitioner = StorageService.getPartitioner(); BufferedRandomAccessFile input = new BufferedRandomAccessFile(SSTable.indexFilename(ssTableFile), "r"); while (!input.isEOF()) { DecoratedKey decoratedKey = partitioner.convertFromDiskFormat(input.readUTF()); long dataPosition = input.readLong(); outs.println(decoratedKey.key); } outs.flush(); }
From source file:controllers.TNodes.java
/** * telnet/*from ww w .j av a2 s .c om*/ * * @param ip * @param user * @param password * @param telnet * @return */ public static boolean connect(String ip, String user, String password, TelnetClient telnet) { try { telnet.connect(ip, 23); telnet.setSoTimeout(2 * 1000); PrintStream out = new PrintStream(telnet.getOutputStream()); out.println(user); out.flush(); // TimeUnit.SECONDS.sleep(1); out.println(password); out.flush(); // TimeUnit.SECONDS.sleep(1); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
From source file:NMTFUtils.GetFWords.java
public static void getTopWordsDTL(String base) throws IOException { int TOP_NUM = 20; List<String> dictsLists = FileUtils.readLines(new File(dicpath)); List<String> indexLists = FileUtils.readLines(new File("F:\\matlab_code\\DTL\\indexs.csv")); Map<String, String> wordMaps = new HashMap<>(); for (String line : dictsLists) { String[] split = line.split("@:@"); if (split.length != 2) { wordMaps.put(split[0], ""); } else {/*from ww w . j a va 2 s. c o m*/ wordMaps.put(split[0], split[1]); } } PrintStream ps = new PrintStream( "G:\\\\\\journal\\" + base + "\\DTLs-TopWords.txt"); for (int li = 0; li < indexLists.size(); li++) { String[] split = indexLists.get(li).split(","); StringBuilder topWords = new StringBuilder(); for (int i = 0; i < TOP_NUM; i++) { String get = wordMaps.get(split[i]); if (get != null) { topWords.append(get.trim()).append(" "); } else { System.out.println(split[i]); return; } } System.out.println(topWords); ps.println("TOP:" + (li + 1) + " " + topWords); } ps.flush(); ps.close(); }
From source file:NMTFUtils.GetFWords.java
public static void getTopWordsLSFTL(String base) throws IOException { int TOP_NUM = 20; List<String> dictsLists = FileUtils.readLines(new File(dicpath)); List<String> indexLists = FileUtils.readLines(new File("G:\\syn_github\\KLSNMF\\KLSNMF\\indext.csv")); Map<String, String> wordMaps = new HashMap<>(); for (String line : dictsLists) { String[] split = line.split("@:@"); if (split.length != 2) { wordMaps.put(split[0], ""); } else {/*from w ww . j a va 2 s .c o m*/ wordMaps.put(split[0], split[1]); } } PrintStream ps = new PrintStream( "G:\\\\\\journal\\" + base + "\\LSFTLs-TopWordt.txt"); for (int li = 0; li < indexLists.size(); li++) { String[] split = indexLists.get(li).split(","); StringBuilder topWords = new StringBuilder(); for (int i = 0; i < TOP_NUM; i++) { String get = wordMaps.get(split[i]); if (get != null) { topWords.append(get.trim()).append(" "); } else { System.out.println(split[i]); return; } } System.out.println(topWords); ps.println("TOP:" + (li + 1) + " " + topWords); } ps.flush(); ps.close(); }
From source file:NMTFUtils.GetFWords.java
public static void getTopWordsTriTL(String base) throws IOException { int TOP_NUM = 20; List<String> dictsLists = FileUtils.readLines(new File(dicpath)); List<String> indexLists = FileUtils.readLines(new File("F:\\matlab_code\\TriTL\\indext.csv")); Map<String, String> wordMaps = new HashMap<>(); for (String line : dictsLists) { String[] split = line.split("@:@"); if (split.length != 2) { wordMaps.put(split[0], ""); } else {//from w w w . j a v a2 s . c o m wordMaps.put(split[0], split[1]); } } PrintStream ps = new PrintStream( "G:\\\\\\journal\\" + base + "\\TRITLt-TopWords.txt"); for (int li = 0; li < indexLists.size(); li++) { String[] split = indexLists.get(li).split(","); StringBuilder topWords = new StringBuilder(); for (int i = 0; i < TOP_NUM; i++) { String get = wordMaps.get(split[i]); if (get != null) { topWords.append(get.trim()).append(" "); } else { System.out.println(split[i]); return; } } System.out.println(topWords); ps.println("TOP:" + (li + 1) + " " + topWords); } ps.flush(); ps.close(); }
From source file:org.apache.cassandra.tools.SSTableExport.java
/** * Enumerate row keys from an SSTableReader and write the result to a PrintStream. * /*from ww w . j a v a2 s .co m*/ * @param ssTableFile the file to export the rows from * @param outs PrintStream to write the output to * @throws IOException on failure to read/write input/output */ public static void enumeratekeys(String ssTableFile, PrintStream outs) throws IOException { Descriptor desc = Descriptor.fromFilename(ssTableFile); KeyIterator iter = new KeyIterator(desc); DecoratedKey lastKey = null; while (iter.hasNext()) { DecoratedKey key = iter.next(); // validate order of the keys in the sstable if (lastKey != null && lastKey.compareTo(key) > 0) throw new IOException("Key out of order! " + lastKey + " > " + key); lastKey = key; outs.println(bytesToHex(key.key)); } iter.close(); outs.flush(); }
From source file:imagingbook.lib.math.Matrix.java
public static void printToStream(double[] A, PrintStream strm) { strm.format("{"); for (int i = 0; i < A.length; i++) { if (i > 0) strm.format(", "); strm.format(fStr, A[i]);// w w w . j a va 2 s. c om } strm.format("}"); strm.flush(); }
From source file:imagingbook.lib.math.Matrix.java
public static void printToStream(float[] A, PrintStream strm) { strm.format("{"); for (int i = 0; i < A.length; i++) { if (i > 0) strm.format(", "); strm.format(fStr, A[i]);/*from w w w . jav a 2 s . c o m*/ } strm.format("}"); strm.flush(); }