ca.idms.io
Class NativeDataInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by ca.idms.io.NativeDataInputStream
All Implemented Interfaces:
java.io.Closeable, java.io.DataInput
Direct Known Subclasses:
FloDataInputStream, LoDataInputStream, UnicodeDataInputStream, UtfDataInputStream

public class NativeDataInputStream
extends java.io.FilterInputStream
implements java.io.DataInput

A NativeDataInputStream reads "native" data from a buffered input stream. This class combines a DataInputStream, a NativeFormat, and a TraceBufferInputStream, and provides additional features to those defined by the DataInput interface:

  • The data conversion methods are optimized to take advantage of the direct access to the byte array buffer provided by the TraceBufferInputStream.
  • The methods provided by the TraceBufferInputStream to access the underlying byte array are exposed to the caller.
  • The native data conversion options specifed in the NativeFormat are encapsulated and transparent to the caller in most cases.
  • Additional methods are provided to read and convert data, including native character set data and OS/390 formats, including packed decimal, zoned decimal, and DBCS.
  • Unlike DataInputStream, the methods are not final, so this class can be a base class for specialized data input classes. The exceptions are the same as those defined by the DataInput interface and the DataInputStream class.

    Since:
    CA IDMS Server 4.2 OS/390 Edition
    Version:
    1.00, 12/14/99
    Author:
    Dave Ross
    See Also:
    TraceBufferInputStream, NativeFormat, LoDataInputStream, FloDataInputStream, UtfDataInputStream, UnicodeDataInputStream

    Field Summary
    protected  java.io.DataInputStream dis
              Contains the default methods.
    protected  NativeFormat fmt
              Describes the native data formats.
     
    Fields inherited from class java.io.FilterInputStream
    in
     
    Method Summary
     byte[] getBuffer()
              Gets a reference to the buffer.
     int getCount()
              Gets the number of valid bytes in the buffer.
     NativeFormat getFormat()
              Gets the data formats in effect for this stream.
     int getPosition()
              Gets the index of the next character to be read.
     boolean readBoolean()
              Reads a boolean from the data input stream.
     byte readByte()
              Reads a signed 8-bit value from the data input stream.
     java.lang.String readBytes(int len)
              Reads a string from a stream as an array of bytes.
     java.lang.String readBytesInternal(int len)
              Reads an internal control block string from a stream as an array of bytes.
     java.lang.String readBytesKatakana(int len)
              Reads a single byte Katakana string from a stream as an array of bytes.
     char readChar()
              Reads a Unicode character from the underlying input stream, by calling the DataInputStream readChar method.
     double readDouble()
              Reads a double from the data input stream.
     float readFloat()
              Reads a float from the data input stream.
     void readFully(byte[] b)
              Reads b.length bytes from the data input stream.
     void readFully(byte[] b, int off, int len)
              Reads exactly len bytes from the data input stream.
     java.lang.String readGraphic(int len)
              Reads OS/390 DBCS data into String.
     int readInt()
              Reads an int from the data input stream.
     java.lang.String readLine()
              Deprecated. But specified by the DataInput interface.
     long readLong()
              Reads a long from the data input stream.
     java.math.BigDecimal readPacked(int prec, int scale)
              Reads a native format PACKED DECIMAL into a BigDecimal.
     short readShort()
              Reads a short from the data input stream.
     int readUnsignedByte()
              Reads an unsigned 8-bit number from the underlying data input stream.
     int readUnsignedShort()
              Reads an unsigned short from the data input stream.
     java.lang.String readUTF()
              Reads a string that has been encoded using a modified UTF-8 format from the data input stream.
     java.math.BigDecimal readZoned(int prec, int scale)
              Reads a Native format ZONED DECIMAL into a BigDecimal.
     void setSize(int len)
              Sets the size of the buffer.
     int skipBytes(int n)
              Skips exactly n bytes of input in the data input stream.
     void snap()
              Displays the contents of this buffer if tracing is enabled.
    protected  java.math.BigDecimal toBigDecimal(char[] c, int scale)
              Creates a BigDecimal object from a "numeric" character array.
     
    Methods inherited from class java.io.FilterInputStream
    available, close, mark, markSupported, read, read, read, reset, skip
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    dis

    protected java.io.DataInputStream dis
    Contains the default methods.


    fmt

    protected NativeFormat fmt
    Describes the native data formats.

    Method Detail

    setSize

    public void setSize(int len)
    Sets the size of the buffer. This method allows optimization of the buffer size. The previous contents of the buffer are released.


    getFormat

    public NativeFormat getFormat()
    Gets the data formats in effect for this stream.

    Returns:
    the format specifier.

    getBuffer

    public byte[] getBuffer()
    Gets a reference to the buffer. This method allows access to the buffer without copying large byte arrays any more than necessary. Note that subsequent reads from the underlying input stream can change the contents of the buffer.

    Returns:
    TraceBufferInputStream.buf.

    getCount

    public int getCount()
    Gets the number of valid bytes in the buffer.

    Returns:
    TraceBufferInputStream.count.

    getPosition

    public int getPosition()
    Gets the index of the next character to be read.

    Returns:
    TraceBufferInputStream.pos.

    snap

    public void snap()
    Displays the contents of this buffer if tracing is enabled.

    Enabled by TraceObject.trace and TraceObject.snapBytes.

    See Also:
    TraceObject

    readFully

    public void readFully(byte[] b)
                   throws java.io.IOException
    Reads b.length bytes from the data input stream.

    Specified by:
    readFully in interface java.io.DataInput
    Parameters:
    b - the buffer into which the data is read.
    Throws:
    java.io.IOException

    readFully

    public void readFully(byte[] b,
                          int off,
                          int len)
                   throws java.io.IOException
    Reads exactly len bytes from the data input stream.

    Specified by:
    readFully in interface java.io.DataInput
    Parameters:
    b - the buffer into which the data is read.
    off - the start offset of the data.
    len - the number of bytes to read.
    Throws:
    java.io.IOException

    skipBytes

    public int skipBytes(int n)
                  throws java.io.IOException
    Skips exactly n bytes of input in the data input stream.

    Specified by:
    skipBytes in interface java.io.DataInput
    Parameters:
    n - the number of bytes to be skipped.
    Returns:
    the number of bytes skipped, which is always n.
    Throws:
    java.io.IOException

    readBoolean

    public boolean readBoolean()
                        throws java.io.IOException
    Reads a boolean from the data input stream. Reads a single byte, 1 is true, 0 is false.

    Specified by:
    readBoolean in interface java.io.DataInput
    Returns:
    the boolean value read.
    Throws:
    java.io.EOFException - if this input stream has reached the end.
    java.io.IOException - if an I/O error occurs.

    readByte

    public byte readByte()
                  throws java.io.IOException
    Reads a signed 8-bit value from the data input stream.

    Specified by:
    readByte in interface java.io.DataInput
    Returns:
    the next byte of this input stream as a signed 8-bit byte
    Throws:
    java.io.IOException

    readUnsignedByte

    public int readUnsignedByte()
                         throws java.io.IOException
    Reads an unsigned 8-bit number from the underlying data input stream.

    Specified by:
    readUnsignedByte in interface java.io.DataInput
    Returns:
    the next byte of this input stream, interpreted as an unsigned 8-bit number.
    Throws:
    java.io.IOException

    readShort

    public short readShort()
                    throws java.io.IOException
    Reads a short from the data input stream.

    Specified by:
    readShort in interface java.io.DataInput
    Returns:
    the next two bytes of this input stream, interpreted as a signed 16-bit number.
    Throws:
    java.io.EOFException - if this input stream reaches the end before reading two bytes.
    java.io.IOException - if an I/O error occurs.

    readUnsignedShort

    public int readUnsignedShort()
                          throws java.io.IOException
    Reads an unsigned short from the data input stream.

    Specified by:
    readUnsignedShort in interface java.io.DataInput
    Returns:
    the next two bytes of this input stream, interpreted as an unsigned 16-bit number.
    Throws:
    java.io.EOFException - if this input stream reaches the end before reading two bytes.
    java.io.IOException - if an I/O error occurs.

    readChar

    public char readChar()
                  throws java.io.IOException
    Reads a Unicode character from the underlying input stream, by calling the DataInputStream readChar method.

    Specified by:
    readChar in interface java.io.DataInput
    Returns:
    the next two bytes of this input stream as a Unicode character.
    Throws:
    java.io.EOFException - if this input stream reaches the end before reading two bytes.
    java.io.IOException - if an I/O error occurs.

    readInt

    public int readInt()
                throws java.io.IOException
    Reads an int from the data input stream.

    Specified by:
    readInt in interface java.io.DataInput
    Returns:
    the next four bytes of this input stream, interpreted as an int.
    Throws:
    java.io.EOFException - if this input stream reaches the end before reading four bytes.
    java.io.IOException - if an I/O error occurs.

    readLong

    public long readLong()
                  throws java.io.IOException
    Reads a long from the data input stream.

    Specified by:
    readLong in interface java.io.DataInput
    Returns:
    the next eight bytes of this input stream, interpreted as a long
    Throws:
    java.io.EOFException - if this input stream reaches the end before java.io.reading eight bytes.
    java.io.IOException - if an I/O error occurs.

    readFloat

    public float readFloat()
                    throws java.io.IOException
    Reads a float from the data input stream.

    Specified by:
    readFloat in interface java.io.DataInput
    Returns:
    the next four bytes of this input stream, interpreted as a float.
    Throws:
    java.io.IOException
    See Also:
    readInt()

    readDouble

    public double readDouble()
                      throws java.io.IOException
    Reads a double from the data input stream.

    Specified by:
    readDouble in interface java.io.DataInput
    Returns:
    the next eight bytes of this input stream, interpreted as a double.
    Throws:
    java.io.IOException
    See Also:
    readLong()

    readLine

    public java.lang.String readLine()
                              throws java.io.IOException
    Deprecated. But specified by the DataInput interface.

    Reads the next line of text from the underlying data input stream using its readLine() method.

    Specified by:
    readLine in interface java.io.DataInput
    Returns:
    next line of text (in theory)
    Throws:
    java.io.IOException - always, don't call it

    readUTF

    public java.lang.String readUTF()
                             throws java.io.IOException
    Reads a string that has been encoded using a modified UTF-8 format from the data input stream.

    Specified by:
    readUTF in interface java.io.DataInput
    Returns:
    a Unicode string.
    Throws:
    java.io.IOException

    readBytes

    public java.lang.String readBytes(int len)
                               throws java.io.UnsupportedEncodingException,
                                      java.io.IOException
    Reads a string from a stream as an array of bytes. An array of bytes is read from the input stream and converted to a String according to the encoding.

    Parameters:
    len - number of bytes to read from stream
    Returns:
    a String
    Throws:
    java.io.UnsupportedEncodingException - if the character set encoding is not supported
    java.io.IOException - if an IO error occurs
    See Also:
    NativeDataOutputStream.writeBytes(String, int)

    readBytesKatakana

    public java.lang.String readBytesKatakana(int len)
                                       throws java.io.UnsupportedEncodingException,
                                              java.io.IOException
    Reads a single byte Katakana string from a stream as an array of bytes. All lower case Latin characters in the array of bytes are first converted to upper case, then read from the input stream and converted to a String according to the encoding (which normally is Cp930).

    Parameters:
    len - number of bytes to read from stream
    Returns:
    a String
    Throws:
    java.io.UnsupportedEncodingException - if the character set encoding is not supported
    java.io.IOException - if an IO error occurs

    readBytesInternal

    public java.lang.String readBytesInternal(int len)
                                       throws java.io.UnsupportedEncodingException,
                                              java.io.IOException
    Reads an internal control block string from a stream as an array of bytes. An array of bytes is read from the input stream and converted to a String according to the internal control block encoding. When the "network" encoding is being used (UTF8 or Unicode) the string is converted "normally", that is, by the derived class method.

    Parameters:
    len - number of bytes to read from stream
    Returns:
    a String
    Throws:
    java.io.UnsupportedEncodingException - if the character set encoding is not supported
    java.io.IOException - if an IO error occurs
    See Also:
    NativeDataOutputStream.writeBytesInternal(String, int)

    readPacked

    public java.math.BigDecimal readPacked(int prec,
                                           int scale)
                                    throws java.io.IOException
    Reads a native format PACKED DECIMAL into a BigDecimal. This reads an array of bytes representing a DECIMAL value and converts it to a BigDecimal object.

    Parameters:
    prec - total number of digits
    scale - number of digits after the decimal
    Returns:
    a BigDecimal containing the DECIMAL value.
    Throws:
    java.io.IOException - if any error
    See Also:
    toBigDecimal(char[], int)

    readZoned

    public java.math.BigDecimal readZoned(int prec,
                                          int scale)
                                   throws java.io.IOException
    Reads a Native format ZONED DECIMAL into a BigDecimal. This reads a String representing a NUMERIC value and converts it to a BigDecimal object.

    Parameters:
    prec - total number of digits
    scale - number of digits after the decimal
    Returns:
    a BigDecimal containing the NUMERIC value.
    Throws:
    java.io.IOException - if any error
    See Also:
    toBigDecimal(char[], int)

    toBigDecimal

    protected java.math.BigDecimal toBigDecimal(char[] c,
                                                int scale)
                                         throws DecimalFormatException
    Creates a BigDecimal object from a "numeric" character array. This converts the internal representation of a numeric value used to read native packed and zone decimal data to a BigDecimal object. This representation consists of a character array with leading 0's to fill out the precision, the decimal point removed, and an explicit trailing sign (+/-).

    Parameters:
    c - an array of "numeric" characters.
    scale - number of digits after the decimal.
    Returns:
    BigDecimal object.
    Throws:
    DecimalFormatException - if invalid
    See Also:
    readPacked(int, int), readZoned(int, int)

    readGraphic

    public java.lang.String readGraphic(int len)
                                 throws java.io.IOException
    Reads OS/390 DBCS data into String. This method reads OS/390 EBCDIC double byte characters from the input stream into a buffer prefixed with a "shift-out" character suffixed with a "shift-in" character, then converts the buffer to a String using the encoding in effect for this stream (which should be EBCDIC_DBCS).

    Parameters:
    len - the number of DBCS characters to read
    Returns:
    the converted string
    Throws:
    java.io.IOException - if an IO error occurs
    See Also:
    readBytes(int), UtfDataInputStream.readBytes(int), UnicodeDataInputStream.readBytes(int), NativeFormat.getString(byte[])


    Copyright © 2009 CA, All rights reserved