org.basex.io
Class DataOutput

java.lang.Object
  extended by java.io.OutputStream
      extended by org.basex.io.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.

Author:
Workgroup DBIS, University of Konstanz 2005-09, ISC License, Christian Gruen, Tim Petrowsky

Constructor Summary
DataOutput(java.io.File db)
          Convenience constructor.
DataOutput(java.io.File db, int bufs)
          Convenience constructor with a specified buffer size.
DataOutput(java.io.OutputStream out)
          Constructor writing to 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 an integer value to the specified output stream.
 void write2(int v)
          Writes an integer value to the specified output stream.
 void write5(long v)
          Writes an integer value to the specified output stream.
 void writeBool(boolean b)
          Writes a boolean value to the output stream.
 int writeBytes(byte[] text)
          Writes the specified array to the output stream.
 void writeBytesArray(byte[][] array)
          Writes the specified array to the output stream; null references are replaced with an empty array.
 int writeDouble(double num)
          Writes the specified array to the output stream.
 void writeInt(int v)
          Writes an integer value to the specified output stream.
 int writeNum(int v)
          Compresses and writes an integer value to the specified output stream.
 void writeNums(int[] array)
          Writes the specified array to the output stream.
 void writeString(java.lang.String s)
          Writes a string to the output stream.
 
Methods inherited from class java.io.OutputStream
write, write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataOutput

public DataOutput(java.io.OutputStream out)
Constructor writing to an output stream. Writes to the stream will not be buffered.

Parameters:
out - Output Stream to operate on

DataOutput

public DataOutput(java.io.File db)
           throws java.io.IOException
Convenience constructor. A default buffer size will be used.

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

DataOutput

public DataOutput(java.io.File db,
                  int bufs)
           throws java.io.IOException
Convenience constructor with a specified 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 to the output stream.

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

writeString

public void writeString(java.lang.String s)
                 throws java.io.IOException
Writes a string to the output stream.

Parameters:
s - string
Throws:
java.io.IOException - I/O exception

writeBytes

public int writeBytes(byte[] text)
               throws java.io.IOException
Writes the specified array to the output stream.

Parameters:
text - 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 the specified array to the output stream.

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

writeBytesArray

public void writeBytesArray(byte[][] array)
                     throws java.io.IOException
Writes the specified array to the output stream; null references are replaced with an empty array.

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

writeNums

public void writeNums(int[] array)
               throws java.io.IOException
Writes the specified array to the output stream.

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

writeNum

public int writeNum(int v)
             throws java.io.IOException
Compresses and writes an integer value to the specified output stream. 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

writeInt

public void writeInt(int v)
              throws java.io.IOException
Writes an integer value to the specified output stream.

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

write1

public void write1(int v)
            throws java.io.IOException
Writes an integer value to the specified output stream.

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

write2

public void write2(int v)
            throws java.io.IOException
Writes an integer value to the specified output stream.

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

write5

public void write5(long v)
            throws java.io.IOException
Writes an integer value to the specified output stream.

Parameters:
v - value 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