org.mapdb
Class DataOutput2

java.lang.Object
  extended by java.io.OutputStream
      extended by org.mapdb.DataOutput2
All Implemented Interfaces:
Closeable, DataOutput, Flushable

public final class DataOutput2
extends OutputStream
implements DataOutput

Provides DataOutput implementation on top of growable byte[]

ByteArrayOutputStream is not used as it requires byte[] copying

Author:
Jan Kotek

Field Summary
 byte[] buf
           
 int pos
           
 
Constructor Summary
DataOutput2()
           
DataOutput2(byte[] buf)
           
 
Method Summary
 byte[] copyBytes()
           
 void ensureAvail(int n)
          make sure there will be enought space in buffer to write N bytes
static void packInt(DataOutput in, int value)
          Pack non-negative long into output stream.
static void packLong(DataOutput out, long value)
          Pack non-negative long into output stream.
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 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 s)
           
 
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
 

Field Detail

buf

public byte[] buf

pos

public volatile int pos
Constructor Detail

DataOutput2

public DataOutput2()

DataOutput2

public DataOutput2(byte[] buf)
Method Detail

copyBytes

public byte[] copyBytes()

ensureAvail

public void ensureAvail(int n)
make sure there will be enought space in buffer to write N bytes


write

public void write(int b)
           throws IOException
Specified by:
write in interface DataOutput
Specified by:
write in class OutputStream
Throws:
IOException

write

public void write(byte[] b)
           throws IOException
Specified by:
write in interface DataOutput
Overrides:
write in class OutputStream
Throws:
IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Specified by:
write in interface DataOutput
Overrides:
write in class OutputStream
Throws:
IOException

writeBoolean

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

writeByte

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

writeShort

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

writeChar

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

writeInt

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

writeLong

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

writeFloat

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

writeDouble

public void writeDouble(double v)
                 throws IOException
Specified by:
writeDouble 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 s)
              throws IOException
Specified by:
writeUTF in interface DataOutput
Throws:
IOException

packLong

public static void packLong(DataOutput out,
                            long value)
                     throws IOException
Pack non-negative long into output stream. It will occupy 1-10 bytes depending on value (lower values occupy smaller space) This method originally comes from Kryo Framework, author Nathan Sweet. It was modified to fit MapDB needs.

Parameters:
out - DataOutput to put value into
value - to be serialized, must be non-negative
Throws:
IOException

packInt

public static void packInt(DataOutput in,
                           int value)
                    throws IOException
Pack non-negative long into output stream. It will occupy 1-5 bytes depending on value (lower values occupy smaller space) This method originally comes from Kryo Framework, author Nathan Sweet. It was modified to fit MapDB needs.

Parameters:
in - DataOutput to put value into
value - to be serialized, must be non-negative
Throws:
IOException


Copyright © 2014. All Rights Reserved.