List of usage examples for java.io Writer flush
public abstract void flush() throws IOException;
From source file:org.crazydog.util.spring.StreamUtils.java
/** * Copy the contents of the given String to the given output OutputStream. * Leaves the stream open when done./*from w ww . j av a2 s . c o m*/ * @param in the String to copy from * @param charset the Charset * @param out the OutputStream to copy to * @throws IOException in case of I/O errors */ public static void copy(String in, Charset charset, OutputStream out) throws IOException { org.springframework.util.Assert.notNull(in, "No input String specified"); org.springframework.util.Assert.notNull(charset, "No charset specified"); org.springframework.util.Assert.notNull(out, "No OutputStream specified"); Writer writer = new OutputStreamWriter(out, charset); writer.write(in); writer.flush(); }
From source file:com.asakusafw.yaess.tools.Explain.java
private static void explainBatch(BatchScript script) throws IOException { assert script != null; JsonObject batch = analyzeBatch(script); Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create(); Writer writer = new PrintWriter(new OutputStreamWriter(System.out, Charset.defaultCharset())); gson.toJson(batch, writer);/*from w w w. j a v a 2s .co m*/ writer.flush(); }
From source file:Main.java
public static void write(Reader input, OutputStream output) throws IOException { Writer out = new OutputStreamWriter(output); write(input, out);//from w w w .j ava2s .c o m out.flush(); }
From source file:boxConnection.SerBoxTelnet.java
public static void runReboot() throws IOException, InterruptedException { Logger.getLogger("SerBoxTelnet").info(ControlMain.getProperty("msg_reboot")); telnet.connect(ControlMain.getActiveBox().getDboxIp()); OutputStream ostream = telnet.getOutputStream(); Writer writer = new OutputStreamWriter(ostream); writer.write(ControlMain.getActiveBox().getLogin() + "\n"); writer.flush(); Thread.sleep(1000);/*from w w w . jav a2s .co m*/ writer.write(ControlMain.getActiveBox().getPassword() + "\n"); writer.flush(); Thread.sleep(1000); writer.write("killall sectionsd" + "\n"); writer.flush(); Thread.sleep(1000); writer.write("killall camd2" + "\n"); writer.flush(); Thread.sleep(1000); writer.write("killall timerd" + "\n"); writer.flush(); Thread.sleep(1000); writer.write("killall timerd" + "\n"); writer.flush(); Thread.sleep(1000); writer.write("killall zapit" + "\n"); writer.flush(); Thread.sleep(1000); writer.write("killall controld" + "\n"); writer.flush(); Thread.sleep(1000); writer.write("killall nhttpd" + "\n"); writer.flush(); Thread.sleep(1000); writer.write("sleep 3" + "\n"); writer.flush(); Thread.sleep(1000); writer.write("busybox -reboot" + "\n"); writer.flush(); Thread.sleep(1000); closeTelnetSession(); }
From source file:Main.java
public static void write(Reader input, OutputStream output, String encoding) throws IOException { Writer out = new OutputStreamWriter(output, encoding); write(input, out);/*from w w w . j a va 2 s . c om*/ out.flush(); }
From source file:Main.java
/** * Writes out the contents./* ww w . j a v a 2 s.c o m*/ * @param outFile outFile * @param contents contents * @throws FileNotFoundException FileNotFoundException * @throws IOException IOException */ public static void setContents(final File outFile, final String contents) throws FileNotFoundException, IOException { if (outFile == null) { throw new IllegalArgumentException("File should not be null."); //$NON-NLS-1$ } if (outFile.exists()) { if (!outFile.isFile()) { throw new IllegalArgumentException("Should not be a directory: " + outFile); //$NON-NLS-1$ } if (!outFile.canWrite()) { throw new IllegalArgumentException("File cannot be written: " + outFile); //$NON-NLS-1$ } } Writer output = null; try { output = new BufferedWriter(new FileWriter(outFile)); if (contents != null) { output.write(contents); output.flush(); } } finally { if (output != null) { output.close(); } } }
From source file:com.ikon.util.FileLogger.java
/** * Write to log file/* w w w. j a v a 2s. com*/ * * @throws IOException If there is an exception when writing. */ private static void logWrite(String baseName, String level, String message, Object... params) throws IOException { Writer sLogger = new FileWriter(getLogFile(baseName), true); sLogger.write(getLogEntry(level, message, params)); sLogger.flush(); sLogger.close(); }
From source file:com.scorpio4.util.io.StreamCopy.java
public static void copy(Reader input, Writer output, int buffer_size) throws IOException { char[] buffer = new char[buffer_size + 16]; int n = 0;//w w w . j a v a 2s. c o m while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); output.flush(); } output.flush(); }
From source file:Main.java
/** * Copy a reader to writer./*from www . j ava2 s .c om*/ */ private static void copy(Reader in, Writer out) throws IOException { try { int bytesRead; char[] buffer = new char[COPY_BUFFER_SIZE]; while ((bytesRead = in.read(buffer)) != -1) { out.write(buffer, 0, bytesRead); } out.flush(); } finally { in.close(); out.close(); } }
From source file:Dengue.CDengueManager.java
private static void sendInfoToCPU(String pStrJSON, int pIntPort) { new Thread(() -> { try (Socket client = new Socket(InetAddress.getLocalHost(), pIntPort)) { Writer objWriter = Channels.newWriter(Channels.newChannel(client.getOutputStream()), StandardCharsets.US_ASCII.name()); objWriter.write(pStrJSON);// w ww . j a v a2s . co m objWriter.flush(); client.shutdownOutput(); try (Reader objReader = Channels.newReader(Channels.newChannel(client.getInputStream()), StandardCharsets.US_ASCII.name()); BufferedReader objOutReader = new BufferedReader(objReader)) { System.out.println((char) objOutReader.read()); } } catch (IOException e) { System.out.println(e); } }).start(); }