Class XdrInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.firebirdsql.gds.impl.wire.XdrInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public final class XdrInputStream extends FilterInputStream
An input stream for reading in data that is in the XDR format. An XdrInputStream instance is wrapped around an underlying java.io.InputStream.

This class is not thread-safe.

Author:
Alejandro Alberola, David Jencks, Mark Rotteveel
  • Constructor Details

    • XdrInputStream

      public XdrInputStream(InputStream in)
      Create a new instance of XdrInputStream.
      Parameters:
      in - underlying InputStream to read from
    • XdrInputStream

      public XdrInputStream(InputStream in, int size)
      Create a new instance of XdrInputStream.
      Parameters:
      in - underlying InputStream to read from
      size - buffer size
  • Method Details

    • skipPadding

      public void skipPadding(int len) throws IOException
      Skips the padding after a buffer of the specified length. The number of bytes to skip is calculated as (4 - len) & 3.
      Parameters:
      len - length of the previously read buffer
      Throws:
      IOException - if an error occurs while reading from the underlying input stream
      See Also:
    • readBuffer

      public byte[] readBuffer() throws IOException
      Reads an int length from the stream, reads and returns the buffer of that length and skips the padding.
      Returns:
      buffer that was read
      Throws:
      IOException - if an error occurs while reading from the underlying input stream
    • readBuffer

      public byte[] readBuffer(int len) throws IOException
      Reads and returns the buffer of len and skips the padding.
      Parameters:
      len - length of the buffer
      Returns:
      buffer that was read
      Throws:
      IOException - if an error occurs while reading from the underlying input stream
    • skipBuffer

      public void skipBuffer() throws IOException
      Skips a buffer, by reading an int length from the stream, and then skipping that length plus the padding.
      Throws:
      IOException - if an error occurs while reading from the underlying input stream
    • readRawBuffer

      public byte[] readRawBuffer(int len) throws IOException
      Read in a raw array of bytes.
      Parameters:
      len - number of bytes to read
      Returns:
      byte buffer that was read
      Throws:
      IOException - if an error occurs while reading from the underlying input stream
    • readString

      public String readString(Encoding encoding) throws IOException
      Read in a String.
      Parameters:
      encoding - encoding to use for reading the string
      Returns:
      String that was read
      Throws:
      IOException - if an error occurs while reading from the underlying input stream
    • readLong

      public long readLong() throws IOException
      Read in a long.
      Returns:
      long that was read
      Throws:
      IOException - if an error occurs while reading from the underlying input stream
    • readInt

      public int readInt() throws IOException
      Read in an int.
      Returns:
      int that was read
      Throws:
      IOException - if an error occurs while reading from the underlying input stream
    • readFully

      public void readFully(byte[] b, int off, int len) throws IOException
      Read a given amount of data from the underlying input stream. The data that is read is stored in b, starting from offset off.
      Parameters:
      b - byte buffer to hold the data that is read
      off - offset at which to start storing data in b
      len - number of bytes to be read
      Throws:
      IOException - if an error occurs while reading from the underlying input stream
    • enableDecompression

      @InternalApi public void enableDecompression() throws IOException
      Wraps the underlying stream for zlib decompression.
      Throws:
      IOException - if the underlying stream is already set up for decompression
    • setCipher

      public void setCipher(Cipher cipher) throws IOException
      Throws:
      IOException