Package ch.systemsx.cisd.base.io
Class RandomAccessFileImpl
- java.lang.Object
-
- ch.systemsx.cisd.base.io.RandomAccessFileImpl
-
- All Implemented Interfaces:
IInputStream
,IOutputStream
,IRandomAccessFile
,ISynchronizable
,java.io.Closeable
,java.io.DataInput
,java.io.DataOutput
,java.lang.AutoCloseable
public class RandomAccessFileImpl extends java.lang.Object implements IRandomAccessFile
The file implementation ofIRandomAccessFile
.
-
-
Constructor Summary
Constructors Constructor Description RandomAccessFileImpl(java.io.File file, java.lang.String mode)
RandomAccessFileImpl(java.io.RandomAccessFile randomAccessFile)
RandomAccessFileImpl(java.lang.String name, java.lang.String mode)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
boolean
equals(java.lang.Object obj)
void
flush()
java.nio.ByteOrder
getByteOrder()
Gets the byte-order (endiness) of the random access file.java.nio.channels.FileChannel
getChannel()
java.io.FileDescriptor
getFD()
long
getFilePointer()
Returns the current offset in this file.int
hashCode()
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.java.lang.String
toString()
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
-
RandomAccessFileImpl
public RandomAccessFileImpl(java.io.RandomAccessFile randomAccessFile)
-
RandomAccessFileImpl
public RandomAccessFileImpl(java.lang.String name, java.lang.String mode) throws IOExceptionUnchecked
- Throws:
IOExceptionUnchecked
-
RandomAccessFileImpl
public RandomAccessFileImpl(java.io.File file, java.lang.String mode) throws IOExceptionUnchecked
- Throws:
IOExceptionUnchecked
-
-
Method Detail
-
getFD
public final java.io.FileDescriptor getFD() throws java.io.IOException
- Throws:
java.io.IOException
-
getChannel
public final java.nio.channels.FileChannel getChannel()
-
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
-
read
public int read() throws IOExceptionUnchecked
- Specified by:
read
in interfaceIInputStream
- Throws:
IOExceptionUnchecked
- See Also:
InputStream.read()
-
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)
-
read
public int read(byte[] b) throws IOExceptionUnchecked
- Specified by:
read
in interfaceIInputStream
- Throws:
IOExceptionUnchecked
- See Also:
InputStream.read(byte[])
-
readFully
public final 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 final 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)
-
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)
-
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
-
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()
-
readBoolean
public final boolean readBoolean() throws IOExceptionUnchecked
- Specified by:
readBoolean
in interfacejava.io.DataInput
- Specified by:
readBoolean
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readBoolean()
-
readByte
public final byte readByte() throws IOExceptionUnchecked
- Specified by:
readByte
in interfacejava.io.DataInput
- Specified by:
readByte
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readByte()
-
readUnsignedByte
public final int readUnsignedByte() throws IOExceptionUnchecked
- Specified by:
readUnsignedByte
in interfacejava.io.DataInput
- Specified by:
readUnsignedByte
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readUnsignedByte()
-
readShort
public final short readShort() throws IOExceptionUnchecked
- Specified by:
readShort
in interfacejava.io.DataInput
- Specified by:
readShort
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readShort()
-
readUnsignedShort
public final int readUnsignedShort() throws IOExceptionUnchecked
- Specified by:
readUnsignedShort
in interfacejava.io.DataInput
- Specified by:
readUnsignedShort
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readUnsignedShort()
-
readChar
public final char readChar() throws IOExceptionUnchecked
- Specified by:
readChar
in interfacejava.io.DataInput
- Specified by:
readChar
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readChar()
-
readInt
public final int readInt() throws IOExceptionUnchecked
- Specified by:
readInt
in interfacejava.io.DataInput
- Specified by:
readInt
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readInt()
-
readLong
public final long readLong() throws IOExceptionUnchecked
- Specified by:
readLong
in interfacejava.io.DataInput
- Specified by:
readLong
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readLong()
-
readFloat
public final float readFloat() throws IOExceptionUnchecked
- Specified by:
readFloat
in interfacejava.io.DataInput
- Specified by:
readFloat
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readFloat()
-
readDouble
public final double readDouble() throws IOExceptionUnchecked
- Specified by:
readDouble
in interfacejava.io.DataInput
- Specified by:
readDouble
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readDouble()
-
readLine
public final java.lang.String readLine() throws IOExceptionUnchecked
- Specified by:
readLine
in interfacejava.io.DataInput
- Specified by:
readLine
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readLine()
-
readUTF
public final java.lang.String readUTF() throws IOExceptionUnchecked
- Specified by:
readUTF
in interfacejava.io.DataInput
- Specified by:
readUTF
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataInput.readUTF()
-
writeBoolean
public final 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 final 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 final 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 final 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 final 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 final 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 final 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 final 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 final 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 final 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 final void writeUTF(java.lang.String str) throws IOExceptionUnchecked
- Specified by:
writeUTF
in interfacejava.io.DataOutput
- Specified by:
writeUTF
in interfaceIRandomAccessFile
- Throws:
IOExceptionUnchecked
- See Also:
DataOutput.writeUTF(String)
-
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()
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-