com.bigdata.io
Class DataOutputBuffer

java.lang.Object
  extended by java.io.OutputStream
      extended by com.bigdata.io.ByteArrayBuffer
          extended by com.bigdata.io.DataOutputBuffer
All Implemented Interfaces:
IByteArrayBuffer, IByteArraySlice, IDataRecord, it.unimi.dsi.fastutil.io.RepositionableStream, Closeable, DataOutput, Flushable

public class DataOutputBuffer
extends ByteArrayBuffer
implements DataOutput

Fast special purpose serialization onto a managed byte[] buffer conforming to the DataOutput API.

Note: The base classes provide all of the same functionality without declaring IOException as a thrown exception.

Version:
$Id: DataOutputBuffer.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson

Field Summary
 
Fields inherited from class com.bigdata.io.ByteArrayBuffer
DEFAULT_INITIAL_CAPACITY, INFO, log
 
Constructor Summary
DataOutputBuffer()
          Uses ByteArrayBuffer.DEFAULT_INITIAL_CAPACITY.
DataOutputBuffer(InputStream in)
          Reads the entire input stream into the buffer.
DataOutputBuffer(int initialCapacity)
           
DataOutputBuffer(int len, byte[] buf)
           
DataOutputBuffer(ObjectInput in)
          Reads the entire input stream into the buffer.
 
Method Summary
 DataOutputBuffer reset()
          Conforms the return type to an instance of this class.
 void write(DataInput in, int len)
          Read len bytes into the buffer.
 void writeBoolean(boolean v)
           
 void writeByte(int v)
           
 void writeBytes(String s)
           
 void writeChar(int v)
           
 void writeChars(String s)
           
 void writeDouble(double v)
           
 void writeFloat(float v)
           
 void writeInt(int v)
           
 void writeLong(long v)
           
 void writeShort(int v)
           
 void writeUTF(String str)
           
 
Methods inherited from class com.bigdata.io.ByteArrayBuffer
array, asByteBuffer, assertNonNegative, capacity, copy, copyAll, copyRest, ensureCapacity, ensureFree, ensureFree, extend, flip, get, get, getBit, getByte, getByte, getDouble, getDouble, getFloat, getFloat, getInt, getInt, getLong, getLong, getNibbleLength, getOutputBitStream, getShort, getShort, len, limit, mark, off, packLong, packShort, pos, pos, position, position, put, put, put, put, putByte, putByte, putDouble, putDouble, putFloat, putFloat, putInt, putInt, putLong, putLong, putShort, putShort, remaining, rewind, setBit, skip, slice, toByteArray, trim, write, write, write
 
Methods inherited from class java.io.OutputStream
close, flush
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.io.DataOutput
write, write, write
 

Constructor Detail

DataOutputBuffer

public DataOutputBuffer()
Uses ByteArrayBuffer.DEFAULT_INITIAL_CAPACITY.


DataOutputBuffer

public DataOutputBuffer(int initialCapacity)
Parameters:
initialCapacity - The initial capacity of the internal byte[].

DataOutputBuffer

public DataOutputBuffer(int len,
                        byte[] buf)
Parameters:
len - The #of bytes of data already in the provided buffer.
buf - The buffer, with len pre-existing bytes of valid data. The buffer reference is used directly rather than making a copy of the data.

DataOutputBuffer

public DataOutputBuffer(InputStream in)
                 throws IOException
Reads the entire input stream into the buffer. The data are then available in ByteArrayBuffer.buf from position 0 (inclusive) through position ByteArrayBuffer.pos (exclusive).

Throws:
IOException

DataOutputBuffer

public DataOutputBuffer(ObjectInput in)
                 throws IOException
Reads the entire input stream into the buffer. The data are then available in ByteArrayBuffer.buf from position 0 (inclusive) through position ByteArrayBuffer.pos (exclusive).

Throws:
IOException
Method Detail

reset

public DataOutputBuffer reset()
Conforms the return type to an instance of this class. Prepares the buffer for new data by resetting the position and limit to zero.

Overrides:
reset in class ByteArrayBuffer
Returns:
This buffer.

write

public final void write(DataInput in,
                        int len)
                 throws IOException
Read len bytes into the buffer.

Parameters:
in - The input source.
len - The #of bytes to read.
Throws:
EOFException - if the EOF is reached before len bytes have been read.
IOException - if an I/O error occurs.
TODO:
read many bytes at a time., write test.

writeBoolean

public final void writeBoolean(boolean v)
                        throws IOException
Specified by:
writeBoolean in interface DataOutput
Throws:
IOException

writeByte

public final void writeByte(int v)
                     throws IOException
Specified by:
writeByte in interface DataOutput
Throws:
IOException

writeDouble

public final void writeDouble(double v)
                       throws IOException
Specified by:
writeDouble in interface DataOutput
Throws:
IOException

writeFloat

public final void writeFloat(float v)
                      throws IOException
Specified by:
writeFloat in interface DataOutput
Throws:
IOException

writeInt

public final void writeInt(int v)
                    throws IOException
Specified by:
writeInt in interface DataOutput
Throws:
IOException

writeLong

public final void writeLong(long v)
                     throws IOException
Specified by:
writeLong in interface DataOutput
Throws:
IOException

writeShort

public final void writeShort(int v)
                      throws IOException
Specified by:
writeShort in interface DataOutput
Throws:
IOException

writeChar

public final void writeChar(int v)
                     throws IOException
Specified by:
writeChar in interface DataOutput
Throws:
IOException

writeBytes

public void writeBytes(String s)
                throws IOException
Specified by:
writeBytes in interface DataOutput
Throws:
IOException

writeChars

public void writeChars(String s)
                throws IOException
Specified by:
writeChars in interface DataOutput
Throws:
IOException

writeUTF

public void writeUTF(String str)
              throws IOException
Specified by:
writeUTF in interface DataOutput
Throws:
IOException
TODO:
This is not wildly efficient (it would be fine if DataOutputStream#writeUTF(String str, DataOutput out)} was public) but the use cases for serializing the nodes and leaves of a btree do not suggest any requirement for Unicode (if you assume that the application values are already being serialized as byte[]s - which is always true when there is a client-server divide). It is used by Name2Addr to store the index names., Consider changing the access modified on the desired method using reflection.


Copyright © 2006-2009 SYSTAP, LLC. All Rights Reserved.