Package ch.systemsx.cisd.base.io
Class ByteBufferRandomAccessFile
- java.lang.Object
-
- ch.systemsx.cisd.base.io.ByteBufferRandomAccessFile
-
- All Implemented Interfaces:
IInputStream
,IOutputStream
,IRandomAccessFile
,ISynchronizable
,java.io.Closeable
,java.io.DataInput
,java.io.DataOutput
,java.lang.AutoCloseable
public class ByteBufferRandomAccessFile extends java.lang.Object implements IRandomAccessFile
An implementation ofIRandomAccessFile
based on aByteBuffer
.Does not implement
IRandomAccessFile.readLine()
.
-
-
Constructor Summary
Constructors Constructor Description ByteBufferRandomAccessFile(byte[] array)
Creates aIRandomAccessFile
wrapper for the given array.ByteBufferRandomAccessFile(byte[] array, int initialLength)
Creates aIRandomAccessFile
wrapper for the given array.ByteBufferRandomAccessFile(int capacity)
Creates aIRandomAccessFile
wrapper for aByteBuffer
with capacity.ByteBufferRandomAccessFile(java.nio.ByteBuffer buf)
Creates aIRandomAccessFile
wrapper for the given buf.ByteBufferRandomAccessFile(java.nio.ByteBuffer buf, int initialLength)
Creates aIRandomAccessFile
wrapper for the given buf.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
void
flush()
java.nio.ByteOrder
getByteOrder()
Gets the byte-order (endiness) of the random access file.long
getFilePointer()
Returns the current offset in this file.long
length()
Returns the length of this file.void
mark(int readlimit)
boolean
markSupported()
int
read()
int
read(byte[] b)
int
read(byte[] b, int off, int len)
boolean
readBoolean()
byte
readByte()
char
readChar()
double
readDouble()
float
readFloat()
void
readFully(byte[] b)
void
readFully(byte[] b, int off, int len)
int
readInt()
java.lang.String
readLine()
long
readLong()
short
readShort()
int
readUnsignedByte()
int
readUnsignedShort()
java.lang.String
readUTF()
void
reset()
void
seek(long pos)
Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.void
setByteOrder(java.nio.ByteOrder byteOrder)
Sets the byte-order (endiness) of the random access file.void
setLength(long newLength)
Sets the length of this file.long
skip(long n)
int
skipBytes(int n)
void
synchronize()
Performs a synchronization of the resource.void
write(byte[] b)
void
write(byte[] b, int off, int len)
void
write(int b)
void
writeBoolean(boolean v)
void
writeByte(int v)
void
writeBytes(java.lang.String s)
void
writeChar(int v)
void
writeChars(java.lang.String s)
void
writeDouble(double v)
void
writeFloat(float v)
void
writeInt(int v)
void
writeLong(long v)
void
writeShort(int v)
void
writeUTF(java.lang.String str)
-
-
-
Constructor Detail
-
ByteBufferRandomAccessFile
public ByteBufferRandomAccessFile(java.nio.ByteBuffer buf, int initialLength)
Creates aIRandomAccessFile
wrapper for the given buf.- Parameters:
buf
- The buffer to wrap.initialLength
- The initially set length (corresponds to theBuffer.limit()
).
-
ByteBufferRandomAccessFile
public ByteBufferRandomAccessFile(java.nio.ByteBuffer buf)
Creates aIRandomAccessFile
wrapper for the given buf. Does not change theBuffer.limit()
of buf.- Parameters:
buf
- The buffer to wrap.
-
ByteBufferRandomAccessFile
public ByteBufferRandomAccessFile(byte[] array, int initialLength)
Creates aIRandomAccessFile
wrapper for the given array.- Parameters:
array
- The byte array to wrap.initialLength
- The initially set length.
-
ByteBufferRandomAccessFile
public ByteBufferRandomAccessFile(byte[] array)
Creates aIRandomAccessFile
wrapper for the given array. The initialBuffer.limit()
will bearray.length
.- Parameters:
array
- The byte array to wrap.
-
ByteBufferRandomAccessFile
public ByteBufferRandomAccessFile(int capacity)
Creates aIRandomAccessFile
wrapper for aByteBuffer
with capacity. The initialBuffer.limit()
will be0
.- Parameters:
capacity
- The maximal size of theByteBuffer
.
-
-
Method Detail
-
getByteOrder
public java.nio.ByteOrder getByteOrder()
Description copied from interface:IRandomAccessFile
Gets the byte-order (endiness) of the random access file. Default is network-byte order (big-endian).- Specified by:
getByteOrder
in interfaceIRandomAccessFile
-
setByteOrder
public void setByteOrder(java.nio.ByteOrder byteOrder)
Description copied from interface:IRandomAccessFile
Sets the byte-order (endiness) of the random access file.- Specified by:
setByteOrder
in interfaceIRandomAccessFile
-
readFully
public void readFully(byte[] b) throws IOExceptionUnchecked
- Specified by:
readFully
in interfacejava.io.DataInput
- Specified by:
readFully
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readFully(byte[])
-
readFully
public void readFully(byte[] b, int off, int len) throws IOExceptionUnchecked
- Specified by:
readFully
in interfacejava.io.DataInput
- Specified by:
readFully
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readFully(byte[], int, int)
-
skipBytes
public int skipBytes(int n) throws IOExceptionUnchecked
- Specified by:
skipBytes
in interfacejava.io.DataInput
- Specified by:
skipBytes
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.skipBytes(int)
-
close
public void close() throws IOExceptionUnchecked
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceIInputStream
- Specified by:
close
in interfaceIOutputStream
- Throws:
IOExceptionUnchecked
- See Also:
InputStream.close()
-
read
public int read() throws IOExceptionUnchecked
- Specified by:
read
in interfaceIInputStream
- Throws:
IOExceptionUnchecked
- See Also:
InputStream.read()
-
read
public int read(byte[] b) throws IOExceptionUnchecked
- Specified by:
read
in interfaceIInputStream
- Throws:
IOExceptionUnchecked
- See Also:
InputStream.read(byte[])
-
read
public int read(byte[] b, int off, int len) throws IOExceptionUnchecked
- Specified by:
read
in interfaceIInputStream
- Throws:
IOExceptionUnchecked
- See Also:
InputStream.read(byte[], int, int)
-
skip
public long skip(long n) throws IOExceptionUnchecked
- Specified by:
skip
in interfaceIInputStream
- Throws:
IOExceptionUnchecked
- See Also:
InputStream.skip(long)
-
available
public int available() throws IOExceptionUnchecked
- Specified by:
available
in interfaceIInputStream
- Throws:
IOExceptionUnchecked
- See Also:
InputStream.available()
-
mark
public void mark(int readlimit)
- Specified by:
mark
in interfaceIInputStream
- See Also:
InputStream.mark(int)
-
reset
public void reset() throws IOExceptionUnchecked
- Specified by:
reset
in interfaceIInputStream
- Throws:
IOExceptionUnchecked
- See Also:
InputStream.reset()
-
markSupported
public boolean markSupported()
- Specified by:
markSupported
in interfaceIInputStream
- See Also:
InputStream.markSupported()
-
flush
public void flush() throws IOExceptionUnchecked
- Specified by:
flush
in interfaceIOutputStream
- Throws:
IOExceptionUnchecked
- See Also:
OutputStream.flush()
-
synchronize
public void synchronize() throws IOExceptionUnchecked
Description copied from interface:ISynchronizable
Performs a synchronization of the resource.- Specified by:
synchronize
in interfaceIOutputStream
- Specified by:
synchronize
in interfaceISynchronizable
- Throws:
IOExceptionUnchecked
- See Also:
OutputStream.flush()
-
getFilePointer
public long getFilePointer() throws IOExceptionUnchecked
Description copied from interface:IRandomAccessFile
Returns the current offset in this file.- Specified by:
getFilePointer
in interfaceIRandomAccessFile
- Returns:
- the offset from the beginning of the file, in bytes, at which the next read or write occurs.
- Throws:
IOExceptionUnchecked
- if an I/O error occurs.
-
seek
public void seek(long pos) throws IOExceptionUnchecked
Description copied from interface:IRandomAccessFile
Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs. The offset may be set beyond the end of the file. Setting the offset beyond the end of the file does not change the file length. The file length will change only by writing after the offset has been set beyond the end of the file.- Specified by:
seek
in interfaceIRandomAccessFile
- Parameters:
pos
- the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.- Throws:
IOExceptionUnchecked
- ifpos
is less than0
or if an I/O error occurs.
-
length
public long length() throws IOExceptionUnchecked
Description copied from interface:IRandomAccessFile
Returns the length of this file.- Specified by:
length
in interfaceIRandomAccessFile
- Returns:
- the length of this file, measured in bytes.
- Throws:
IOExceptionUnchecked
- if an I/O error occurs.
-
setLength
public void setLength(long newLength) throws IOExceptionUnchecked
Description copied from interface:IRandomAccessFile
Sets the length of this file.If the present length of the file as returned by the
length
method is greater than thenewLength
argument then the file will be truncated. In this case, if the file offset as returned by thegetFilePointer
method is greater thannewLength
then after this method returns the offset will be equal tonewLength
.If the present length of the file as returned by the
length
method is smaller than thenewLength
argument then the file will be extended. In this case, the contents of the extended portion of the file are not defined.- Specified by:
setLength
in interfaceIRandomAccessFile
- Parameters:
newLength
- The desired length of the file- Throws:
IOExceptionUnchecked
- If an I/O error occurs
-
readBoolean
public boolean readBoolean() throws IOExceptionUnchecked
- Specified by:
readBoolean
in interfacejava.io.DataInput
- Specified by:
readBoolean
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readBoolean()
-
readByte
public byte readByte() throws IOExceptionUnchecked
- Specified by:
readByte
in interfacejava.io.DataInput
- Specified by:
readByte
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readByte()
-
readUnsignedByte
public int readUnsignedByte() throws IOExceptionUnchecked
- Specified by:
readUnsignedByte
in interfacejava.io.DataInput
- Specified by:
readUnsignedByte
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readUnsignedByte()
-
readShort
public short readShort() throws IOExceptionUnchecked
- Specified by:
readShort
in interfacejava.io.DataInput
- Specified by:
readShort
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readShort()
-
readUnsignedShort
public int readUnsignedShort() throws IOExceptionUnchecked
- Specified by:
readUnsignedShort
in interfacejava.io.DataInput
- Specified by:
readUnsignedShort
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readUnsignedShort()
-
readChar
public char readChar() throws IOExceptionUnchecked
- Specified by:
readChar
in interfacejava.io.DataInput
- Specified by:
readChar
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readChar()
-
readInt
public int readInt() throws IOExceptionUnchecked
- Specified by:
readInt
in interfacejava.io.DataInput
- Specified by:
readInt
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readInt()
-
readLong
public long readLong() throws IOExceptionUnchecked
- Specified by:
readLong
in interfacejava.io.DataInput
- Specified by:
readLong
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readLong()
-
readFloat
public float readFloat() throws IOExceptionUnchecked
- Specified by:
readFloat
in interfacejava.io.DataInput
- Specified by:
readFloat
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readFloat()
-
readDouble
public double readDouble() throws IOExceptionUnchecked
- Specified by:
readDouble
in interfacejava.io.DataInput
- Specified by:
readDouble
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readDouble()
-
readLine
public java.lang.String readLine() throws java.lang.UnsupportedOperationException
- Specified by:
readLine
in interfacejava.io.DataInput
- Specified by:
readLine
in interfaceIRandomAccessFile
- Throws:
java.lang.UnsupportedOperationException
- See Also:
DataInput.readLine()
-
readUTF
public java.lang.String readUTF()
- Specified by:
readUTF
in interfacejava.io.DataInput
- Specified by:
readUTF
in interfaceIRandomAccessFile
- See Also:
DataInput.readUTF()
-
write
public void write(int b) throws IOExceptionUnchecked
- Specified by:
write
in interfacejava.io.DataOutput
- Specified by:
write
in interfaceIOutputStream
- Specified by:
write
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataOutput.write(int)
-
write
public void write(byte[] b) throws IOExceptionUnchecked
- Specified by:
write
in interfacejava.io.DataOutput
- Specified by:
write
in interfaceIOutputStream
- Specified by:
write
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataOutput.write(byte[])
-
write
public void write(byte[] b, int off, int len) throws IOExceptionUnchecked
- Specified by:
write
in interfacejava.io.DataOutput
- Specified by:
write
in interfaceIOutputStream
- Specified by:
write
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataOutput.write(byte[], int, int)
-
writeBoolean
public void writeBoolean(boolean v) throws IOExceptionUnchecked
- Specified by:
writeBoolean
in interfacejava.io.DataOutput
- Specified by:
writeBoolean
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataOutput.writeBoolean(boolean)
-
writeByte
public void writeByte(int v) throws IOExceptionUnchecked
- Specified by:
writeByte
in interfacejava.io.DataOutput
- Specified by:
writeByte
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataOutput.writeByte(int)
-
writeShort
public void writeShort(int v) throws IOExceptionUnchecked
- Specified by:
writeShort
in interfacejava.io.DataOutput
- Specified by:
writeShort
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataOutput.writeShort(int)
-
writeChar
public void writeChar(int v) throws IOExceptionUnchecked
- Specified by:
writeChar
in interfacejava.io.DataOutput
- Specified by:
writeChar
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataOutput.writeChar(int)
-
writeInt
public void writeInt(int v) throws IOExceptionUnchecked
- Specified by:
writeInt
in interfacejava.io.DataOutput
- Specified by:
writeInt
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataOutput.writeInt(int)
-
writeLong
public void writeLong(long v) throws IOExceptionUnchecked
- Specified by:
writeLong
in interfacejava.io.DataOutput
- Specified by:
writeLong
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataOutput.writeLong(long)
-
writeFloat
public void writeFloat(float v) throws IOExceptionUnchecked
- Specified by:
writeFloat
in interfacejava.io.DataOutput
- Specified by:
writeFloat
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataOutput.writeFloat(float)
-
writeDouble
public void writeDouble(double v) throws IOExceptionUnchecked
- Specified by:
writeDouble
in interfacejava.io.DataOutput
- Specified by:
writeDouble
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataOutput.writeDouble(double)
-
writeBytes
public void writeBytes(java.lang.String s) throws IOExceptionUnchecked
- Specified by:
writeBytes
in interfacejava.io.DataOutput
- Specified by:
writeBytes
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataOutput.writeBytes(String)
-
writeChars
public void writeChars(java.lang.String s) throws IOExceptionUnchecked
- Specified by:
writeChars
in interfacejava.io.DataOutput
- Specified by:
writeChars
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataOutput.writeChars(String)
-
writeUTF
public void writeUTF(java.lang.String str) throws java.lang.UnsupportedOperationException
- Specified by:
writeUTF
in interfacejava.io.DataOutput
- Specified by:
writeUTF
in interfaceIRandomAccessFile
- Throws:
java.lang.UnsupportedOperationException
- See Also:
DataOutput.writeUTF(String)
-
-