TupleOutput (Sleepycat Software, Inc. - Berkeley DB Java API)
Keywords: com.sleepycat.bdb.bind.tuple.TupleOutput,TupleOutput class

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Berkeley DB version 4.2.52
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.sleepycat.bdb.bind.tuple
Class TupleOutput

    java.lang.Object
      |
      +--java.io.OutputStream
            |
            +--com.sleepycat.bdb.util.FastOutputStream
                  |
                  +--com.sleepycat.bdb.bind.tuple.TupleOutput

public class TupleOutput
extends FastOutputStream

Used by tuple bindings to write tuple data.

This class has many methods that have the same signatures as methods in the `DataOutput` interface. The reason this class does not implement `DataOutput` is because it would break the interface contract for those methods because of data format differences.

Signed numbers are stored in the buffer in MSB (most significant byte first) order with their sign bit (high-order bit) inverted to cause negative numbers to be sorted first when comparing values as unsigned byte arrays, as done in a database. Unsigned numbers, including characters, are stored in MSB order with no change to their sign bit.

Strings and character arrays are stored either as a fixed length array of unicode characters, where the length must be known by the application, or as a null-terminated UTF byte array.

Floats and doubles are stored in standard integer-bit representation and are therefore not ordered by numeric value.

Field Summary

Fields inherited from class com.sleepycat.bdb.util.FastOutputStream
`DEFAULT_BUMP_SIZE, DEFAULT_INIT_SIZE`

Constructor Summary
`TupleOutput()` Creates a tuple output object for writing a byte array of tuple data.
`TupleOutput(byte[] buffer)` Creates a tuple output object for writing a byte array of tuple data, using a given buffer.

Method Summary
`void` | `writeBoolean(boolean val)` Writes a boolean (one byte) unsigned value to the buffer, writing one if the value is true and zero if it is false.
`void` | `writeByte(int val)` Writes an signed byte (one byte) value to the buffer.
`void` | `writeBytes(char[] chars)` Writes the specified bytes to the buffer, converting each character to an unsigned byte value.
`void` | `writeBytes(String val)` Writes the specified bytes to the buffer, converting each character to an unsigned byte value.
`void` | `writeChar(int val)` Writes a char (two byte) unsigned value to the buffer.
`void` | `writeChars(char[] chars)` Writes the specified characters to the buffer, converting each character to a two byte unsigned value.
`void` | `writeChars(String val)` Writes the specified characters to the buffer, converting each character to a two byte unsigned value.
`void` | `writeDouble(double val)` Writes an signed double (eight byte) value to the buffer.
`void` | `writeFloat(float val)` Writes an signed float (four byte) value to the buffer.
`void` | `writeInt(int val)` Writes an signed int (four byte) value to the buffer.
`void` | `writeLong(long val)` Writes an signed long (eight byte) value to the buffer.
`void` | `writeShort(int val)` Writes an signed short (two byte) value to the buffer.
`void` | `writeString(char[] chars)` Writes the specified characters to the buffer, converting each character to UTF format.
`void` | `writeString(String val)` Writes the specified characters to the buffer, converting each character to UTF format, and adding a null terminator byte.
`void` | `writeUnsignedByte(int val)` Writes an unsigned byte (one byte) value to the buffer.
`void` | `writeUnsignedInt(long val)` Writes an unsigned int (four byte) value to the buffer.
`void` | `writeUnsignedShort(int val)` Writes an unsigned short (two byte) value to the buffer.

Methods inherited from class com.sleepycat.bdb.util.FastOutputStream
`addSize, getBufferBytes, getBufferLength, getBufferOffset, makeSpace, reset, size, toByteArray, toByteArray, toString, toString, write, write, write, writeTo`

Methods inherited from class java.io.OutputStream
`close, flush`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### TupleOutput

    public TupleOutput()

  Creates a tuple output object for writing a byte array of tuple data.

### TupleOutput

    public TupleOutput(byte[] buffer)

  Creates a tuple output object for writing a byte array of tuple data, using a given buffer. A new buffer will be allocated only if the number of bytes needed is greater than the length of this buffer. A reference to the byte array will be kept by this object and therefore the byte array should not be modified while this object is in use.

Parameters:
  `buffer` - is the byte array to use as the buffer.

Method Detail

### writeBytes

    public final void writeBytes(String val)
                          throws IOException

  Writes the specified bytes to the buffer, converting each character to an unsigned byte value. Writes values that can be read using `TupleInput.readBytes(int)`. Only characters with values below 0x100 may be written using this method, since the high-order 8 bits of all characters are discarded.

  Parameters:
    `val` - is the string containing the values to be written.
  Throws:
    `IOException` - is never thrown but is declared for compatibility with {java.io.OutputStream#write}.

### writeChars

    public final void writeChars(String val)
                          throws IOException

  Writes the specified characters to the buffer, converting each character to a two byte unsigned value. Writes values that can be read using `TupleInput.readChars(int)`.

  Parameters:
    `val` - is the string containing the characters to be written.
  Throws:
    `IOException` - is never thrown but is declared for compatibility with {java.io.OutputStream#write}.

### writeString

    public final void writeString(String val)
                           throws IOException

  Writes the specified characters to the buffer, converting each character to UTF format, and adding a null terminator byte. Writes values that can be read using `TupleInput.readString()`.

  Parameters:
    `val` - is the string containing the characters to be written.
  Throws:
    `IOException` - is never thrown but is declared for compatibility with {java.io.OutputStream#write}.

### writeChar

    public final void writeChar(int val)
                         throws IOException

  Writes a char (two byte) unsigned value to the buffer. Writes values that can be read using `TupleInput.readChar()`.

  Parameters:
    `val` - is the value to write to the buffer.
  Throws:
    `IOException` - is never thrown but is declared for compatibility with {java.io.OutputStream#write}.

### writeBoolean

    public final void writeBoolean(boolean val)
                            throws IOException

  Writes a boolean (one byte) unsigned value to the buffer, writing one if the value is true and zero if it is false. Writes values that can be read using `TupleInput.readBoolean()`.

  Parameters:
    `val` - is the value to write to the buffer.
  Throws:
    `IOException` - is never thrown but is declared for compatibility with {java.io.OutputStream#write}.

### writeByte

    public final void writeByte(int val)
                         throws IOException

  Writes an signed byte (one byte) value to the buffer. Writes values that can be read using `TupleInput.readByte()`.

  Parameters:
    `val` - is the value to write to the buffer.
  Throws:
    `IOException` - is never thrown but is declared for compatibility with {java.io.OutputStream#write}.

### writeShort

    public final void writeShort(int val)
                          throws IOException

  Writes an signed short (two byte) value to the buffer. Writes values that can be read using `TupleInput.readShort()`.

  Parameters:
    `val` - is the value to write to the buffer.
  Throws:
    `IOException` - is never thrown but is declared for compatibility with {java.io.OutputStream#write}.

### writeInt

    public final void writeInt(int val)
                        throws IOException

  Writes an signed int (four byte) value to the buffer. Writes values that can be read using `TupleInput.readInt()`.

  Parameters:
    `val` - is the value to write to the buffer.
  Throws:
    `IOException` - is never thrown but is declared for compatibility with {java.io.OutputStream#write}.

### writeLong

    public final void writeLong(long val)
                         throws IOException

  Writes an signed long (eight byte) value to the buffer. Writes values that can be read using `TupleInput.readLong()`.

  Parameters:
    `val` - is the value to write to the buffer.
  Throws:
    `IOException` - is never thrown but is declared for compatibility with {java.io.OutputStream#write}.

### writeFloat

    public final void writeFloat(float val)
                          throws IOException

  Writes an signed float (four byte) value to the buffer. Writes values that can be read using `TupleInput.readFloat()`. `Float.floatToIntBits` is used to convert the signed float value.

  Parameters:
    `val` - is the value to write to the buffer.
  Throws:
    `IOException` - is never thrown but is declared for compatibility with {java.io.OutputStream#write}.

### writeDouble

    public final void writeDouble(double val)
                           throws IOException

  Writes an signed double (eight byte) value to the buffer. Writes values that can be read using `TupleInput.readDouble()`. `Double.doubleToLongBits` is used to convert the signed double value.

  Parameters:
    `val` - is the value to write to the buffer.
  Throws:
    `IOException` - is never thrown but is declared for compatibility with {java.io.OutputStream#write}.

### writeBytes

    public final void writeBytes(char[] chars)
                          throws IOException

  Writes the specified bytes to the buffer, converting each character to an unsigned byte value. Writes values that can be read using `TupleInput.readBytes(int)`. Only characters with values below 0x100 may be written using this method, since the high-order 8 bits of all characters are discarded.

  Parameters:
    `chars` - is the array of values to be written.
  Throws:
    `IOException` - is never thrown but is declared for compatibility with {java.io.OutputStream#write}.

### writeChars

    public final void writeChars(char[] chars)
                          throws IOException

  Writes the specified characters to the buffer, converting each character to a two byte unsigned value. Writes values that can be read using `TupleInput.readChars(int)`.

  Parameters:
    `chars` - is the array of characters to be written.
  Throws:
    `IOException` - is never thrown but is declared for compatibility with {java.io.OutputStream#write}.

### writeString

    public final void writeString(char[] chars)
                           throws IOException

  Writes the specified characters to the buffer, converting each character to UTF format. Writes values that can be read using `TupleInput.readString(int)` or `TupleInput.readString(char[])`.

  Parameters:
    `chars` - is the array of characters to be written.
  Throws:
    `IOException` - is never thrown but is declared for compatibility with {java.io.OutputStream#write}.

### writeUnsignedByte

    public final void writeUnsignedByte(int val)
                                 throws IOException

  Writes an unsigned byte (one byte) value to the buffer. Writes values that can be read using `TupleInput.readUnsignedByte()`.

  Parameters:
    `val` - is the value to write to the buffer.
  Throws:
    `IOException` - is never thrown but is declared for compatibility with {java.io.OutputStream#write}.

### writeUnsignedShort

    public final void writeUnsignedShort(int val)
                                  throws IOException

  Writes an unsigned short (two byte) value to the buffer. Writes values that can be read using `TupleInput.readUnsignedShort()`.

  Parameters:
    `val` - is the value to write to the buffer.
  Throws:
    `IOException` - is never thrown but is declared for compatibility with {java.io.OutputStream#write}.

### writeUnsignedInt

    public final void writeUnsignedInt(long val)
                                throws IOException

  Writes an unsigned int (four byte) value to the buffer. Writes values that can be read using `TupleInput.readUnsignedInt()`.

  Parameters:
    `val` - is the value to write to the buffer.
  Throws:
    `IOException` - is never thrown but is declared for compatibility with {java.io.OutputStream#write}.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Berkeley DB version 4.2.52
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright (c) 1996-2003 Sleepycat Software, Inc. - All rights reserved.