Class RamFileRandomAccessContent
- All Implemented Interfaces:
Closeable
,DataInput
,DataOutput
,AutoCloseable
,RandomAccessContent
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRamFileRandomAccessContent
(RamFileObject file, RandomAccessMode mode) Constructs a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this random access file stream and releases any system resources associated with the stream.long
Returns the current offset in this file.Gets the input stream.long
length()
Returns the length of this file.boolean
byte
readByte()
char
readChar()
double
float
void
readFully
(byte[] b) void
readFully
(byte[] b, int off, int len) int
readInt()
readLine()
long
readLong()
short
int
int
readUTF()
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
setLength
(long newLength) Sets the length of this content.int
skipBytes
(int n) static byte[]
toBytes
(long n, byte[] b) Build an 8-byte array from a long.static long
toLong
(byte[] b) Build a long from first 8 bytes of the array.static short
toShort
(byte[] b) Build a short from first 2 bytes of the array.static int
toUnsignedShort
(byte[] b) Build a short from first 2 bytes of the array.void
write
(byte[] b) void
write
(byte[] b, int off, int len) void
write
(int b) void
writeBoolean
(boolean v) void
writeByte
(int i) void
writeBytes
(String s) void
writeChar
(int v) void
writeChars
(String s) void
writeDouble
(double v) void
writeFloat
(float v) void
writeInt
(int v) void
writeLong
(long v) void
writeShort
(int v) void
-
Field Details
-
filePointer
File Pointer
-
-
Constructor Details
-
RamFileRandomAccessContent
Constructs a new instance.- Parameters:
file
- The file to access.mode
- The access mode.
-
-
Method Details
-
toBytes
Build an 8-byte array from a long. No check is performed on the array length.- Parameters:
n
- The number to convert.b
- The array to fill.- Returns:
- A byte[].
-
toLong
Build a long from first 8 bytes of the array.- Parameters:
b
- The byte[] to convert.- Returns:
- A long.
-
toShort
Build a short from first 2 bytes of the array.- Parameters:
b
- The byte[] to convert.- Returns:
- A short.
-
toUnsignedShort
Build a short from first 2 bytes of the array.- Parameters:
b
- The byte[] to convert.- Returns:
- A short.
-
close
Description copied from interface:RandomAccessContent
Closes this random access file stream and releases any system resources associated with the stream.A closed random access file cannot perform input or output operations and cannot be reopened.
If this file has an associated channel then the channel is closed as well.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceRandomAccessContent
- Throws:
IOException
- if an I/O error occurs.
-
getFilePointer
Description copied from interface:RandomAccessContent
Returns the current offset in this file.- Specified by:
getFilePointer
in interfaceRandomAccessContent
- Returns:
- the offset from the beginning of the file, in bytes, at which the next read or write occurs.
- Throws:
IOException
- if an I/O error occurs.
-
getInputStream
Description copied from interface:RandomAccessContent
Gets the input stream.Notice: If you use
RandomAccessContent.seek(long)
you have to re-get the InputStream- Specified by:
getInputStream
in interfaceRandomAccessContent
- Returns:
- the InputStream.
- Throws:
IOException
- if an I/O error occurs.
-
length
Description copied from interface:RandomAccessContent
Returns the length of this file.- Specified by:
length
in interfaceRandomAccessContent
- Returns:
- the length of this file, measured in bytes.
- Throws:
IOException
- if an I/O error occurs.
-
readBoolean
- Specified by:
readBoolean
in interfaceDataInput
- Throws:
IOException
-
readByte
- Specified by:
readByte
in interfaceDataInput
- Throws:
IOException
-
readChar
- Specified by:
readChar
in interfaceDataInput
- Throws:
IOException
-
readDouble
- Specified by:
readDouble
in interfaceDataInput
- Throws:
IOException
-
readFloat
- Specified by:
readFloat
in interfaceDataInput
- Throws:
IOException
-
readFully
- Specified by:
readFully
in interfaceDataInput
- Throws:
IOException
-
readFully
- Specified by:
readFully
in interfaceDataInput
- Throws:
IOException
-
readInt
- Specified by:
readInt
in interfaceDataInput
- Throws:
IOException
-
readLine
- Specified by:
readLine
in interfaceDataInput
- Throws:
IOException
-
readLong
- Specified by:
readLong
in interfaceDataInput
- Throws:
IOException
-
readShort
- Specified by:
readShort
in interfaceDataInput
- Throws:
IOException
-
readUnsignedByte
- Specified by:
readUnsignedByte
in interfaceDataInput
- Throws:
IOException
-
readUnsignedShort
- Specified by:
readUnsignedShort
in interfaceDataInput
- Throws:
IOException
-
readUTF
- Specified by:
readUTF
in interfaceDataInput
- Throws:
IOException
-
seek
Description copied from interface:RandomAccessContent
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.
Notice: If you use
RandomAccessContent.getInputStream()
you have to re-get the InputStream after callingRandomAccessContent.seek(long)
- Specified by:
seek
in interfaceRandomAccessContent
- Parameters:
pos
- the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.- Throws:
IOException
- ifpos
is less than0
or if an I/O error occurs.
-
setLength
Description copied from interface:RandomAccessContent
Sets the length of this content.If the
newLength
argument is smaller thanRandomAccessContent.length()
, the content is truncated.If the
newLength
argument is greater thanRandomAccessContent.length()
, the content grows with undefined data.- Specified by:
setLength
in interfaceRandomAccessContent
- Parameters:
newLength
- The desired content length- Throws:
IOException
- If an I/O error occurs
-
skipBytes
- Specified by:
skipBytes
in interfaceDataInput
- Throws:
IOException
-
write
- Specified by:
write
in interfaceDataOutput
- Throws:
IOException
-
write
- Specified by:
write
in interfaceDataOutput
- Throws:
IOException
-
write
- Specified by:
write
in interfaceDataOutput
- Throws:
IOException
-
writeBoolean
- Specified by:
writeBoolean
in interfaceDataOutput
- Throws:
IOException
-
writeByte
- Specified by:
writeByte
in interfaceDataOutput
- Throws:
IOException
-
writeBytes
- Specified by:
writeBytes
in interfaceDataOutput
- Throws:
IOException
-
writeChar
- Specified by:
writeChar
in interfaceDataOutput
- Throws:
IOException
-
writeChars
- Specified by:
writeChars
in interfaceDataOutput
- Throws:
IOException
-
writeDouble
- Specified by:
writeDouble
in interfaceDataOutput
- Throws:
IOException
-
writeFloat
- Specified by:
writeFloat
in interfaceDataOutput
- Throws:
IOException
-
writeInt
- Specified by:
writeInt
in interfaceDataOutput
- Throws:
IOException
-
writeLong
- Specified by:
writeLong
in interfaceDataOutput
- Throws:
IOException
-
writeShort
- Specified by:
writeShort
in interfaceDataOutput
- Throws:
IOException
-
writeUTF
- Specified by:
writeUTF
in interfaceDataOutput
- Throws:
IOException
-