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, countFields inherited from class java.io.FilterOutputStream
out -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new instance ofXdrOutputStreamwith default buffer size.XdrOutputStream(OutputStream out, int size) 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 off, int len, int pad) Write byte bufferbto the underlying output stream in XDR format.voidwriteAlignment(int len) Writes the0x00alignment for the specified length.voidwriteBuffer(byte[] buf) Write byte bufferbufto the underlying output stream in XDR format.voidwriteBuffer(byte[] buf, int off, int len) Write byte bufferbuffrom offsetoffforlenbytes 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 len, int padByte) Writes padding for the specified length of the specified padding byte.voidwriteSpacePadding(int len) 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 len) 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- underlyingOutputStreamto write to
-
XdrOutputStream
Create a new instance ofXdrOutputStreamwith the specified buffer size.- Parameters:
out- underlyingOutputStreamto write tosize- size of the buffer (implementation uses a minimum of 8 bytes)
-
-
Method Details
-
writeAlignment
Writes the0x00alignment 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 bufferbufto 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 bufferbuffrom offsetoffforlenbytes 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- Ifoffis negative,lenis negative, orlenis greater thanbuff.length - off
-
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- 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-longvalue 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-intvalue to be written- Throws:
IOException- if an error occurs while writing to the underlying output stream
-
write
Write byte bufferbto 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
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- 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:
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
-