Java Utililty Methods UTF8

List of utility methods to do UTF8

  1. HOME
  2. Java
  3. U
  4. UTF8

Description

The list of methods to do UTF8 are organized into topic(s).

Method

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!");
String asUtf8(byte[] bytes)
as Utf
return new String(bytes, Charset.forName("UTF-8"));
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!");
InputStream asUtf8ByteStream(final String string)
as Utf Byte Stream
final byte[] data = string.getBytes("utf-8");
final InputStream in = new ByteArrayInputStream(data);
return in;
String asUTF8String(byte[] bytes)
Turns a byte[] array into a UTF8 string
return asString(bytes, UTF_8);
String asUTFString(byte[] content)
as UTF String
return asUTFString(content, 0, content.length);


AltStyle によって変換されたページ (->オリジナル) /