Package org.dellroad.stuff.io
Class BOMReader
java.lang.Object
java.io.Reader
org.dellroad.stuff.io.BOMReader
- All Implemented Interfaces:
Closeable,AutoCloseable,Readable
A
Reader that wraps an InputStream, detects and strips the byte order mark, and then converts
bytes into characters accordingly.
If no byte order mark is found, the input is implicitly assumed to be in some default character encoding.
The default character encoding and the action to take on malformed input are configurable.
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionBOMReader(InputStream input) Constructor.BOMReader(InputStream input, CodingErrorAction errorAction, Charset defaultCharset) Primary constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()getBOM()Get theBOMfound at the beginning of the input.Get the actual character encoding used.voidmark(int limit) intread()intread(char[] cbuf) intread(char[] cbuf, int off, int len) intread(CharBuffer target) booleanready()voidreset()longskip(long num) Methods inherited from class java.io.Reader
markSupported, nullReader, transferTo
-
Constructor Details
-
BOMReader
Constructor.Equivalent to
BOMReader(input, CodingErrorAction.REPORT, Charset.defaultCharset()).- Parameters:
input- data input- Throws:
IllegalArgumentException- ifinputis null
-
BOMReader
Primary constructor.The
errorActionconfigures the behavior when malformed input is encountered; in the case ofCodingErrorAction.REPORT, aMalformedInputExceptionexception is thrown.- Parameters:
input- data inputerrorAction- what to do about malformed inputdefaultCharset- character encoding to use if no BOM is found- Throws:
IllegalArgumentException- if any parameter is null
-
-
Method Details
-
getBOM
Get theBOMfound at the beginning of the input.If no input has been read yet, this method will trigger the reading of the first few bytes.
- Returns:
- the BOM that was detected, or null if no supported BOM was found
- Throws:
IOException
-
getCharset
Get the actual character encoding used.If no input has been read yet, this method will trigger the reading of the first few bytes.
- Returns:
- the character encoding chosen to decode the data, never null
- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classReader- Throws:
IOException
-
mark
- Overrides:
markin classReader- Throws:
IOException
-
read
- Overrides:
readin classReader- Throws:
IOException
-
read
- Overrides:
readin classReader- Throws:
IOException
-
read
- Specified by:
readin classReader- Throws:
IOException
-
read
- Specified by:
readin interfaceReadable- Overrides:
readin classReader- Throws:
IOException
-
ready
- Overrides:
readyin classReader- Throws:
IOException
-
reset
- Overrides:
resetin classReader- Throws:
IOException
-
skip
- Overrides:
skipin classReader- Throws:
IOException
-