Package org.basex.io.out
Class DataOutput
java.lang.Object
java.io.OutputStream
org.basex.io.out.DataOutput
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
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 Summary
ConstructorsConstructorDescriptionDataOutput(OutputStream out) Constructor, specifying an output stream.DataOutput(IOFile input) Constructor, specifying a file.DataOutput(IOFile input, int bufsize) Constructor, specifying a file and a buffer size. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidflush()longsize()Returns the number of written bytes.voidwrite(int b) voidwrite1(int v) Writes a byte value.voidwrite2(int v) Writes a short value.voidwrite4(int v) Writes an integer value.voidwrite5(long v) Writes 5 bytes of a long value.voidwriteBool(boolean b) Writes a boolean value.voidwriteBytes(byte[] bytes) Writes a byte array.voidwriteDiffs(IntList array) Writes distances between integers.intwriteDouble(double num) Writes a double value.voidwriteLongs(long[] array) Writes long values.intwriteNum(int v) Writes a compressed integer value; seeNumfor more.voidwriteNums(int[] array) Writes compressed numbers; seeNumfor more.intwriteToken(byte[] tok) Writes a token, represented by its compressed length and its byte array.voidwriteTokens(byte[][] array) Writes tokens.Methods inherited from class java.io.OutputStream
nullOutputStream, write, write
-
Constructor Details
-
DataOutput
Constructor, specifying an output stream.- Parameters:
out- the stream to write to
-
DataOutput
Constructor, specifying a file.- Parameters:
input- input to be read- Throws:
IOException- I/O exception
-
DataOutput
Constructor, specifying a file and a buffer size. The specified buffer size is used.- Parameters:
input- input to be readbufsize- size of the buffer to use- Throws:
IOException- I/O exception
-
-
Method Details
-
write
- Specified by:
writein classOutputStream- Throws:
IOException
-
writeBool
Writes a boolean value.- Parameters:
b- boolean value- Throws:
IOException- I/O exception
-
writeToken
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
Writes a double value.- Parameters:
num- array to be written- Returns:
- number of written bytes
- Throws:
IOException- I/O exception
-
writeTokens
Writes tokens.nullreferences are replaced by an empty array.- Parameters:
array- array to be written- Throws:
IOException- I/O exception
-
writeDiffs
Writes distances between integers.- Parameters:
array- array to be written- Throws:
IOException- I/O exception
-
writeNums
Writes compressed numbers; seeNumfor more.- Parameters:
array- array to be written- Throws:
IOException- I/O exception
-
writeNum
Writes a compressed integer value; seeNumfor 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
Writes long values. NOTE: the long values are not compressed!- Parameters:
array- array to be written- Throws:
IOException- I/O exception
-
write1
Writes a byte value.- Parameters:
v- value to be written- Throws:
IOException- I/O exception
-
write2
Writes a short value.- Parameters:
v- value to be written- Throws:
IOException- I/O exception
-
write4
Writes an integer value.- Parameters:
v- value to be written- Throws:
IOException- I/O exception
-
write5
Writes 5 bytes of a long value.- Parameters:
v- value to be written- Throws:
IOException- I/O exception
-
writeBytes
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
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-