The list of methods to do UTF8 are organized into topic(s).
void
addLineIds(String inFile, String outFile) add Line Ids
StringBuilder builder = new StringBuilder();
List<String> list = Files.readAllLines(Paths.get(inFile), StandardCharsets.UTF_8);
int id = 1;
for (String line : list) {
builder.append(id + "\t" + line);
builder.append(System.lineSeparator());
id++;
writeFile(builder.toString(), outFile, false);
void
appendToFile(String outputFile, String contents) append To File
try {
Files.write(Paths.get(outputFile), contents.getBytes(), StandardOpenOption.APPEND);
} catch (IOException e) {
throw new UnsupportedOperationException("Failed to append to file '" + outputFile + "'", e);
String
asStringUTF8(byte[] bytes) Return the String representation of the byte array.
if (bytes == null) {
return null;
if (bytes.length == 0) {
return EMPTY_STRING;
return new String(bytes, CHARSET_UTF8);
String
asUTF16BEEncoded(String basicString) Take a basic PDF string and produce a string from its bytes as an UTF16-BE encoding.
try {
return new String(asBytes(basicString), 2, basicString.length() - 2, "UTF-16BE");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("No UTF-16BE charset!");
Reader
asUTF8(InputStream in) Create a reader that uses UTF-8 encoding
return new InputStreamReader(in, utf8.newDecoder());
byte[]
asUTF8bytes(String s) as UT Fbytes
try {
return s.getBytes("UTF-8");
} catch (UnsupportedEncodingException ex) {
throw new InternalError("UTF-8 not supported!");