Class DataOutput

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

public final class DataOutput extends OutputStream
This is an output stream for project specific data types. It bears resemblance to Java's DataOutputStream.
Author:
BaseX Team 2005-21, BSD License, Christian Gruen
  • Constructor Details

    • DataOutput

      public DataOutput(OutputStream out)
      Constructor, specifying an output stream.
      Parameters:
      out - the stream to write to
    • DataOutput

      public DataOutput(IOFile input) throws IOException
      Constructor, specifying a file.
      Parameters:
      input - input to be read
      Throws:
      IOException - I/O exception
    • DataOutput

      public DataOutput(IOFile input, int bufsize) throws IOException
      Constructor, specifying a file and a buffer size. The specified buffer size is used.
      Parameters:
      input - input to be read
      bufsize - size of the buffer to use
      Throws:
      IOException - I/O exception
  • Method Details

    • write

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

      public void writeBool(boolean b) throws IOException
      Writes a boolean value.
      Parameters:
      b - boolean value
      Throws:
      IOException - I/O exception
    • writeToken

      public int writeToken(byte[] tok) throws 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:
      IOException - I/O exception
    • writeDouble

      public int writeDouble(double num) throws IOException
      Writes a double value.
      Parameters:
      num - array to be written
      Returns:
      number of written bytes
      Throws:
      IOException - I/O exception
    • writeTokens

      public void writeTokens(byte[][] array) throws IOException
      Writes tokens. null references are replaced by an empty array.
      Parameters:
      array - array to be written
      Throws:
      IOException - I/O exception
    • writeDiffs

      public void writeDiffs(IntList array) throws IOException
      Writes distances between integers.
      Parameters:
      array - array to be written
      Throws:
      IOException - I/O exception
    • writeNums

      public void writeNums(int[] array) throws IOException
      Writes compressed numbers; see Num for more.
      Parameters:
      array - array to be written
      Throws:
      IOException - I/O exception
    • writeNum

      public int writeNum(int v) throws 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:
      IOException - I/O exception
    • writeLongs

      public void writeLongs(long[] array) throws IOException
      Writes long values. NOTE: the long values are not compressed!
      Parameters:
      array - array to be written
      Throws:
      IOException - I/O exception
    • write1

      public void write1(int v) throws IOException
      Writes a byte value.
      Parameters:
      v - value to be written
      Throws:
      IOException - I/O exception
    • write2

      public void write2(int v) throws IOException
      Writes a short value.
      Parameters:
      v - value to be written
      Throws:
      IOException - I/O exception
    • write4

      public void write4(int v) throws IOException
      Writes an integer value.
      Parameters:
      v - value to be written
      Throws:
      IOException - I/O exception
    • write5

      public void write5(long v) throws IOException
      Writes 5 bytes of a long value.
      Parameters:
      v - value to be written
      Throws:
      IOException - I/O exception
    • writeBytes

      public void writeBytes(byte[] bytes) throws IOException
      Writes a byte array.
      Parameters:
      bytes - array to be written
      Throws:
      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 IOException
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
      Throws:
      IOException
    • close

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