Class JodaBeanSmartReader


  • public class JodaBeanSmartReader
    extends java.lang.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​(java.io.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, java.lang.Class<T> rootType)
      Reads and parses to a bean.
      Bean read​(java.io.InputStream input)
      Reads and parses to a bean.
      <T> T read​(java.io.InputStream input, java.lang.Class<T> rootType)
      Reads and parses to a bean.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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​(java.io.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:
        java.io.UncheckedIOException - if unable to read the stream
        java.lang.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:
        java.lang.IllegalArgumentException - if the file format is not recognized
        java.lang.RuntimeException - if unable to parse
      • read

        public <T> T read​(byte[] input,
                          java.lang.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:
        java.lang.IllegalArgumentException - if the file format is not recognized
        java.lang.RuntimeException - if unable to parse
      • read

        public Bean read​(java.io.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:
        java.io.UncheckedIOException - if unable to read the stream
        java.lang.IllegalArgumentException - if the file format is not recognized
        java.lang.RuntimeException - if unable to parse
      • read

        public <T> T read​(java.io.InputStream input,
                          java.lang.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:
        java.io.UncheckedIOException - if unable to read the stream
        java.lang.IllegalArgumentException - if the file format is not recognized
        java.lang.RuntimeException - if unable to parse