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:
- java.io.Closeable,- java.io.Flushable,- java.lang.AutoCloseable
 
 public final class XdrOutputStream extends java.io.BufferedOutputStreamAnXdrOutputStreamwrites data in XDR format to an underlyingjava.io.OutputStream.This class is not thread-safe. - Author:
- Alejandro Alberola, David Jencks, Mark Rotteveel
 
- 
- 
Field SummaryFields Modifier and Type Field Description static intNULL_BYTEstatic intSPACE_BYTE
 - 
Constructor SummaryConstructors Constructor Description XdrOutputStream(java.io.OutputStream out)Create a new instance ofXdrOutputStreamwith default buffer size.XdrOutputStream(java.io.OutputStream out, int bufferSize)Create a new instance ofXdrOutputStreamwith the specified buffer size.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close this stream and the underlying output stream.voidenableCompression()Wraps the underlying stream for zlib compression.voidsetCipher(javax.crypto.Cipher cipher)voidwrite(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[] 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 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(java.lang.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 length
 
- 
- 
- 
Field Detail- 
SPACE_BYTEpublic static final int SPACE_BYTE - See Also:
- Constant Field Values
 
 - 
NULL_BYTEpublic static final int NULL_BYTE - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
XdrOutputStreampublic XdrOutputStream(java.io.OutputStream out) Create a new instance ofXdrOutputStreamwith default buffer size.- Parameters:
- out- The underlying- OutputStreamto write to
 
 - 
XdrOutputStreampublic XdrOutputStream(java.io.OutputStream out, int bufferSize)Create a new instance ofXdrOutputStreamwith the specified buffer size.- Parameters:
- out- The underlying- OutputStreamto write to
- bufferSize- The size of the buffer
 
 
- 
 - 
Method Detail- 
writeAlignmentpublic void writeAlignment(int length) throws java.io.IOExceptionWrites 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:
- java.io.IOException- if an error occurs while writing to the underlying output stream
 
 - 
writeZeroPaddingpublic void writeZeroPadding(int length) throws java.io.IOExceptionWrites zero padding of the specified length- Parameters:
- length- Length to write
- Throws:
- java.io.IOException- if an error occurs while writing to the underlying output stream
- See Also:
- writePadding(int, int)
 
 - 
writeSpacePaddingpublic void writeSpacePadding(int length) throws java.io.IOExceptionWrites space (0x20) padding of the specified length- Parameters:
- length- Length to write
- Throws:
- java.io.IOException- if an error occurs while writing to the underlying output stream
- See Also:
- writePadding(int, int)
 
 - 
writePaddingpublic void writePadding(int length, int padByte) throws java.io.IOExceptionWrites 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 write
- padByte- Padding byte to use
- Throws:
- java.io.IOException- if an error occurs while writing to the underlying output stream
- See Also:
- writeSpacePadding(int),- writeZeroPadding(int)
 
 - 
writeBufferpublic void writeBuffer(byte[] buf) throws java.io.IOExceptionWrite byte bufferbufto the underlying output stream in XDR format.- Parameters:
- buf- byte buffer to be written
- Throws:
- java.io.IOException- if an error occurs while writing to the underlying output stream
 
 - 
writeBufferpublic void writeBuffer(byte[] buf, int off, int len) throws java.io.IOExceptionWrite byte bufferbuffrom offsetoffforlenbytes to the underlying output stream in XDR format.- Parameters:
- buf- byte buffer to be written
- off- offset to start
- len- length to write
- Throws:
- java.io.IOException- if an error occurs while writing to the underlying output stream
- java.lang.IndexOutOfBoundsException- If- offis negative,- lenis negative, or- lenis greater than- buff.length - off
 
 - 
writeStringpublic void writeString(java.lang.String s, Encoding encoding) throws java.io.IOExceptionWrite content of the specified string using the specified encoding.- Throws:
- java.io.IOException
 
 - 
writeTypedpublic void writeTyped(int type, Xdrable item) throws java.io.IOExceptionWrite anXdrableto this output stream.- Parameters:
- type- Type of the- Xdrableto be written, e.g.- ISCConstants.isc_tpb_version3
- item- The object to be written
- Throws:
- java.io.IOException- if an error occurs while writing to the underlying output stream
 
 - 
writeTypedpublic void writeTyped(ParameterBuffer parameterBuffer) throws java.io.IOException - Throws:
- java.io.IOException
 
 - 
writeLongpublic void writeLong(long v) throws java.io.IOExceptionWrite alongvalue to the underlying stream in XDR format.- Parameters:
- v- The- longvalue to be written
- Throws:
- java.io.IOException- if an error occurs while writing to the underlying output stream
 
 - 
writeIntpublic void writeInt(int v) throws java.io.IOExceptionWrite anintvalue to the underlying stream in XDR format.- Parameters:
- v- The- intvalue to be written
- Throws:
- java.io.IOException- if an error occurs while writing to the underlying output stream
 
 - 
writepublic void write(byte[] b, int offset, int len, int pad) throws java.io.IOExceptionWrite abytebuffer to the underlying output stream in XDR format.- Parameters:
- b- The- bytebuffer to be written
- offset- The start offset in the buffer
- len- The number of bytes to write
- pad- The number of (blank) padding bytes to write
- Throws:
- java.io.IOException- if an error occurs while writing to the underlying output stream
 
 - 
writepublic void write(byte[] b, int off, int len) throws java.io.IOExceptionWriteslenbytes 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 class- java.io.BufferedOutputStream
- Parameters:
- b- The data
- off- The start offset in the data
- len- The number of bytes to write
- Throws:
- java.io.IOException- if an error occurs while writing to the underlying output stream
 
 - 
closepublic void close() throws java.io.IOExceptionClose this stream and the underlying output stream.- Specified by:
- closein interface- java.lang.AutoCloseable
- Specified by:
- closein interface- java.io.Closeable
- Overrides:
- closein class- java.io.FilterOutputStream
- Throws:
- java.io.IOException- if an error occurs while closing the underlying stream
 
 - 
enableCompression@InternalApi public void enableCompression() throws java.io.IOException Wraps the underlying stream for zlib compression.- Throws:
- java.io.IOException- If the underlying stream is already set up for compression
 
 - 
setCipherpublic void setCipher(javax.crypto.Cipher cipher) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
writeDirectpublic void writeDirect(byte[] data) throws java.io.IOExceptionWrites directly to theOutputStreamof the underlying socket.- Parameters:
- data- Data to write
- Throws:
- java.io.IOException- For errors writing to the socket.
 
 
- 
 
-