Package org.firebirdsql.gds.impl.wire
Class XdrOutputStream
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.
- Version:
- 1.0
- Author:
- Alejandro Alberola, David Jencks, Mark Rotteveel
-
Field Summary
FieldsFields inherited from class java.io.BufferedOutputStream
buf, countFields inherited from class java.io.FilterOutputStream
out -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new instance ofXdrOutputStreamwith default buffer size.XdrOutputStream(OutputStream out, int bufferSize) Create a new instance ofXdrOutputStreamwith the specified buffer size. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close this stream and the underlying output stream.voidWraps the underlying stream for zlib compression.voidvoidwrite(byte[] b, int off, int len) Writeslenbytes from the specified byte array starting at offsetoffto this output stream as defined byOutputStream.write(byte[], int, int).voidwrite(byte[] b, int offset, int len, int pad) Write abytebuffer to the underlying output stream in XDR format.voidwriteAlignment(int length) Writes the0x00alignment for the specified length.voidwriteBuffer(byte[] buffer) Write abytebuffer to the underlying output stream in XDR format.voidwriteDirect(byte[] data) Writes directly to theOutputStreamof the underlying socket.voidwriteInt(int v) Write anintvalue to the underlying stream in XDR format.voidwriteLong(long v) Write alongvalue to the underlying stream in XDR format.voidwritePadding(int length, int padByte) Writes padding for the specified length of the specified padding byte.voidwriteSpacePadding(int length) Writes space (0x20) padding of the specified lengthvoidwriteString(String s, Encoding encoding) Write content of the specified string using the specified encoding.voidwriteTyped(int type, Xdrable item) Write anXdrableto this output stream.voidwriteTyped(ParameterBuffer parameterBuffer) voidwriteZeroPadding(int length) Writes zero padding of the specified lengthMethods inherited from class java.io.BufferedOutputStream
flush, writeMethods inherited from class java.io.FilterOutputStream
writeMethods 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 ofXdrOutputStreamwith default buffer size.- Parameters:
out- The underlyingOutputStreamto write to
-
XdrOutputStream
Create a new instance ofXdrOutputStreamwith the specified buffer size.- Parameters:
out- The underlyingOutputStreamto write tobufferSize- The size of the buffer
-
-
Method Details
-
writeAlignment
Writes the0x00alignment for the specified length. This padding is calculated as(4 - length) & 3.- Parameters:
length- The 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:
length- 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:
length- 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:
length- 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 abytebuffer to the underlying output stream in XDR format.- Parameters:
buffer- Thebytebuffer to be written- Throws:
IOException- if an error occurs while writing to the underlying output stream
-
writeString
Write content of the specified string using the specified encoding.- Throws:
IOException
-
writeTyped
Write anXdrableto this output stream.- Parameters:
type- Type of theXdrableto be written, e.g.ISCConstants.isc_tpb_version3item- The object to be written- Throws:
IOException- if an error occurs while writing to the underlying output stream
-
writeTyped
- Throws:
IOException
-
writeLong
Write alongvalue to the underlying stream in XDR format.- Parameters:
v- Thelongvalue to be written- Throws:
IOException- if an error occurs while writing to the underlying output stream
-
writeInt
Write anintvalue to the underlying stream in XDR format.- Parameters:
v- Theintvalue to be written- Throws:
IOException- if an error occurs while writing to the underlying output stream
-
write
Write abytebuffer to the underlying output stream in XDR format.- Parameters:
b- Thebytebuffer to be writtenoffset- The start offset in the bufferlen- The number of bytes to writepad- The number of (blank) padding bytes to write- Throws:
IOException- if an error occurs while writing to the underlying output stream
-
write
Writeslenbytes from the specified byte array starting at offsetoffto 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:
writein classBufferedOutputStream- Parameters:
b- The dataoff- The start offset in the datalen- The 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein 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 theOutputStreamof the underlying socket.- Parameters:
data- Data to write- Throws:
IOException- For errors writing to the socket.
-