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-08, ISC License, Christian Gruen, Tim Petrowsky

Constructor Summary
DataOutput(java.io.OutputStream out)
          Constructor writing to an output stream.
DataOutput(java.lang.String db, java.lang.String fn)
          Convenience constructor.
DataOutput(java.lang.String db, java.lang.String fn, int bufs)
          Convenience constructor with a specified buffer size.
 
Method Summary
 void close()
           
 void flush()
           
 long size()
          Return 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.
 void writeBooleans(boolean[] array)
          Writes the specified array 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.
 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.lang.String db,
                  java.lang.String fn)
           throws java.io.IOException
Convenience constructor. A default buffer size will be used.

Parameters:
db - name of the database
fn - File to write to
Throws:
java.io.IOException - in case of write errors

DataOutput

public DataOutput(java.lang.String db,
                  java.lang.String fn,
                  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
fn - name of the file to write to
bufs - size of the buffer to use
Throws:
java.io.IOException - in case of write errors
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 - in case of write errors

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 - in case of write errors

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 - in case of write errors

writeBooleans

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

Parameters:
array - array to be written
Throws:
java.io.IOException - in case of write errors

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 - in case of write errors

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 - in case of write errors

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 - in case of write errors

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 - in case of write errors

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 - in case of write errors

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 - in case of write errors

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 - in case of write errors

size

public long size()
Return 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