public static void print(String[][] cols) throws Exception { BufferedWriter out = new BufferedWriter(new FileWriter(outputFilename)); for (String[] col : cols) { if (col.length >= 2) { out.write(col[0] + "\t" + col[1] + "\n"); } else { out.write("\n"); } } out.flush(); out.close(); }
private void bufferWriterAndFlushWhenDone(Writer writer, Consumer<BufferedWriter> consumer) { BufferedWriter bufferedWriter = (writer instanceof BufferedWriter) ? (BufferedWriter) writer : new BufferedWriter(writer, 32 * 1024); try { try { consumer.accept(bufferedWriter); } finally { bufferedWriter.flush(); } } catch (IOException e) { throw new RuntimeException(e); } }
public void write(OutputStream output, Collection<StorableDateTimeZone> timeZones) throws IOException { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8)); StringBuilder sb = new StringBuilder(); for (StorableDateTimeZone timeZone : timeZones) { writer.append(timeZone.getID()).append(' '); timeZone.write(sb); writer.append(sb); sb.setLength(0); writer.append('\n'); } writer.flush(); }
try (FileWriter fw = new FileWriter(file)) { BufferedWriter bw = new BufferedWriter(fw); bw.write(text); bw.flush(); }
private EntityData.GlobalStore persistAndRetrieve(EntityData.GlobalStore world) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(baos, TerasologyConstants.CHARSET)); EntityDataJSONFormat.write(world, writer); writer.flush(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); return EntityDataJSONFormat.readWorld(new BufferedReader(new InputStreamReader(bais, TerasologyConstants.CHARSET))); }
private static String pbaksmali(DexClassNode dcn) throws IOException { StringWriter bufWriter = new StringWriter(); BufferedWriter w = new BufferedWriter(bufWriter); new BaksmaliDumper(true, true).baksmaliClass(dcn, new BaksmaliDumpOut(w)); w.flush(); bufWriter.flush(); return bufWriter.toString(); }
BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter("test.txt")); bw.write("test"); bw.flush(); // you can omit this if you don't care about errors while flushing bw.close(); // you can omit this if you don't care about errors while closing } catch (IOException e) { // error handling (e.g. on flushing) } finally { IOUtils.closeQuietly(bw); }
@Override public void convertCode(DexMethodNode methodNode, MethodVisitor mv) { try { super.convertCode(methodNode, mv); } catch (Exception ex) { BaksmaliDumper d = new BaksmaliDumper(); try { BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.err, "UTF-8")); d.baksmaliMethod(methodNode, out); out.flush(); } catch (IOException e) { e.printStackTrace(); } throw new DexException(ex, "fail convert code %s", methodNode.method); } } };
private static boolean writeValue(Socket client, String value) { boolean result; BufferedWriter out = null; try { OutputStream clientStream = client.getOutputStream(); out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); out.write(value); out.write("\n"); out.flush(); result = true; } catch (Exception e) { result = false; } finally { if (out != null) { try { out.close(); } catch (IOException e) { result = false; } } } return result; }
@Test public void test() throws IOException { DexFileNode dfn = new DexFileNode(); try (InputStream is = SmaliTest.class.getResourceAsStream("/a.smali")) { Smali.smaliFile("a.smali", is, dfn); } for (DexClassNode dcn : dfn.clzs) { BufferedWriter w = new BufferedWriter(new OutputStreamWriter(System.out)); new BaksmaliDumper(true, true).baksmaliClass(dcn, new BaksmaliDumpOut(w)); w.flush(); } }
public static void writeFileByLine(String filePath, List<String> linesToWrite) throws IOException { LOG.debug("For CGroups - writing {} to {} ", linesToWrite, filePath); File file = new File(filePath); if (!file.exists()) { LOG.error("{} does not exist", filePath); return; } try (FileWriter writer = new FileWriter(file, true); BufferedWriter bw = new BufferedWriter(writer)) { for (String string : linesToWrite) { bw.write(string); bw.newLine(); bw.flush(); } } }
@Override public void execute(Tuple input) { Values values = (Values) input.getValue(0); byte[] array = serializer.write(values, null).array(); String data = new String(array); try { writer.write(data + "\n"); writer.flush(); collector.ack(input); } catch (IOException e) { LOG.error("Error while writing data to socket.", e); collector.reportError(e); collector.fail(input); } }
try { BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); log.write("This will be printed on stdout!\n"); log.flush(); } catch (Exception e) { e.printStackTrace(); }
private Path writeTextTo(final String location) throws IOException { final Path path = Paths.get(location); Files.createDirectories(path.getParent()); try (BufferedWriter buffy = Files.newBufferedWriter(path, Charset.defaultCharset())) { buffy.write("some text"); buffy.newLine(); buffy.flush(); } return path; } }