Module org.firebirdsql.jaybird
Package org.firebirdsql.gds.impl.wire

# 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

## Field Summary

### Fields inherited from class java.io.FilterInputStream

`in`

## Constructor Summary

Constructors
Constructor
Description
`XdrInputStream(InputStream in)`
Create a new instance of `XdrInputStream`.
`XdrInputStream(InputStream in, int size)`
Create a new instance of `XdrInputStream`.

## Method Summary

Modifier and Type
Method
Description
`void`
`enableDecompression()`
Wraps the underlying stream for zlib decompression.
`byte[]`
`readBuffer()`
Reads an `int` length from the stream, reads and returns the buffer of that length and skips the padding.
`byte[]`
`readBuffer(int len)`
Reads and returns the buffer of `len` and skips the padding.
`void`
`readFully(byte[] b, int off, int len)`
Read a given amount of data from the underlying input stream.
`int`
`readInt()`
Read in an `int`.
`long`
`readLong()`
Read in a `long`.
`byte[]`
`readRawBuffer(int len)`
Read in a raw array of bytes.
`String`
`readString(Encoding encoding)`
Read in a `String`.
`void`
`setCipher(Cipher cipher)`
`void`
`skipBuffer()`
Skips a buffer, by reading an `int` length from the stream, and then skipping that length plus the padding.
`void`
`skipPadding(int len)`
Skips the padding after a buffer of the specified length.

### Methods inherited from class java.io.FilterInputStream

`available, close, mark, markSupported, read, read, read, reset, skip`

### Methods inherited from class java.io.InputStream

`nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## 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:
  - `XdrOutputStream.writePadding(int, int)`

### 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`