Class ReaderFactory


  • public class ReaderFactory
    extends Object
    Utility to create Readers from streams, with explicit encoding choice: platform default, XML, or specified.
    Since:
    1.4.3
    Author:
    Herve Boutemy
    See Also:
    Charset, Supported encodings
    • Field Detail

      • ISO_8859_1

        public static final String ISO_8859_1
        ISO Latin Alphabet #1, also known as ISO-LATIN-1. Every implementation of the Java platform is required to support this character encoding.
        See Also:
        Charset, Constant Field Values
      • US_ASCII

        public static final String US_ASCII
        Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set. Every implementation of the Java platform is required to support this character encoding.
        See Also:
        Charset, Constant Field Values
      • UTF_16

        public static final String UTF_16
        Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either order accepted on input, big-endian used on output). Every implementation of the Java platform is required to support this character encoding.
        See Also:
        Charset, Constant Field Values
      • UTF_16BE

        public static final String UTF_16BE
        Sixteen-bit Unicode Transformation Format, big-endian byte order. Every implementation of the Java platform is required to support this character encoding.
        See Also:
        Charset, Constant Field Values
      • UTF_16LE

        public static final String UTF_16LE
        Sixteen-bit Unicode Transformation Format, little-endian byte order. Every implementation of the Java platform is required to support this character encoding.
        See Also:
        Charset, Constant Field Values
      • UTF_8

        public static final String UTF_8
        Eight-bit Unicode Transformation Format. Every implementation of the Java platform is required to support this character encoding.
        See Also:
        Charset, Constant Field Values
      • FILE_ENCODING

        public static final String FILE_ENCODING
        The file.encoding System Property.
    • Constructor Detail

      • ReaderFactory

        public ReaderFactory()
    • Method Detail

      • newXmlReader

        public static XmlStreamReader newXmlReader​(File file)
                                            throws IOException
        Create a new Reader with XML encoding detection rules.
        Parameters:
        file - not null file.
        Returns:
        an XML reader instance for the input file.
        Throws:
        IOException - if any.
        See Also:
        XmlStreamReader
      • newXmlReader

        public static XmlStreamReader newXmlReader​(URL url)
                                            throws IOException
        Create a new Reader with XML encoding detection rules.
        Parameters:
        url - not null url.
        Returns:
        an XML reader instance for the input url.
        Throws:
        IOException - if any.
        See Also:
        XmlStreamReader
      • newPlatformReader

        public static Reader newPlatformReader​(InputStream in)
        Create a new Reader with default platform encoding.
        Parameters:
        in - not null input stream.
        Returns:
        a reader instance for the input stream using the default platform charset.
        See Also:
        Charset.defaultCharset()
      • newPlatformReader

        public static Reader newPlatformReader​(File file)
                                        throws IOException
        Create a new Reader with default platform encoding.
        Parameters:
        file - not null file.
        Returns:
        a reader instance for the input file using the default platform charset.
        Throws:
        IOException - if any.
        See Also:
        Charset.defaultCharset()
      • newPlatformReader

        public static Reader newPlatformReader​(URL url)
                                        throws IOException
        Create a new Reader with default platform encoding.
        Parameters:
        url - not null url.
        Returns:
        a reader instance for the input url using the default platform charset.
        Throws:
        IOException - if any.
        See Also:
        Charset.defaultCharset()
      • newReader

        public static Reader newReader​(File file,
                                       String encoding)
                                throws IOException
        Create a new Reader with specified encoding. Note that there is no buffering on this reader, which favours clients that read into large buffers (8K+).
        Parameters:
        file - not null file.
        encoding - not null supported encoding.
        Returns:
        a reader instance for the input file using the given encoding.
        Throws:
        IOException - if any.
        See Also:
        Supported encodings
      • newReader

        public static Reader newReader​(URL url,
                                       String encoding)
                                throws IOException
        Create a new Reader with specified encoding.
        Parameters:
        url - not null url.
        encoding - not null supported encoding.
        Returns:
        a reader instance for the input url using the given encoding.
        Throws:
        IOException - if any.
        See Also:
        Supported encodings