Package loci.common
Class RandomAccessOutputStream
java.lang.Object
java.io.OutputStream
loci.common.RandomAccessOutputStream
- All Implemented Interfaces:
Closeable,DataOutput,Flushable,AutoCloseable
RandomAccessOutputStream provides methods for writing to files and
byte arrays.
-
Constructor Summary
ConstructorsConstructorDescriptionRandomAccessOutputStream(byte[] array) Constructs a random access stream around the given byte array.Constructs a random access stream around the given file.Constructs a random access stream around the given handle. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidflush()longbooleanGets the endianness of the stream.longlength()voidorder(boolean little) Sets the endianness of the stream.voidseek(long pos) Seeks to the given offset within the stream.voidskipBytes(int skip) Advances the current offset by the given number of bytes.voidwrite(byte[] b) voidwrite(byte[] b, int off, int len) voidwrite(int b) voidwrite(ByteBuffer b) Writes bytes to the stream from the given buffer.voidwrite(ByteBuffer b, int off, int len) voidwriteBits(int value, int numBits) Writes the given value using the given number of bits.voidWrites the bits represented by a bit string to the buffer.voidwriteBoolean(boolean v) voidwriteByte(int v) voidwriteBytes(String s) voidwriteChar(int v) voidwriteChars(String s) voidwriteDouble(double v) voidwriteFloat(float v) voidwriteInt(int v) voidWrites the given string followed by a newline character.voidwriteLong(long v) voidwriteShort(int v) voidMethods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
RandomAccessOutputStream
Constructs a random access stream around the given file.- Parameters:
file- Filename to open the stream for.- Throws:
IOException- If there is a problem opening the file.
-
RandomAccessOutputStream
Constructs a random access stream around the given handle.- Parameters:
handle- Handle to open the stream for.
-
RandomAccessOutputStream
Constructs a random access stream around the given byte array.- Parameters:
array- the byte array to be written to- Throws:
IOException- if the array cannot be wrapped in aByteArrayHandle
-
-
Method Details
-
seek
Seeks to the given offset within the stream.- Parameters:
pos- the new offset within the stream- Throws:
IOException- is the seek is not successful
-
getFilePointer
- Returns:
- the current offset within the stream.
- Throws:
IOException- if the offset cannot be retrieved
-
length
- Returns:
- the length of the file
- Throws:
IOException- if the length cannot be retrieved
-
skipBytes
Advances the current offset by the given number of bytes.- Parameters:
skip- the number of bytes to skip- Throws:
IOException- if the offset cannot be changed
-
order
public void order(boolean little) Sets the endianness of the stream.- Parameters:
little- true if the byte order of the stream is little-endian
-
isLittleEndian
public boolean isLittleEndian()Gets the endianness of the stream.- Returns:
- true if the byte order of the stream is little-endian
-
writeLine
Writes the given string followed by a newline character.- Parameters:
s- the line of text to be written. A newline does not need to be appended, as this method automatically writes a newline character.- Throws:
IOException- if writing is not possible
-
writeBits
Writes the given value using the given number of bits.- Parameters:
value- int value to be writtennumBits- exact number of bits to be written- Throws:
IOException- if writing fails for any reason
-
writeBits
Writes the bits represented by a bit string to the buffer.- Parameters:
bitString- a string of '0' and/or '1' characters representing bits to be written. Each character in the string results in a call towriteBits(int, int)that writes 1 bit.- Throws:
IllegalArgumentException- If any characters other than '0' and '1' appear in the string.IOException- if writing fails for any other reason
-
write
- Specified by:
writein interfaceDataOutput- Overrides:
writein classOutputStream- Throws:
IOException
-
write
- Specified by:
writein interfaceDataOutput- Overrides:
writein classOutputStream- Throws:
IOException
-
write
Writes bytes to the stream from the given buffer.- Parameters:
b- Source buffer to read data from.- Throws:
IOException- If there is an error writing to the stream.
-
write
- Parameters:
b- Source buffer to read data from.off- Offset within the buffer to start reading from.len- Number of bytes to read.- Throws:
IOException- If there is an error writing to the stream.
-
write
- Specified by:
writein interfaceDataOutput- Specified by:
writein classOutputStream- Throws:
IOException
-
writeBoolean
- Specified by:
writeBooleanin interfaceDataOutput- Throws:
IOException
-
writeByte
- Specified by:
writeBytein interfaceDataOutput- Throws:
IOException
-
writeBytes
- Specified by:
writeBytesin interfaceDataOutput- Throws:
IOException
-
writeChar
- Specified by:
writeCharin interfaceDataOutput- Throws:
IOException
-
writeChars
- Specified by:
writeCharsin interfaceDataOutput- Throws:
IOException
-
writeDouble
- Specified by:
writeDoublein interfaceDataOutput- Throws:
IOException
-
writeFloat
- Specified by:
writeFloatin interfaceDataOutput- Throws:
IOException
-
writeInt
- Specified by:
writeIntin interfaceDataOutput- Throws:
IOException
-
writeLong
- Specified by:
writeLongin interfaceDataOutput- Throws:
IOException
-
writeShort
- Specified by:
writeShortin interfaceDataOutput- Throws:
IOException
-
writeUTF
- Specified by:
writeUTFin interfaceDataOutput- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-