org.firebirdsql.gds.impl.wire

## Class XdrOutputStream

- java.lang.Object
- - java.io.OutputStream
  - - 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.OutputStream

  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

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `NULL_BYTE`
    `static int` | `SPACE_BYTE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `XdrOutputStream(java.io.OutputStream out)` Create a new instance of `XdrOutputStream` with buffering.
    `XdrOutputStream(java.io.OutputStream out, boolean buffered)` Create a new instance of `XdrOutputStream` with either a buffered or an unbuffered stream.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Close this stream and the underlying output stream.
    `void` | `flush()` Flush all buffered data to the underlying output stream.
    `void` | `setCipher(javax.crypto.Cipher cipher)`
    `void` | `write(byte[] b, int off, int len)` Writes `len` bytes from the specified byte array starting at offset `off` to this output stream as defined by `OutputStream.write(byte[], int, int)`.
    `void` | `write(byte[] b, int offset, int len, int pad)` Write a `byte` buffer to the underlying output stream in XDR format.
    `void` | `write(int b)` Write a single `byte` to the underlying output stream in XDR format.
    `void` | `writeAlignment(int length)` Writes the `0x00` alignment for the specified length.
    `void` | `writeBuffer(byte[] buffer)` Write a `byte` buffer to the underlying output stream in XDR format.
    `void` | `writeDirect(byte[] data)` Writes directly to the `OutputStream` of the underlying socket.
    `void` | `writeInt(int v)` Write an `int` value to the underlying stream in XDR format.
    `void` | `writeLong(long v)` Write a `long` value to the underlying stream in XDR format.
    `void` | `writePadding(int length, int padByte)` Writes padding for the specified length of the specified padding byte.
    `void` | `writeSpacePadding(int length)` Writes space (`0x20`) padding of the specified length
    `void` | `writeString(java.lang.String s, Encoding encoding)` Write content of the specified string using the specified encoding.
    `void` | `writeTyped(int type, Xdrable item)` Write an `Xdrable` to this output stream.
    `void` | `writeTyped(ParameterBuffer parameterBuffer)`
    `void` | `writeZeroPadding(int length)` Writes zero padding of the specified length

    - ### Methods inherited from class java.io.OutputStream

      `write`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### SPACE_BYTE

          public static final int SPACE_BYTE

      See Also:
        Constant Field Values

    - #### NULL_BYTE

          public static final int NULL_BYTE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### XdrOutputStream

          public XdrOutputStream(java.io.OutputStream out)

      Create a new instance of `XdrOutputStream` with buffering.
      Parameters:
        `out` - The underlying `OutputStream` to write to

    - #### XdrOutputStream

          public XdrOutputStream(java.io.OutputStream out,
                                 boolean buffered)

      Create a new instance of `XdrOutputStream` with either a buffered or an unbuffered stream.
      Parameters:
        `out` - The underlying `OutputStream` to write to
        `buffered` - `true` Uses buffering (like `XdrOutputStream(java.io.OutputStream)` or `false` writes directly to provided `OutputStream`.

  - ### Method Detail

    - #### writeAlignment

          public void writeAlignment(int length)
                              throws java.io.IOException

      Writes the `0x00` alignment 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

    - #### writeZeroPadding

          public void writeZeroPadding(int length)
                                throws java.io.IOException

      Writes 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)`

    - #### writeSpacePadding

          public void writeSpacePadding(int length)
                                 throws java.io.IOException

      Writes 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)`

    - #### writePadding

          public void writePadding(int length,
                                   int padByte)
                            throws java.io.IOException

      Writes padding for the specified length of the specified padding byte.

      Prefer using the more specific `writeZeroPadding(int)` and `writeZeroPadding(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)`

    - #### writeBuffer

          public void writeBuffer(byte[] buffer)
                           throws java.io.IOException

      Write a `byte` buffer to the underlying output stream in XDR format.
      Parameters:
        `buffer` - The `byte` buffer to be written
      Throws:
        `java.io.IOException` - if an error occurs while writing to the underlying output stream

    - #### writeString

          public void writeString(java.lang.String s,
                                  Encoding encoding)
                           throws java.io.IOException

      Write content of the specified string using the specified encoding.
      Throws:
        `java.io.IOException`

    - #### writeTyped

          public void writeTyped(int type,
                                 Xdrable item)
                          throws java.io.IOException

      Write an `Xdrable` to this output stream.
      Parameters:
        `type` - Type of the `Xdrable` to 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

    - #### writeTyped

          public void writeTyped(ParameterBuffer parameterBuffer)
                          throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### writeLong

          public void writeLong(long v)
                         throws java.io.IOException

      Write a `long` value to the underlying stream in XDR format.
      Parameters:
        `v` - The `long` value to be written
      Throws:
        `java.io.IOException` - if an error occurs while writing to the underlying output stream

    - #### writeInt

          public void writeInt(int v)
                        throws java.io.IOException

      Write an `int` value to the underlying stream in XDR format.
      Parameters:
        `v` - The `int` value to be written
      Throws:
        `java.io.IOException` - if an error occurs while writing to the underlying output stream

    - #### write

          public void write(byte[] b,
                            int offset,
                            int len,
                            int pad)
                     throws java.io.IOException

      Write a `byte` buffer to the underlying output stream in XDR format.
      Parameters:
        `b` - The `byte` buffer 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

    - #### write

          public void write(int b)
                     throws java.io.IOException

      Write a single `byte` to the underlying output stream in XDR format.
      Specified by:
        `write` in class `java.io.OutputStream`
      Parameters:
        `b` - The value to be written, will be truncated to a byte
      Throws:
        `java.io.IOException` - if an error occurs while writing to the underlying output stream

    - #### write

          public void write(byte[] b,
                            int off,
                            int len)
                     throws java.io.IOException

      Writes `len` bytes from the specified byte array starting at offset `off` to this output stream as defined by `OutputStream.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 class `java.io.OutputStream`
      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

    - #### flush

          public void flush()
                     throws java.io.IOException

      Flush all buffered data to the underlying output stream.
      Specified by:
        `flush` in interface `java.io.Flushable`
      Overrides:
        `flush` in class `java.io.OutputStream`
      Throws:
        `java.io.IOException` - if an error occurs while writing to the underlying output stream

    - #### close

          public void close()
                     throws java.io.IOException

      Close this stream and the underlying output stream.
      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Overrides:
        `close` in class `java.io.OutputStream`
      Throws:
        `java.io.IOException` - if an error occurs while closing the underlying stream

    - #### setCipher

          public void setCipher(javax.crypto.Cipher cipher)
                         throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### writeDirect

          public final void writeDirect(byte[] data)
                                 throws java.io.IOException

      Writes directly to the `OutputStream` of the underlying socket.
      Parameters:
        `data` - Data to write
      Throws:
        `java.io.IOException` - For errors writing to the socket.

Copyright © 2001-2021 Jaybird (Firebird JDBC/JCA) team. All rights reserved.