本文整理了Java中java.io.BufferedWriter.flush()
方法的一些代码示例,展示了BufferedWriter.flush()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BufferedWriter.flush()
方法的具体详情如下:
包路径:java.io.BufferedWriter
类名称:BufferedWriter
方法名:flush
[英]Flushes this writer. The contents of the buffer are committed to the target writer and it is then flushed.
[中]
代码示例来源:origin: apache/storm
private void writeString(String str) throws IOException {
processIn.write(str);
processIn.write("\nend\n");
processIn.flush();
}
代码示例来源:origin: stanfordnlp/CoreNLP
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();
}
代码示例来源:origin: gocd/gocd
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);
}
}
代码示例来源:origin: konsoletyper/teavm
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();
}
代码示例来源:origin: kairosdb/kairosdb
private void closeDataFile() throws IOException
{
m_dataWriter.write("]");
m_dataWriter.flush();
m_dataWriter.close();
}
代码示例来源:origin: alibaba/TProfiler
/**
*
*/
public void closeFile() {
if (bufferedWriter != null) {
try {
bufferedWriter.flush();
bufferedWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: stackoverflow.com
try (FileWriter fw = new FileWriter(file)) {
BufferedWriter bw = new BufferedWriter(fw);
bw.write(text);
bw.flush();
}
代码示例来源:origin: MovingBlocks/Terasology
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)));
}
代码示例来源:origin: oldmanpushcart/greys-anatomy
@Override
public void actionPerformed(ActionEvent e) {
try {
socketWriter.write(CTRL_D);
socketWriter.flush();
} catch (Exception e1) {
// 这里是控制台,可能么?
GreysConsole.this.err("write fail : %s", e1.getMessage());
shutdown();
}
}
代码示例来源:origin: pxb1988/dex2jar
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();
}
代码示例来源:origin: stackoverflow.com
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);
}
代码示例来源:origin: pxb1988/dex2jar
@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);
}
}
};
代码示例来源:origin: oldmanpushcart/greys-anatomy
private void disableSilentOfSession() throws IOException {
socketWriter.write("session -s false\n");
socketWriter.flush();
waitingForEOT();
}
代码示例来源:origin: androidannotations/androidannotations
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;
}
代码示例来源:origin: pxb1988/dex2jar
@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();
}
}
代码示例来源:origin: facebook/stetho
public void send(String message) throws IOException {
mReporter.onSend(message);
try {
mOutput.write(message + "\r\n");
mOutput.flush();
} catch (IOException e) {
mReporter.onError(e);
throw e;
}
}
代码示例来源:origin: apache/storm
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();
}
}
}
代码示例来源:origin: apache/storm
@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);
}
}
代码示例来源:origin: stackoverflow.com
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();
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
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;
}
}
内容来源于网络,如有侵权,请联系作者删除!