Package org.joda.beans.ser
Class JodaBeanSmartReader
- java.lang.Object
-
- org.joda.beans.ser.JodaBeanSmartReader
-
public class JodaBeanSmartReader extends Object
Determines the correct file format and parses it appropriately.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isKnownFormat(byte[] input)
Checks if the input is a serialized Joda-Bean.boolean
isKnownFormat(InputStream input)
Checks if the input is a serialized Joda-Bean.Bean
read(byte[] input)
Reads and parses to a bean.<T> T
read(byte[] input, Class<T> rootType)
Reads and parses to a bean.Bean
read(InputStream input)
Reads and parses to a bean.<T> T
read(InputStream input, Class<T> rootType)
Reads and parses to a bean.
-
-
-
Method Detail
-
isKnownFormat
public boolean isKnownFormat(byte[] input)
Checks if the input is a serialized Joda-Bean.XML and JSON files may be prefixed by the UTF-8 Unicode BOM.
Callers may pass in part of the file, rather than the whole file. Up to 128 bytes are needed to determine the format (XML requires the most, others far less).
- Parameters:
input
- the input bytes to check, which need only consist of the first 128 bytes of the file, not null- Returns:
- true if it is a known format
-
isKnownFormat
public boolean isKnownFormat(InputStream input)
Checks if the input is a serialized Joda-Bean.XML and JSON files may be prefixed by the UTF-8 Unicode BOM.
The input stream will be marked and reset, thus these operations must be supported. As such, the same stream can then be for parsing.
- Parameters:
input
- the input stream to check, where only the first few bytes are read, not null- Returns:
- true if it is a known format
- Throws:
UncheckedIOException
- if unable to read the streamIllegalArgumentException
- if the input stream does not support mark/reset
-
read
public Bean read(byte[] input)
Reads and parses to a bean.XML and JSON files may be prefixed by the UTF-8 Unicode BOM.
- Parameters:
input
- the input bytes to parse, not null- Returns:
- the bean, not null
- Throws:
IllegalArgumentException
- if the file format is not recognizedRuntimeException
- if unable to parse
-
read
public <T> T read(byte[] input, Class<T> rootType)
Reads and parses to a bean.XML and JSON files may be prefixed by the UTF-8 Unicode BOM.
- Type Parameters:
T
- the root type- Parameters:
input
- the input bytes to parse, not nullrootType
- the root type, not null- Returns:
- the bean, not null
- Throws:
IllegalArgumentException
- if the file format is not recognizedRuntimeException
- if unable to parse
-
read
public Bean read(InputStream input)
Reads and parses to a bean.XML and JSON files may be prefixed by the UTF-8 Unicode BOM.
- Parameters:
input
- the input stream, not null- Returns:
- the bean, not null
- Throws:
UncheckedIOException
- if unable to read the streamIllegalArgumentException
- if the file format is not recognizedRuntimeException
- if unable to parse
-
read
public <T> T read(InputStream input, Class<T> rootType)
Reads and parses to a bean.XML and JSON files may be prefixed by the UTF-8 Unicode BOM.
- Type Parameters:
T
- the root type- Parameters:
input
- the input stream, not nullrootType
- the root type, not null- Returns:
- the bean, not null
- Throws:
UncheckedIOException
- if unable to read the streamIllegalArgumentException
- if the file format is not recognizedRuntimeException
- if unable to parse
-
-