org.basex.io.out
Class DataOutput

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

public final class DataOutput
extends java.io.OutputStream

This is an output stream for project specific data types. It bears resemblance to Java's DataOutputStream.

Author:
BaseX Team 2005-12, BSD License, Christian Gruen

Constructor Summary
DataOutput(IOFile db)
          Constructor, specifying a file.
DataOutput(IOFile db, int bufs)
          Constructor, specifying a file and a buffer size.
DataOutput(java.io.OutputStream out)
          Constructor, specifying an output stream.
 
Method Summary
 void close()
           
 void flush()
           
 long size()
          Returns the number of written bytes.
 void write(int b)
           
 void write1(int v)
          Writes a byte value.
 void write2(int v)
          Writes a short value.
 void write4(int v)
          Writes an integer value.
 void write5(long v)
          Writes 5 bytes of a long value.
 void writeBool(boolean b)
          Writes a boolean value.
 void writeBytes(byte[] bytes)
          Writes a byte array.
 void writeDiffs(IntList array)
          Writes distances between integers.
 int writeDouble(double num)
          Writes a double value.
 void writeLongs(long[] array)
          Writes long values.
 int writeNum(int v)
          Writes a compressed integer value; see Num for more.
 void writeNums(int[] array)
          Writes compressed numbers; see Num for more.
 int writeToken(byte[] tok)
          Writes a token, represented by its compressed length and its byte array.
 void writeTokens(byte[][] array)
          Writes tokens.
 
Methods inherited from class java.io.OutputStream
write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataOutput

public DataOutput(java.io.OutputStream out)
Constructor, specifying an output stream.

Parameters:
out - output stream to operate on

DataOutput

public DataOutput(IOFile db)
           throws java.io.IOException
Constructor, specifying a file.

Parameters:
db - name of the database
Throws:
java.io.IOException - I/O exception

DataOutput

public DataOutput(IOFile db,
                  int bufs)
           throws java.io.IOException
Constructor, specifying a file and a buffer size. The specified buffer size is used.

Parameters:
db - name of the database
bufs - size of the buffer to use
Throws:
java.io.IOException - I/O exception
Method Detail

write

public void write(int b)
           throws java.io.IOException
Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException

writeBool

public void writeBool(boolean b)
               throws java.io.IOException
Writes a boolean value.

Parameters:
b - boolean value
Throws:
java.io.IOException - I/O exception

writeToken

public int writeToken(byte[] tok)
               throws java.io.IOException
Writes a token, represented by its compressed length and its byte array.

Parameters:
tok - array to be written
Returns:
number of written bytes
Throws:
java.io.IOException - I/O exception

writeDouble

public int writeDouble(double num)
                throws java.io.IOException
Writes a double value.

Parameters:
num - array to be written
Returns:
number of written bytes
Throws:
java.io.IOException - I/O exception

writeTokens

public void writeTokens(byte[][] array)
                 throws java.io.IOException
Writes tokens. null references are replaced by an empty array.

Parameters:
array - array to be written
Throws:
java.io.IOException - I/O exception

writeDiffs

public void writeDiffs(IntList array)
                throws java.io.IOException
Writes distances between integers.

Parameters:
array - array to be written
Throws:
java.io.IOException - I/O exception

writeNums

public void writeNums(int[] array)
               throws java.io.IOException
Writes compressed numbers; see Num for more.

Parameters:
array - array to be written
Throws:
java.io.IOException - I/O exception

writeNum

public int writeNum(int v)
             throws java.io.IOException
Writes a compressed integer value; see Num for more. By compressing, the size of the database files is reduced.

Parameters:
v - value to be written
Returns:
number of written values
Throws:
java.io.IOException - I/O exception

writeLongs

public void writeLongs(long[] array)
                throws java.io.IOException
Writes long values. NOTE: the long values are not compressed!

Parameters:
array - array to be written
Throws:
java.io.IOException - I/O exception

write1

public void write1(int v)
            throws java.io.IOException
Writes a byte value.

Parameters:
v - value to be written
Throws:
java.io.IOException - I/O exception

write2

public void write2(int v)
            throws java.io.IOException
Writes a short value.

Parameters:
v - value to be written
Throws:
java.io.IOException - I/O exception

write4

public void write4(int v)
            throws java.io.IOException
Writes an integer value.

Parameters:
v - value to be written
Throws:
java.io.IOException - I/O exception

write5

public void write5(long v)
            throws java.io.IOException
Writes 5 bytes of a long value.

Parameters:
v - value to be written
Throws:
java.io.IOException - I/O exception

writeBytes

public void writeBytes(byte[] bytes)
                throws java.io.IOException
Writes a byte array.

Parameters:
bytes - array to be written
Throws:
java.io.IOException - I/O exception

size

public long size()
Returns the number of written bytes. This is not necessarily e.g. the file size.

Returns:
number of written bytes

flush

public void flush()
           throws java.io.IOException
Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException