Package com.fasterxml.jackson.core.json
Class ByteSourceJsonBootstrapper
- java.lang.Object
-
- com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper
-
public final class ByteSourceJsonBootstrapper extends java.lang.Object
This class is used to determine the encoding of byte stream that is to contain JSON content. Rules are fairly simple, and defined in JSON specification (RFC-4627 or newer), except for BOM handling, which is a property of underlying streams.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
_bigEndian
Whether input has been detected to be in Big-Endian encoding or not.private boolean
_bufferRecyclable
Flag that indicates whether buffer above is to be recycled after being used or not.private int
_bytesPerChar
private IOContext
_context
private java.io.InputStream
_in
private byte[]
_inputBuffer
private int
_inputEnd
private int
_inputPtr
static byte
UTF8_BOM_1
static byte
UTF8_BOM_2
static byte
UTF8_BOM_3
-
Constructor Summary
Constructors Constructor Description ByteSourceJsonBootstrapper(IOContext ctxt, byte[] inputBuffer, int inputStart, int inputLen)
ByteSourceJsonBootstrapper(IOContext ctxt, java.io.InputStream in)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
checkUTF16(int i16)
private boolean
checkUTF32(int quad)
JsonParser
constructParser(int parserFeatures, ObjectCodec codec, ByteQuadsCanonicalizer rootByteSymbols, CharsToNameCanonicalizer rootCharSymbols, int factoryFeatures)
java.io.Reader
constructReader()
JsonEncoding
detectEncoding()
Method that should be called after constructing an instace.protected boolean
ensureLoaded(int minimum)
private boolean
handleBOM(int quad)
static MatchStrength
hasJSONFormat(InputAccessor acc)
Current implementation is not as thorough as other functionality (ByteSourceJsonBootstrapper
); supports UTF-8, for example.private void
reportWeirdUCS4(java.lang.String type)
private static int
skipSpace(InputAccessor acc)
private static int
skipSpace(InputAccessor acc, byte b)
static int
skipUTF8BOM(java.io.DataInput input)
Helper method that may be called to see if givenDataInput
has BOM marker, and if so, to skip it.private static MatchStrength
tryMatch(InputAccessor acc, java.lang.String matchStr, MatchStrength fullMatchStrength)
-
-
-
Field Detail
-
UTF8_BOM_1
public static final byte UTF8_BOM_1
- See Also:
- Constant Field Values
-
UTF8_BOM_2
public static final byte UTF8_BOM_2
- See Also:
- Constant Field Values
-
UTF8_BOM_3
public static final byte UTF8_BOM_3
- See Also:
- Constant Field Values
-
_context
private final IOContext _context
-
_in
private final java.io.InputStream _in
-
_inputBuffer
private final byte[] _inputBuffer
-
_inputPtr
private int _inputPtr
-
_inputEnd
private int _inputEnd
-
_bufferRecyclable
private final boolean _bufferRecyclable
Flag that indicates whether buffer above is to be recycled after being used or not.
-
_bigEndian
private boolean _bigEndian
Whether input has been detected to be in Big-Endian encoding or not.
-
_bytesPerChar
private int _bytesPerChar
-
-
Method Detail
-
detectEncoding
public JsonEncoding detectEncoding() throws java.io.IOException
Method that should be called after constructing an instace. It will figure out encoding that content uses, to allow for instantiating a proper scanner object.- Throws:
java.io.IOException
-
skipUTF8BOM
public static int skipUTF8BOM(java.io.DataInput input) throws java.io.IOException
Helper method that may be called to see if givenDataInput
has BOM marker, and if so, to skip it.- Throws:
java.io.IOException
- Since:
- 2.8
-
constructReader
public java.io.Reader constructReader() throws java.io.IOException
- Throws:
java.io.IOException
-
constructParser
public JsonParser constructParser(int parserFeatures, ObjectCodec codec, ByteQuadsCanonicalizer rootByteSymbols, CharsToNameCanonicalizer rootCharSymbols, int factoryFeatures) throws java.io.IOException
- Throws:
java.io.IOException
-
hasJSONFormat
public static MatchStrength hasJSONFormat(InputAccessor acc) throws java.io.IOException
Current implementation is not as thorough as other functionality (ByteSourceJsonBootstrapper
); supports UTF-8, for example. But it should work, for now, and can be improved as necessary.- Throws:
java.io.IOException
-
tryMatch
private static MatchStrength tryMatch(InputAccessor acc, java.lang.String matchStr, MatchStrength fullMatchStrength) throws java.io.IOException
- Throws:
java.io.IOException
-
skipSpace
private static int skipSpace(InputAccessor acc) throws java.io.IOException
- Throws:
java.io.IOException
-
skipSpace
private static int skipSpace(InputAccessor acc, byte b) throws java.io.IOException
- Throws:
java.io.IOException
-
handleBOM
private boolean handleBOM(int quad) throws java.io.IOException
- Returns:
- True if a BOM was succesfully found, and encoding thereby recognized.
- Throws:
java.io.IOException
-
checkUTF32
private boolean checkUTF32(int quad) throws java.io.IOException
- Throws:
java.io.IOException
-
checkUTF16
private boolean checkUTF16(int i16)
-
reportWeirdUCS4
private void reportWeirdUCS4(java.lang.String type) throws java.io.IOException
- Throws:
java.io.IOException
-
ensureLoaded
protected boolean ensureLoaded(int minimum) throws java.io.IOException
- Throws:
java.io.IOException
-
-