Class RandomAccessFileImpl
- java.lang.Object
-
- de.bernd_michaely.common.io.random.RandomAccessFileImpl
-
- All Implemented Interfaces:
RandomAccessData,AutoCloseable
public class RandomAccessFileImpl extends Object implements RandomAccessData
This class is aRandomAccessFilebased implementation of theRandomAccessDatainterface.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()longgetCurrentOffset()Returns the current offset within this data.longgetLength()Returns the length of the data in bytes.booleanisClosed()Returns true, if the data source was closed before.voidreadBytes(byte[] buffer, int offset, int length)Reads an array of bytes of the given length from this data source into the given buffer at the given offset.byte[]readBytes(int length)Reads an array of bytes of the given length from this data source.intreadUnsignedByte()Reads an unsigned eight bit number from this data.voidsetCurrentOffset(long offset)Sets the current offset within this data.
-
-
-
Method Detail
-
isClosed
public boolean isClosed()
Description copied from interface:RandomAccessDataReturns true, if the data source was closed before.- Specified by:
isClosedin interfaceRandomAccessData- Returns:
- true, if the data source was closed
-
close
public void close() throws RandomAccessDataException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceRandomAccessData- Throws:
RandomAccessDataException
-
getLength
public long getLength() throws RandomAccessDataExceptionDescription copied from interface:RandomAccessDataReturns the length of the data in bytes.- Specified by:
getLengthin interfaceRandomAccessData- Returns:
- the length of the data in bytes
- Throws:
RandomAccessDataException- if RandomAccessData source is invalid
-
getCurrentOffset
public long getCurrentOffset() throws RandomAccessDataExceptionDescription copied from interface:RandomAccessDataReturns the current offset within this data.- Specified by:
getCurrentOffsetin interfaceRandomAccessData- Returns:
- offset in bytes
- Throws:
RandomAccessDataException- if RandomAccessData source is invalid
-
setCurrentOffset
public void setCurrentOffset(long offset) throws RandomAccessDataExceptionDescription copied from interface:RandomAccessDataSets the current offset within this data. The offset may be set beyond the end of the file without throwing an exception. (Reading after that will do so.)- Specified by:
setCurrentOffsetin interfaceRandomAccessData- Parameters:
offset- offset in bytes- Throws:
RandomAccessDataException- if an I/O error occurs
-
readUnsignedByte
public int readUnsignedByte() throws RandomAccessDataExceptionDescription copied from interface:RandomAccessDataReads an unsigned eight bit number from this data.- Specified by:
readUnsignedBytein interfaceRandomAccessData- Returns:
- the next byte of this file as an unsigned eight bit number
- Throws:
RandomAccessDataException- if an I/O error occursRandomAccessEndOfDataException- if the end of data is reached
-
readBytes
public byte[] readBytes(int length) throws RandomAccessDataExceptionDescription copied from interface:RandomAccessDataReads an array of bytes of the given length from this data source.- Specified by:
readBytesin interfaceRandomAccessData- Parameters:
length- the number of bytes to read- Returns:
- the bytes read as byte array
- Throws:
RandomAccessDataException- if an I/O error occursRandomAccessEndOfDataException- if the end of data is reached
-
readBytes
public void readBytes(byte[] buffer, int offset, int length) throws RandomAccessDataExceptionDescription copied from interface:RandomAccessDataReads an array of bytes of the given length from this data source into the given buffer at the given offset. The caller is responsible to provide a buffer of sufficient size.- Specified by:
readBytesin interfaceRandomAccessData- Parameters:
buffer- the buffer to write the read data tooffset- starting index to write the data read into the bufferlength- the number of bytes to read- Throws:
RandomAccessDataException- if an I/O error occursRandomAccessEndOfDataException- if the end of data is reached- See Also:
RandomAccessData.readBytes(int)
-
-