java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.firebirdsql.gds.impl.wire.XdrInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
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
ConstructorsConstructorDescriptionCreate a new instance ofXdrInputStream
.XdrInputStream
(InputStream in, int size) Create a new instance ofXdrInputStream
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Wraps the underlying stream for zlib decompression.byte[]
Reads anint
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 oflen
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 anint
.long
readLong()
Read in along
.byte[]
readRawBuffer
(int len) Read in a raw array of bytes.readString
(Encoding encoding) Read in aString
.void
void
Skips a buffer, by reading anint
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
-
Constructor Details
-
XdrInputStream
Create a new instance ofXdrInputStream
.- Parameters:
in
- underlyingInputStream
to read from
-
XdrInputStream
Create a new instance ofXdrInputStream
.- Parameters:
in
- underlyingInputStream
to read fromsize
- buffer size
-
-
Method Details
-
skipPadding
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
Reads anint
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
Reads and returns the buffer oflen
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
Skips a buffer, by reading anint
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
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
Read in aString
.- 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
Read in along
.- Returns:
long
that was read- Throws:
IOException
- if an error occurs while reading from the underlying input stream
-
readInt
Read in anint
.- Returns:
int
that was read- Throws:
IOException
- if an error occurs while reading from the underlying input stream
-
readFully
Read a given amount of data from the underlying input stream. The data that is read is stored inb
, starting from offsetoff
.- Parameters:
b
- byte buffer to hold the data that is readoff
- offset at which to start storing data inb
len
- number of bytes to be read- Throws:
IOException
- if an error occurs while reading from the underlying input stream
-
enableDecompression
Wraps the underlying stream for zlib decompression.- Throws:
IOException
- if the underlying stream is already set up for decompression
-
setCipher
- Throws:
IOException
-