java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.io.BufferedOutputStream
org.firebirdsql.gds.impl.wire.XdrOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
An
XdrOutputStream
writes data in XDR format to an underlying java.io.OutputStream
.
This class is not thread-safe.
- Author:
- Alejandro Alberola, David Jencks, Mark Rotteveel
-
Field Summary
FieldsFields inherited from class java.io.BufferedOutputStream
buf, count
Fields inherited from class java.io.FilterOutputStream
out
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new instance ofXdrOutputStream
with default buffer size.XdrOutputStream
(OutputStream out, int size) Create a new instance ofXdrOutputStream
with the specified buffer size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close this stream and the underlying output stream.void
Wraps the underlying stream for zlib compression.void
void
write
(byte[] b, int off, int len) Writeslen
bytes from the specified byte array starting at offsetoff
to this output stream as defined byOutputStream.write(byte[], int, int)
.void
write
(byte[] b, int off, int len, int pad) Write byte bufferb
to the underlying output stream in XDR format.void
writeAlignment
(int len) Writes the0x00
alignment for the specified length.void
writeBuffer
(byte[] buf) Write byte bufferbuf
to the underlying output stream in XDR format.void
writeBuffer
(byte[] buf, int off, int len) Write byte bufferbuf
from offsetoff
forlen
bytes to the underlying output stream in XDR format.void
writeDirect
(byte[] data) Writes directly to theOutputStream
of the underlying socket.void
writeInt
(int v) Write anint
value to the underlying stream in XDR format.void
writeLong
(long v) Write along
value to the underlying stream in XDR format.void
writePadding
(int len, int padByte) Writes padding for the specified length of the specified padding byte.void
writeSpacePadding
(int len) Writes space (0x20
) padding of the specified lengthvoid
writeString
(String s, Encoding encoding) Write content of the specified string using the specified encoding.void
writeTyped
(int type, Xdrable item) Write anXdrable
to this output stream.void
writeTyped
(ParameterBuffer parameterBuffer) void
writeZeroPadding
(int len) Writes zero padding of the specified lengthMethods inherited from class java.io.BufferedOutputStream
flush, write
Methods inherited from class java.io.FilterOutputStream
write
Methods inherited from class java.io.OutputStream
nullOutputStream
-
Field Details
-
SPACE_BYTE
public static final int SPACE_BYTE- See Also:
-
NULL_BYTE
public static final int NULL_BYTE- See Also:
-
-
Constructor Details
-
XdrOutputStream
Create a new instance ofXdrOutputStream
with default buffer size.- Parameters:
out
- underlyingOutputStream
to write to
-
XdrOutputStream
Create a new instance ofXdrOutputStream
with the specified buffer size.- Parameters:
out
- underlyingOutputStream
to write tosize
- size of the buffer (implementation uses a minimum of 8 bytes)
-
-
Method Details
-
writeAlignment
Writes the0x00
alignment for the specified length. This padding is calculated as(4 - len) & 3
.- Parameters:
len
- length of the previously written buffer to pad- Throws:
IOException
- if an error occurs while writing to the underlying output stream
-
writeZeroPadding
Writes zero padding of the specified length- Parameters:
len
- length to write- Throws:
IOException
- if an error occurs while writing to the underlying output stream- See Also:
-
writeSpacePadding
Writes space (0x20
) padding of the specified length- Parameters:
len
- length to write- Throws:
IOException
- if an error occurs while writing to the underlying output stream- See Also:
-
writePadding
Writes padding for the specified length of the specified padding byte.Prefer using the more specific
writeZeroPadding(int)
andwriteZeroPadding(int)
.- Parameters:
len
- length of padding to writepadByte
- padding byte to use- Throws:
IOException
- if an error occurs while writing to the underlying output stream- See Also:
-
writeBuffer
Write byte bufferbuf
to the underlying output stream in XDR format.- Parameters:
buf
- byte buffer to be written- Throws:
IOException
- if an error occurs while writing to the underlying output stream
-
writeBuffer
Write byte bufferbuf
from offsetoff
forlen
bytes to the underlying output stream in XDR format.- Parameters:
buf
- byte buffer to be writtenoff
- offset to startlen
- length to write- Throws:
IOException
- if an error occurs while writing to the underlying output streamIndexOutOfBoundsException
- Ifoff
is negative,len
is negative, orlen
is greater thanbuff.length - off
-
writeString
Write content of the specified string using the specified encoding.- Throws:
IOException
-
writeTyped
Write anXdrable
to this output stream.- Parameters:
type
- type of theXdrable
to be written, e.g.ISCConstants.isc_tpb_version3
item
- object to be written- Throws:
IOException
- if an error occurs while writing to the underlying output stream
-
writeTyped
- Throws:
IOException
-
writeLong
Write along
value to the underlying stream in XDR format.- Parameters:
v
-long
value to be written- Throws:
IOException
- if an error occurs while writing to the underlying output stream
-
writeInt
Write anint
value to the underlying stream in XDR format.- Parameters:
v
-int
value to be written- Throws:
IOException
- if an error occurs while writing to the underlying output stream
-
write
Write byte bufferb
to the underlying output stream in XDR format.- Parameters:
b
- byte buffer to be writtenoff
- start offset in the bufferlen
- number of bytes to writepad
- number of (blank) padding bytes to write- Throws:
IOException
- if an error occurs while writing to the underlying output stream
-
write
Writeslen
bytes from the specified byte array starting at offsetoff
to this output stream as defined byOutputStream.write(byte[], int, int)
.Important: do not confuse this method with
write(byte[], int, int, int)
which originally had the signature of this method.- Overrides:
write
in classBufferedOutputStream
- Parameters:
b
- dataoff
- start offset in the datalen
- number of bytes to write- Throws:
IOException
- if an error occurs while writing to the underlying output stream
-
close
Close this stream and the underlying output stream.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterOutputStream
- Throws:
IOException
- if an error occurs while closing the underlying stream
-
enableCompression
Wraps the underlying stream for zlib compression.- Throws:
IOException
- If the underlying stream is already set up for compression
-
setCipher
- Throws:
IOException
-
writeDirect
Writes directly to theOutputStream
of the underlying socket.- Parameters:
data
- data to write- Throws:
IOException
- for errors writing to the socket
-