List of utility methods to do UTF File Write
PrintWriter | writeFileUTF(String nom) write File UTF return new PrintWriter(getUTF8Writer(new File(nom))); |
void | writeStringAsUTFByteArrayToDataOutput(final DataOutput out, final String str) Writes a string into a DataOutput. byte[] byteArray = str.getBytes(StandardCharsets.UTF_8);
out.writeInt(byteArray.length);
out.write(byteArray);
|
void | writeToFile(File outputFile, String content) Writes string content to a file. Preconditions.checkNotNull(outputFile);
Preconditions.checkNotNull(content);
try (BufferedWriter outWriter = Files.newWriter(outputFile, StandardCharsets.UTF_8)) {
outWriter.write(content);
|
void | writeToFile(String outputFile, String contents) write To File writeToFile(Paths.get(outputFile), contents); |
void | writeToFile(String outputFilePath, String generated) write To File File outputFile = new File(outputFilePath); if (outputFile.getParent() != null && !new File(outputFile.getParent()).exists()) { File parent = new File(outputFile.getParent()); parent.mkdirs(); try (PrintWriter output = new PrintWriter(outputFile, Charset.forName("UTF-8").name())) { output.print(generated); } catch (FileNotFoundException | UnsupportedEncodingException e) { ... |
void | writeUTF8(DataOutput buf, String value) Writes an UTF8 string to a byte buffer. final byte[] bytes = value.getBytes(StandardCharsets.UTF_8); if (bytes.length >= Short.MAX_VALUE) { throw new IOException( "Attempt to write a string with a length greater than Short.MAX_VALUE to ByteBuf!"); writeVarInt(buf, bytes.length); buf.write(bytes); |
void | writeUTF8(final String filePath, final String content) write UTF Files.write(FileSystems.getDefault().getPath(filePath), content.getBytes(StandardCharsets.UTF_8)); |
void | writeUTF8(OutputStream out, String str) Writes the string out as UTF-8 byte[] s = str.getBytes(UTF8);
out.write(s);
|
void | writeUtf8String(final DataOutputStream out, final String str) Writes a UTF-8 string to the buffer. byte[] bytes = str.getBytes(CHARSET_UTF8); if (bytes.length > MAXLEN) { throw new IllegalArgumentException("Encoded UTF-8 string too long."); out.writeShort(bytes.length); out.write(bytes); |
void | writeUTF8WithLength(OutputStream out, String str) Writes out a 4 byte integer of the length (in bytes!) of the String, followed by the String (as UTF-8) byte[] s = str.getBytes(UTF8);
writeInt4(out, s.length);
out.write(s);
|