public final class UnicodeBom extends Object
A Unicode file may contain a Byte Order Mark (BOM) that specifies which encoding is used. Sadly, neither the JDK nor Guava handle this properly.
This class supports the BOM for UTF-8, UTF-16LE and UTF-16BE. The UTF-32 formats are rarely seen and cannot be easily determined as the UTF-32 BOMs are similar to the UTF-16 BOMs.
| Modifier and Type | Method and Description |
|---|---|
static CharSource |
toCharSource(ByteSource byteSource)
Converts a
ByteSource to a CharSource. |
static Reader |
toReader(InputStream inputStream)
Converts an
InputStream to a Reader. |
static String |
toString(byte[] input)
Converts a
byte[] to a String. |
public static String toString(byte[] input)
byte[] to a String.
This ensures that any Unicode byte order marker is used correctly. The default encoding is UTF-8 if no BOM is found.
input - the input byte arraypublic static CharSource toCharSource(ByteSource byteSource)
ByteSource to a CharSource.
This ensures that any Unicode byte order marker is used correctly. The default encoding is UTF-8 if no BOM is found.
byteSource - the byte sourcepublic static Reader toReader(InputStream inputStream) throws IOException
InputStream to a Reader.
This ensures that any Unicode byte order marker is used correctly. The default encoding is UTF-8 if no BOM is found.
inputStream - the input stream to wrapIOException - if an IO error occursCopyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.