/** * Append bytes to the end of a Path. It <strong>will not</strong> be * interpreted as text. * * @param self a Path * @param bytes the byte array to append to the end of the Path * @throws java.io.IOException if an IOException occurs. * @since 2.3.0 */ public static void append(Path self, byte[] bytes) throws IOException { OutputStream stream = null; try { stream = Files.newOutputStream(self, CREATE, APPEND); stream.write(bytes, 0, bytes.length); stream.flush(); OutputStream temp = stream; stream = null; temp.close(); } finally { closeWithWarning(stream); } }
/** * Write the text to the Path, using the specified encoding. If the given * charset is "UTF-16BE" or "UTF-16LE" (or an equivalent alias) and * <code>writeBom</code> is <code>true</code>, the requisite byte order * mark is written to the file before the text. * * @param self a Path * @param text the text to write to the Path * @param charset the charset used * @param writeBom whether to write a BOM * @throws java.io.IOException if an IOException occurs. * @since 2.5.0 */ public static void write(Path self, String text, String charset, boolean writeBom) throws IOException { Writer writer = null; try { OutputStream out = Files.newOutputStream(self); if (writeBom) { IOGroovyMethods.writeUTF16BomIfRequired(out, charset); } writer = new OutputStreamWriter(out, Charset.forName(charset)); writer.write(text); writer.flush(); Writer temp = writer; writer = null; temp.close(); } finally { closeWithWarning(writer); } }
/** * Append bytes to the end of a Path. It <strong>will not</strong> be * interpreted as text. * * @param self a Path * @param bytes the byte array to append to the end of the Path * @throws java.io.IOException if an IOException occurs. * @since 2.3.0 */ public static void append(Path self, byte[] bytes) throws IOException { OutputStream stream = null; try { stream = Files.newOutputStream(self, CREATE, APPEND); stream.write(bytes, 0, bytes.length); stream.flush(); OutputStream temp = stream; stream = null; temp.close(); } finally { closeWithWarning(stream); } }
/** * Append binary data to the file. It <strong>will not</strong> be * interpreted as text. * * @param self a Path * @param stream stream to read data from. * @throws java.io.IOException if an IOException occurs. * @since 2.3.0 */ public static void append(Path self, InputStream stream) throws IOException { OutputStream out = Files.newOutputStream(self, CREATE, APPEND); try { IOGroovyMethods.leftShift(out, stream); } finally { closeWithWarning(out); } }
private static void appendBuffered(Path file, Object text, String charset, boolean writeBom) throws IOException { BufferedWriter writer = null; try { boolean shouldWriteBom = writeBom && !file.toFile().exists(); writer = newWriter(file, charset, true); if (shouldWriteBom) { IOGroovyMethods.writeUTF16BomIfRequired(writer, charset); } InvokerHelper.write(writer, text); writer.flush(); Writer temp = writer; writer = null; temp.close(); } finally { closeWithWarning(writer); } }
/** * Write the text to the Path, using the specified encoding. If the given * charset is "UTF-16BE" or "UTF-16LE" (or an equivalent alias) and * <code>writeBom</code> is <code>true</code>, the requisite byte order * mark is written to the file before the text. * * @param self a Path * @param text the text to write to the Path * @param charset the charset used * @param writeBom whether to write a BOM * @throws java.io.IOException if an IOException occurs. * @since 2.5.0 */ public static void write(Path self, String text, String charset, boolean writeBom) throws IOException { Writer writer = null; try { OutputStream out = Files.newOutputStream(self); if (writeBom) { IOGroovyMethods.writeUTF16BomIfRequired(out, charset); } writer = new OutputStreamWriter(out, Charset.forName(charset)); writer.write(text); writer.flush(); Writer temp = writer; writer = null; temp.close(); } finally { closeWithWarning(writer); } }
temp.close(); } finally { closeWithWarning(writer);