Class RamFileRandomAccessContent
- java.lang.Object
-
- org.apache.commons.vfs2.provider.ram.RamFileRandomAccessContent
-
- All Implemented Interfaces:
java.io.DataInput
,java.io.DataOutput
,RandomAccessContent
public class RamFileRandomAccessContent extends java.lang.Object implements RandomAccessContent
RAM File Random Access Content.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
filePointer
File Pointer
-
Constructor Summary
Constructors Constructor Description RamFileRandomAccessContent(RamFileObject file, RandomAccessMode mode)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes this random access file stream and releases any system resources associated with the stream.long
getFilePointer()
Returns the current offset in this file.java.io.InputStream
getInputStream()
Get the input stream.long
length()
Returns the length of this file.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
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 a 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(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)
-
-
-
Field Detail
-
filePointer
protected int filePointer
File Pointer
-
-
Constructor Detail
-
RamFileRandomAccessContent
public RamFileRandomAccessContent(RamFileObject file, RandomAccessMode mode)
- Parameters:
file
- The file to access.mode
- The access mode.
-
-
Method Detail
-
getFilePointer
public long getFilePointer() throws java.io.IOException
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:
java.io.IOException
- if an I/O error occurs.
-
seek
public void seek(long pos) throws java.io.IOException
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:
java.io.IOException
- ifpos
is less than0
or if an I/O error occurs.
-
length
public long length() throws java.io.IOException
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:
java.io.IOException
- if an I/O error occurs.
-
close
public void close() throws java.io.IOException
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 interfaceRandomAccessContent
- Throws:
java.io.IOException
- if an I/O error occurs.
-
readByte
public byte readByte() throws java.io.IOException
- Specified by:
readByte
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readChar
public char readChar() throws java.io.IOException
- Specified by:
readChar
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readDouble
public double readDouble() throws java.io.IOException
- Specified by:
readDouble
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readFloat
public float readFloat() throws java.io.IOException
- Specified by:
readFloat
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readInt
public int readInt() throws java.io.IOException
- Specified by:
readInt
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readUnsignedByte
public int readUnsignedByte() throws java.io.IOException
- Specified by:
readUnsignedByte
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readUnsignedShort
public int readUnsignedShort() throws java.io.IOException
- Specified by:
readUnsignedShort
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readLong
public long readLong() throws java.io.IOException
- Specified by:
readLong
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readShort
public short readShort() throws java.io.IOException
- Specified by:
readShort
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readBoolean
public boolean readBoolean() throws java.io.IOException
- Specified by:
readBoolean
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
skipBytes
public int skipBytes(int n) throws java.io.IOException
- Specified by:
skipBytes
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readFully
public void readFully(byte[] b) throws java.io.IOException
- Specified by:
readFully
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readFully
public void readFully(byte[] b, int off, int len) throws java.io.IOException
- Specified by:
readFully
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readUTF
public java.lang.String readUTF() throws java.io.IOException
- Specified by:
readUTF
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
- Specified by:
write
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
-
write
public void write(byte[] b) throws java.io.IOException
- Specified by:
write
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
-
writeByte
public void writeByte(int i) throws java.io.IOException
- Specified by:
writeByte
in interfacejava.io.DataOutput
- Throws:
java.io.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
public void write(int b) throws java.io.IOException
- Specified by:
write
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
-
writeBoolean
public void writeBoolean(boolean v) throws java.io.IOException
- Specified by:
writeBoolean
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
-
writeBytes
public void writeBytes(java.lang.String s) throws java.io.IOException
- Specified by:
writeBytes
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
-
writeChar
public void writeChar(int v) throws java.io.IOException
- Specified by:
writeChar
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
-
writeChars
public void writeChars(java.lang.String s) throws java.io.IOException
- Specified by:
writeChars
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
-
writeDouble
public void writeDouble(double v) throws java.io.IOException
- Specified by:
writeDouble
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
-
writeFloat
public void writeFloat(float v) throws java.io.IOException
- Specified by:
writeFloat
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
-
writeInt
public void writeInt(int v) throws java.io.IOException
- Specified by:
writeInt
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
-
writeLong
public void writeLong(long v) throws java.io.IOException
- Specified by:
writeLong
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
-
writeShort
public void writeShort(int v) throws java.io.IOException
- Specified by:
writeShort
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
-
writeUTF
public void writeUTF(java.lang.String str) throws java.io.IOException
- Specified by:
writeUTF
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
-
readLine
public java.lang.String readLine() throws java.io.IOException
- Specified by:
readLine
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOException
Description copied from interface:RandomAccessContent
Get 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:
java.io.IOException
- if an I/O error occurs.
-
setLength
public void setLength(long newLength) throws java.io.IOException
Description copied from interface:RandomAccessContent
Sets the length of this content.If the the
newLength
argument is smaller thanRandomAccessContent.length()
, the content is truncated.If the 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:
java.io.IOException
- If an I/O error occurs
-
-