com.ibm.as400.access

Class ConvTableReader

  • All Implemented Interfaces:
    Closeable, Readable


    public class ConvTableReader
    extends InputStreamReader
    Represents a Toolbox converter that uses stateful character conversion. That is, it wraps an underlying InputStream and reads/caches the appropriate number of bytes to return the requested number of Unicode characters. This is especially useful for mixed-byte tables where the number of converted Unicode characters is almost never the same as the number of underlying EBCDIC bytes. This class exists primarily for use with the IFSTextFile... classes, but other components are free to use it as well.
    See Also:
    ConvTableWriter, ReaderInputStream
    • Field Summary

    • Method Summary

      Methods 
      Modifier and Type Method and Description
      void close()
      Closes this ConvTableReader and its underlying input stream.
      int getByteCacheSize()
      Returns the maximum number of bytes that may be stored in the internal buffer.
      int getCacheSize()
      Returns the maximum number of characters that may be stored in the internal buffer.
      int getCcsid()
      Returns the CCSID used by this ConvTableReader.
      String getEncoding()
      Returns the encoding used by this ConvTableReader.
      boolean markSupported()
      ConvTableReader does not support the mark() operation.
      int read()
      Reads a single character.
      int read(char[] buffer)
      Reads characters into the specified array.
      int read(char[] buffer, int offset, int length)
      Reads characters into a portion of the specified array.
      String read(int length)
      Reads up to length characters out of the underlying stream.
      boolean ready()
      Tells whether this ConvTableReader is ready to be read.
      long skip(long length)
      Skips the specified number of characters in the underlying stream.
    • Constructor Detail

      • ConvTableReader

        public ConvTableReader(InputStream in)
                        throws UnsupportedEncodingException
        Creates a ConvTableReader that uses the default character encoding. The CCSID this reader uses may be set if a known mapping exists for this platform's default character encoding.
        Parameters:
        in - The InputStream from which to read characters.
        Throws:
        UnsupportedEncodingException - If the default character encoding or its associated CCSID is not supported.
      • ConvTableReader

        public ConvTableReader(InputStream in,
                       String encoding)
                        throws UnsupportedEncodingException
        Creates a ConvTableReader that uses the specified character encoding. The CCSID this reader uses may be set if a known mapping exists for the given encoding.
        Parameters:
        in - The InputStream from which to read characters.
        encoding - The name of a supported character encoding.
        Throws:
        UnsupportedEncodingException - If the specified character encoding or its associated CCSID is not supported.
      • ConvTableReader

        public ConvTableReader(InputStream in,
                       int ccsid)
                        throws UnsupportedEncodingException
        Creates a ConvTableReader that uses the specified CCSID.
        Parameters:
        in - The InputStream from which to read characters.
        ccsid - The CCSID.
        Throws:
        UnsupportedEncodingException - If the specified CCSID or its corresponding character encoding is not supported.
      • ConvTableReader

        public ConvTableReader(InputStream in,
                       int ccsid,
                       boolean isXML)
                        throws UnsupportedEncodingException
        Creates a ConvTableReader that uses the specified CCSID.
        Parameters:
        in - The InputStream from which to read characters.
        ccsid - The CCSID.
        isXML - flag that stream is from an XML column type (needed to strip xml declaration)
        Throws:
        UnsupportedEncodingException - If the specified CCSID or its corresponding character encoding is not supported.
      • ConvTableReader

        public ConvTableReader(InputStream in,
                       int ccsid,
                       int bidiStringType,
                       boolean isXML)
                        throws UnsupportedEncodingException
        Creates a ConvTableReader that uses the specified CCSID and bi-directional string type.
        Parameters:
        in - The InputStream from which to read characters.
        ccsid - The CCSID.
        bidiStringType - The bi-directional string type.
        isXML - flag that stream is from an XML column type (needed to strip xml declaration)
        Throws:
        UnsupportedEncodingException - If the specified CCSID or its corresponding character encoding is not supported.
      • ConvTableReader

        public ConvTableReader(InputStream in,
                       int ccsid,
                       BidiConversionProperties properties)
                        throws UnsupportedEncodingException
        Creates a ConvTableReader that uses the specified CCSID and bi-directional string type.
        Parameters:
        in - The InputStream from which to read characters.
        ccsid - The CCSID.
        properties - The bidi conversion properties.
        Throws:
        UnsupportedEncodingException - If the specified CCSID or its corresponding character encoding is not supported.
      • ConvTableReader

        public ConvTableReader(InputStream in,
                       int ccsid,
                       int bidiStringType,
                       int cacheSize)
                        throws UnsupportedEncodingException
        Creates a ConvTableReader that uses the specified CCSID, bi-directional string type, and internal cache size.
        Parameters:
        in - The InputStream from which to read characters.
        ccsid - The CCSID.
        bidiStringType - The bi-directional string type.
        cacheSize - The number of characters to store in the internal buffer. The default is 1024. This number must be greater than zero.
        Throws:
        UnsupportedEncodingException - If the specified CCSID or its corresponding character encoding is not supported.

    • Method Detail

      • close

        public void close()
                   throws IOException
        Closes this ConvTableReader and its underlying input stream. Calling close() multiple times will not throw an exception.
        Specified by:
        close in interface Closeable
        Overrides:
        close in class InputStreamReader
        Throws:
        IOException - If an I/O exception occurs.
      • getByteCacheSize

        public int getByteCacheSize()
        Returns the maximum number of bytes that may be stored in the internal buffer. This number represents the number of bytes that may be read from the underlying InputStream any time a read() method is called on this ConvTableReader.
        Returns:
        The size of the byte cache in use by this ConvTableReader.
      • getCacheSize

        public int getCacheSize()
        Returns the maximum number of characters that may be stored in the internal buffer. This number represents the number of characters that may be converted from the underlying InputStream any time a read() method is called on this ConvTableReader. Note that this is not the number of bytes actually read from the InputStream. The maximum number of bytes that can be read is determined by getByteCacheSize().
        Returns:
        The size of the character cache in use by this ConvTableReader.
      • getCcsid

        public int getCcsid()
        Returns the CCSID used by this ConvTableReader.
        Returns:
        The CCSID, or -1 if the CCSID is not known.
      • getEncoding

        public String getEncoding()
        Returns the encoding used by this ConvTableReader. If the CCSID is not known, the superclass encoding is returned. Otherwise, the corresponding encoding for the CCSID is returned, which may be null if no such mapping exists.
        Overrides:
        getEncoding in class InputStreamReader
        Returns:
        The encoding, or null if the encoding is not known.
      • markSupported

        public boolean markSupported()
        ConvTableReader does not support the mark() operation.
        Overrides:
        markSupported in class Reader
        Returns:
        false.
      • read

        public int read()
                 throws IOException
        Reads a single character. If close() is called prior to calling this method, an exception will be thrown.
        Overrides:
        read in class InputStreamReader
        Returns:
        The character read, or -1 if the end of the stream has been reached.
        Throws:
        IOException - If an I/O exception occurs.
      • read

        public int read(char[] buffer)
                 throws IOException
        Reads characters into the specified array. If close() is called prior to calling this method, an exception will be thrown.
        Overrides:
        read in class Reader
        Parameters:
        buffer - The destination buffer.
        Returns:
        The number of characters read, or -1 if the end of the stream has been reached.
        Throws:
        IOException - If an I/O exception occurs.
      • read

        public int read(char[] buffer,
               int offset,
               int length)
                 throws IOException
        Reads characters into a portion of the specified array. If close() is called prior to calling this method, an exception will be thrown.
        Overrides:
        read in class InputStreamReader
        Parameters:
        buffer - The destination buffer.
        offset - The offset into the buffer at which to begin storing data.
        length - The maximum number of characters to store. If a zero length is specified, this method does nothing and returns 0.
        Returns:
        The number of characters read, or -1 if the end of the stream has been reached.
        Throws:
        IOException - If an I/O exception occurs.
      • read

        public String read(int length)
                    throws IOException
        Reads up to length characters out of the underlying stream. If close() is called prior to calling this method, an exception will be thrown.
        Parameters:
        length - The maximum number of Unicode characters to return as a String. Note that the number of bytes read from the underlying InputStream could be greater than length. If a zero length is specified, this method does nothing and returns "".
        Returns:
        A String of up to length Unicode characters, or null if the end of the stream has been reached. The actual number of characters returned may be less than the specified length if the end of the underlying InputStream is reached while reading.
        Throws:
        IOException - If an I/O exception occurs.
      • ready

        public boolean ready()
                      throws IOException
        Tells whether this ConvTableReader is ready to be read. A ConvTableReader is ready if its input buffer is not empty or if bytes are available to be read from the underlying input stream. If close() is called, a call to ready() will always return false.
        Overrides:
        ready in class InputStreamReader
        Returns:
        true if the ConvTableReader is ready to read characters; false otherwise.
        Throws:
        IOException - If an I/O exception occurs.
      • skip

        public long skip(long length)
                  throws IOException
        Skips the specified number of characters in the underlying stream. If close() is called prior to calling this method, an exception will be thrown.
        Overrides:
        skip in class Reader
        Parameters:
        length - The number of characters to skip.
        Returns:
        The number of characters actually skipped.
        Throws:
        IOException - If an I/O exception occurs.