Class RamFileRandomAccessContent
- All Implemented Interfaces:
Closeable,DataInput,DataOutput,AutoCloseable,RandomAccessContent
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]Bufferprivate final byte[]bufferprivate final byte[]bufferprivate final byte[]bufferprivate final byte[]bufferprivate static final intprivate final RamFileObjectFileprotected intFile Pointerprivate final InputStream -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this random access file stream and releases any system resources associated with the stream.longReturns the current offset in this file.Get the input stream.private intlonglength()Returns the length of this file.booleanbytereadByte()charreadChar()doublefloatvoidreadFully(byte[] b) voidreadFully(byte[] b, int off, int len) intreadInt()readLine()longreadLong()shortintintreadUTF()voidseek(long pos) Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.voidsetLength(long newLength) Sets the length of this content.intskipBytes(int n) static byte[]toBytes(long n, byte[] b) Build a 8-byte array from a long.static longtoLong(byte[] b) Build a long from first 8 bytes of the array.static shorttoShort(byte[] b) Build a short from first 2 bytes of the array.static inttoUnsignedShort(byte[] b) Build a short from first 2 bytes of the array.voidwrite(byte[] b) voidwrite(byte[] b, int off, int len) voidwrite(int b) voidwriteBoolean(boolean v) voidwriteByte(int i) voidwriteBytes(String s) voidwriteChar(int v) voidwriteChars(String s) voidwriteDouble(double v) voidwriteFloat(float v) voidwriteInt(int v) voidwriteLong(long v) voidwriteShort(int v) void
-
Field Details
-
filePointer
protected int filePointerFile Pointer -
buf
private byte[] bufBuffer -
buffer8
private final byte[] buffer8buffer -
buffer4
private final byte[] buffer4buffer -
buffer2
private final byte[] buffer2buffer -
buffer1
private final byte[] buffer1buffer -
file
File -
rafis
-
BYTE_VALUE_MASK
private static final int BYTE_VALUE_MASK- See Also:
-
-
Constructor Details
-
RamFileRandomAccessContent
- Parameters:
file- The file to access.mode- The access mode.
-
-
Method Details
-
getFilePointer
Description copied from interface:RandomAccessContentReturns the current offset in this file.- Specified by:
getFilePointerin 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.
-
seek
Description copied from interface:RandomAccessContentSets 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:
seekin interfaceRandomAccessContent- Parameters:
pos- the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.- Throws:
IOException- ifposis less than0or if an I/O error occurs.
-
length
Description copied from interface:RandomAccessContentReturns the length of this file.- Specified by:
lengthin interfaceRandomAccessContent- Returns:
- the length of this file, measured in bytes.
- Throws:
IOException- if an I/O error occurs.
-
close
Description copied from interface:RandomAccessContentCloses 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceRandomAccessContent- Throws:
IOException- if an I/O error occurs.
-
readByte
- Specified by:
readBytein interfaceDataInput- Throws:
IOException
-
readChar
- Specified by:
readCharin interfaceDataInput- Throws:
IOException
-
readDouble
- Specified by:
readDoublein interfaceDataInput- Throws:
IOException
-
readFloat
- Specified by:
readFloatin interfaceDataInput- Throws:
IOException
-
readInt
- Specified by:
readIntin interfaceDataInput- Throws:
IOException
-
readUnsignedByte
- Specified by:
readUnsignedBytein interfaceDataInput- Throws:
IOException
-
readUnsignedShort
- Specified by:
readUnsignedShortin interfaceDataInput- Throws:
IOException
-
readLong
- Specified by:
readLongin interfaceDataInput- Throws:
IOException
-
readShort
- Specified by:
readShortin interfaceDataInput- Throws:
IOException
-
readBoolean
- Specified by:
readBooleanin interfaceDataInput- Throws:
IOException
-
skipBytes
- Specified by:
skipBytesin interfaceDataInput- Throws:
IOException
-
readFully
- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
readFully
- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
getLeftBytes
private int getLeftBytes() -
readUTF
- Specified by:
readUTFin interfaceDataInput- Throws:
IOException
-
write
- Specified by:
writein interfaceDataOutput- Throws:
IOException
-
write
- Specified by:
writein interfaceDataOutput- Throws:
IOException
-
writeByte
- Specified by:
writeBytein interfaceDataOutput- Throws:
IOException
-
toLong
public static long toLong(byte[] b) Build a long from first 8 bytes of the array.- Parameters:
b- The byte[] to convert.- Returns:
- A long.
-
toBytes
public static byte[] toBytes(long n, byte[] b) Build a 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[].
-
toShort
public static short toShort(byte[] b) Build a short from first 2 bytes of the array.- Parameters:
b- The byte[] to convert.- Returns:
- A short.
-
toUnsignedShort
public static int toUnsignedShort(byte[] b) Build a short from first 2 bytes of the array.- Parameters:
b- The byte[] to convert.- Returns:
- A short.
-
write
- Specified by:
writein interfaceDataOutput- Throws:
IOException
-
writeBoolean
- Specified by:
writeBooleanin 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
-
readLine
- Specified by:
readLinein interfaceDataInput- Throws:
IOException
-
getInputStream
Description copied from interface:RandomAccessContentGet the input stream.Notice: If you use
RandomAccessContent.seek(long)you have to re-get the InputStream- Specified by:
getInputStreamin interfaceRandomAccessContent- Returns:
- the InputStream.
- Throws:
IOException- if an I/O error occurs.
-
setLength
Description copied from interface:RandomAccessContentSets the length of this content.If the the
newLengthargument is smaller thanRandomAccessContent.length(), the content is truncated.If the the
newLengthargument is greater thanRandomAccessContent.length(), the content grows with undefined data.- Specified by:
setLengthin interfaceRandomAccessContent- Parameters:
newLength- The desired content length- Throws:
IOException- If an I/O error occurs
-