Class JodaBeanSmartReader


  • public class JodaBeanSmartReader
    extends Object
    Determines the correct file format and parses it appropriately.
    • 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 stream
        IllegalArgumentException - 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 recognized
        RuntimeException - 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 null
        rootType - the root type, not null
        Returns:
        the bean, not null
        Throws:
        IllegalArgumentException - if the file format is not recognized
        RuntimeException - 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 null
        rootType - the root type, not null
        Returns:
        the bean, not null
        Throws:
        UncheckedIOException - if unable to read the stream
        IllegalArgumentException - if the file format is not recognized
        RuntimeException - if unable to parse