List of usage examples for java.io Writer close
public abstract void close() throws IOException;
From source file:com.github.rnewson.couchdb.lucene.util.ServletUtils.java
public static void sendJson(final HttpServletRequest req, final HttpServletResponse resp, final JSONObject json) throws IOException { setResponseContentTypeAndEncoding(req, resp); final Writer writer = resp.getWriter(); try {/*ww w. j av a 2 s .c o m*/ writer.write(json.toString() + "\r\n"); } finally { writer.close(); } }
From source file:com.uksf.mf.core.utility.LogHandler.java
/** * Writes to file//from ww w . j a va2s . com * @param log formatted message to write */ private static void toFile(String log) { try { Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(logFile, true))); writer.append(log).append("\n"); writer.close(); } catch (IOException e) { error(e); } }
From source file:co.cask.cdap.filetailer.tailer.TailerLogUtils.java
public static void writeLineToFile(String filePath, String line) throws IOException { Writer writer = new FileWriter(filePath, true); writer.write(line + "\n"); writer.flush();// w w w.j a va 2s. co m writer.close(); }
From source file:com.twitter.ambrose.util.JSONUtil.java
public static void writeJson(String fileName, Object object) throws IOException { Writer writer = new PrintWriter(fileName); try {//from w w w . j a va 2 s .com JSONUtil.writeJson(writer, object); } finally { writer.close(); } }
From source file:com.richtodd.android.repository.JSONUtility.java
public static void saveJSONObject(File file, JSONObject jsonObject) throws RepositoryException { try {/*from w ww . j a v a2 s . c om*/ String jsonString = jsonObject.toString(); OutputStream out = new FileOutputStream(file); try { Writer writer = new OutputStreamWriter(out); try { writer.write(jsonString); } finally { writer.close(); } } finally { out.close(); } } catch (FileNotFoundException ex) { throw new RepositoryException(ex); } catch (IOException ex) { throw new RepositoryException(ex); } }
From source file:com.github.rnewson.couchdb.lucene.util.ServletUtils.java
public static void sendJsonError(final HttpServletRequest request, final HttpServletResponse response, final int code, final JSONObject error) throws IOException, JSONException { setResponseContentTypeAndEncoding(request, response); response.setHeader(HttpHeaders.CACHE_CONTROL, "must-revalidate,no-cache,no-store"); response.setStatus(code);/*from ww w . j a v a 2 s . c o m*/ error.put("code", code); final Writer writer = response.getWriter(); try { writer.write(error.toString()); writer.write("\r\n"); } finally { writer.close(); } }
From source file:Main.java
/** * Dump a <code>String</code> to a text file. * * @param file The output file//from w w w.j a va2 s. c o m * @param string The string to be dumped * @param encoding The encoding for the output file or null for default platform encoding * @exception IOException IO Error */ public static void serializeString(File file, String string, String encoding) throws IOException { final Writer fw = (encoding == null) ? new FileWriter(file) : new OutputStreamWriter(new FileOutputStream(file), encoding); try { fw.write(string); fw.flush(); } finally { fw.close(); } }
From source file:de.huxhorn.sulky.io.IOUtilities.java
/** * Unconditionally close a <code>Writer</code>. * <p>// w w w . j av a2 s .c om * Equivalent to {@link Writer#close()}, except any exceptions will be ignored. * {@link InterruptedIOException} is handled correctly by {@link #interruptIfNecessary(Throwable)}. * This is typically used in finally blocks. * * @param x the Writer to close, may be null or already closed */ public static void closeQuietly(Writer x) { if (x == null) { return; } try { x.close(); } catch (IOException e) { interruptIfNecessary(e); } }
From source file:Base64.java
private static void writeChars(File file, char[] data) { try {//from w w w . j a v a2 s . co m Writer fos = new FileWriter(file); Writer os = new BufferedWriter(fos); os.write(data); os.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ikon.util.FileLogger.java
/** * Write to log file// w ww .j a v a 2s. c om * * @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(); }