org.infinispan.schematic.internal.io

## Class BsonDataOutput

- java.lang.Object
- - org.infinispan.schematic.internal.io.BsonDataOutput

- All Implemented Interfaces:
    DataOutput

      public class BsonDataOutput
      extends Object
      implements DataOutput

  An implementation of `DataOutput` with additional methods needed for writing BSON formatted content. Specifically, this class reads little-endian byte order (purposefully in violation of the DataInput interface specification) and provides a way to read C-style strings (where the length is not known up front but instead contain all characters until the zero-byte terminator), which are commonly used within the BSON specification.
  Since:
    5.1

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BsonDataOutput()`
    `BsonDataOutput(int initialSize)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected ByteBuffer` | `getBufferFor(int position)`
    `protected ByteBuffer` | `newByteBuffer(int bufferSize)`
    `int` | `size()`
    `protected void` | `updateSize(int newSize)`
    `void` | `write(byte[] b)`
    `void` | `write(byte[] b, int off, int len)`
    `void` | `write(int b)`
    `void` | `write(int position, byte[] value, int offset, int length)`
    `void` | `writeBoolean(boolean value)`
    `void` | `writeBoolean(int position, boolean value)`
    `void` | `writeByte(int value)`
    `void` | `writeByte(int position, int value)`
    `void` | `writeBytes(String str)` Deprecated. The semantics of `writeBytes(String s)` are considered dangerous. Please use `writeUTF(String s)`, `writeChars(String s)` or another write method instead.
    `void` | `writeChar(int value)`
    `void` | `writeChar(int position, int value)`
    `void` | `writeChars(String str)` Writes every character in the string `s`, to the output stream, in order, two bytes per character.
    `void` | `writeDouble(double value)`
    `void` | `writeDouble(int position, double value)`
    `void` | `writeFloat(float value)`
    `void` | `writeFloat(int position, float value)`
    `void` | `writeInt(int value)`
    `void` | `writeInt(int position, int value)`
    `void` | `writeLong(int position, long value)`
    `void` | `writeLong(long value)`
    `void` | `writeShort(int value)`
    `void` | `writeShort(int position, int value)`
    `void` | `writeTo(OutputStream stream)` Write all content to the supplied stream.
    `void` | `writeTo(WritableByteChannel channel)` Write all content to the supplied channel.
    `int` | `writeUTF(int position, String str)`
    `void` | `writeUTF(String str)`
    `int` | `writeUTFString(String str)` Writes the modified UTF-8 representation of every character in the string `s`.

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

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

- - ### Constructor Detail

    - #### BsonDataOutput

          public BsonDataOutput()

    - #### BsonDataOutput

          public BsonDataOutput(int initialSize)

  - ### Method Detail

    - #### getBufferFor

          protected ByteBuffer getBufferFor(int position)

    - #### newByteBuffer

          protected ByteBuffer newByteBuffer(int bufferSize)

    - #### updateSize

          protected void updateSize(int newSize)

    - #### size

          public int size()

    - #### writeByte

          public void writeByte(int value)

      Specified by:
        `writeByte` in interface `DataOutput`

    - #### writeByte

          public void writeByte(int position,
                       int value)

    - #### write

          public void write(byte[] b)

      Specified by:
        `write` in interface `DataOutput`

    - #### write

          public void write(byte[] b,
                   int off,
                   int len)

      Specified by:
        `write` in interface `DataOutput`

    - #### write

          public void write(int position,
                   byte[] value,
                   int offset,
                   int length)

    - #### write

          public void write(int b)

      Specified by:
        `write` in interface `DataOutput`

    - #### writeBoolean

          public void writeBoolean(boolean value)

      Specified by:
        `writeBoolean` in interface `DataOutput`

    - #### writeBoolean

          public void writeBoolean(int position,
                          boolean value)

    - #### writeChar

          public void writeChar(int value)

      Specified by:
        `writeChar` in interface `DataOutput`

    - #### writeChar

          public void writeChar(int position,
                       int value)

    - #### writeInt

          public void writeInt(int value)

      Specified by:
        `writeInt` in interface `DataOutput`

    - #### writeInt

          public void writeInt(int position,
                      int value)

    - #### writeShort

          public void writeShort(int value)

      Specified by:
        `writeShort` in interface `DataOutput`

    - #### writeShort

          public void writeShort(int position,
                        int value)

    - #### writeLong

          public void writeLong(long value)

      Specified by:
        `writeLong` in interface `DataOutput`

    - #### writeLong

          public void writeLong(int position,
                       long value)

    - #### writeFloat

          public void writeFloat(float value)

      Specified by:
        `writeFloat` in interface `DataOutput`

    - #### writeFloat

          public void writeFloat(int position,
                        float value)

    - #### writeDouble

          public void writeDouble(double value)

      Specified by:
        `writeDouble` in interface `DataOutput`

    - #### writeDouble

          public void writeDouble(int position,
                         double value)

    - #### writeBytes

          @Deprecated
          public void writeBytes(String str)

      Deprecated. The semantics of `writeBytes(String s)` are considered dangerous. Please use `writeUTF(String s)`, `writeChars(String s)` or another write method instead.
      Writes a string to the output stream. For every character in the string `s`, taken in order, one byte is written to the output stream. If `s` is `null`, a `NullPointerException` is thrown.

      If `s.length` is zero, then no bytes are written. Otherwise, the character `s[0]` is written first, then `s[1]`, and so on; the last character written is `s[s.length-1]`. For each character, one byte is written, the low-order byte, in exactly the manner of the `writeByte` method . The high-order eight bits of each character in the string are ignored.

      Specified by:
        `writeBytes` in interface `DataOutput`
      Parameters:
        `str` - the string value to be written.

    - #### writeChars

          public void writeChars(String str)

      Writes every character in the string `s`, to the output stream, in order, two bytes per character. If `s` is `null`, a `NullPointerException` is thrown. If `s.length` is zero, then no characters are written. Otherwise, the character `s[0]` is written first, then `s[1]`, and so on; the last character written is `s[s.length-1]`. For each character, two bytes are actually written, low-order byte first, in exactly the manner of the `writeChar` method.
      Specified by:
        `writeChars` in interface `DataOutput`
      Parameters:
        `str` - the string value to be written.

    - #### writeUTF

          public void writeUTF(String str)

      Specified by:
        `writeUTF` in interface `DataOutput`

    - #### writeUTFString

          public int writeUTFString(String str)

      Writes the modified UTF-8 representation of every character in the string `s`. This is similar to the standard `writeUTF(String)` but without the leading two byte length. If `s` is `null`, a `NullPointerException` is thrown. Each character in the string `s` is converted to a group of one, two, or three bytes, depending on the value of the character.

      If a character `c` is in the range `\u0001` through `\u007f`, it is represented by one byte:

           (byte)c

      If a character `c` is `\u0000` or is in the range `\u0080` through `\u07ff`, then it is represented by two bytes, to be written in the order shown:

           (byte)(0xc0 | (0x1f & (c >> 6)))
           (byte)(0x80 | (0x3f & c))

      If a character `c` is in the range `\u0800` through `uffff`, then it is represented by three bytes, to be written in the order shown:

           (byte)(0xe0 | (0x0f & (c >> 12)))
           (byte)(0x80 | (0x3f & (c >>  6)))
           (byte)(0x80 | (0x3f & c))

      First, the total number of bytes needed to represent all the characters of `s` is calculated. If this number is larger than `65535`, then a `UTFDataFormatException` is thrown. Otherwise, this length is written to the output stream in exactly the manner of the `writeShort` method; after this, the one-, two-, or three-byte representation of each character in the string `s` is written.

      The bytes written by this method may be read by the `readUTF` method of interface `DataInput` , which will then return a `String` equal to `s`.

      Parameters:
        `str` - the string value to be written.
      Returns:
        the number of bytes written

    - #### writeUTF

          public int writeUTF(int position,
                     String str)

    - #### writeTo

          public void writeTo(OutputStream stream)
                       throws IOException

      Write all content to the supplied stream.
      Parameters:
        `stream` - the stream to which the content is to be written.
      Throws:
        `IOException` - if there is a problem writing to the supplied stream

    - #### writeTo

          public void writeTo(WritableByteChannel channel)
                       throws IOException

      Write all content to the supplied channel.
      Parameters:
        `channel` - the channel to which the content is to be written.
      Throws:
        `IOException` - if there is a problem writing to the supplied stream

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.