Class RamFileRandomAccessContent
- java.lang.Object
-
- org.apache.commons.vfs2.provider.ram.RamFileRandomAccessContent
-
- All Implemented Interfaces:
java.io.Closeable,java.io.DataInput,java.io.DataOutput,java.lang.AutoCloseable,RandomAccessContent
public class RamFileRandomAccessContent extends java.lang.Object implements RandomAccessContent
RAM File Random Access Content.
-
-
Field Summary
Fields Modifier and Type Field Description protected intfilePointerFile Pointer
-
Constructor Summary
Constructors Constructor Description RamFileRandomAccessContent(RamFileObject file, RandomAccessMode mode)Constructs a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this random access file stream and releases any system resources associated with the stream.longgetFilePointer()Returns the current offset in this file.java.io.InputStreamgetInputStream()Gets the input stream.longlength()Returns the length of this file.booleanreadBoolean()bytereadByte()charreadChar()doublereadDouble()floatreadFloat()voidreadFully(byte[] b)voidreadFully(byte[] b, int off, int len)intreadInt()java.lang.StringreadLine()longreadLong()shortreadShort()intreadUnsignedByte()intreadUnsignedShort()java.lang.StringreadUTF()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 an 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(java.lang.String s)voidwriteChar(int v)voidwriteChars(java.lang.String s)voidwriteDouble(double v)voidwriteFloat(float v)voidwriteInt(int v)voidwriteLong(long v)voidwriteShort(int v)voidwriteUTF(java.lang.String str)
-
-
-
Field Detail
-
filePointer
protected int filePointer
File Pointer
-
-
Constructor Detail
-
RamFileRandomAccessContent
public RamFileRandomAccessContent(RamFileObject file, RandomAccessMode mode)
Constructs a new instance.- Parameters:
file- The file to access.mode- The access mode.
-
-
Method Detail
-
toBytes
public static byte[] toBytes(long n, byte[] b)
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
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.
-
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.
-
close
public void close() throws java.io.IOException
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 interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceRandomAccessContent- Throws:
java.io.IOException- if an I/O error occurs.
-
getFilePointer
public long getFilePointer() throws java.io.IOException
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:
java.io.IOException- if an I/O error occurs.
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOException
Description copied from interface:RandomAccessContentGets 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:
java.io.IOException- if an I/O error occurs.
-
length
public long length() throws java.io.IOException
Description copied from interface:RandomAccessContentReturns the length of this file.- Specified by:
lengthin interfaceRandomAccessContent- Returns:
- the length of this file, measured in bytes.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readBoolean
public boolean readBoolean() throws java.io.IOException
- Specified by:
readBooleanin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readByte
public byte readByte() throws java.io.IOException
- Specified by:
readBytein interfacejava.io.DataInput- Throws:
java.io.IOException
-
readChar
public char readChar() throws java.io.IOException
- Specified by:
readCharin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readDouble
public double readDouble() throws java.io.IOException
- Specified by:
readDoublein interfacejava.io.DataInput- Throws:
java.io.IOException
-
readFloat
public float readFloat() throws java.io.IOException
- Specified by:
readFloatin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readFully
public void readFully(byte[] b) throws java.io.IOException
- Specified by:
readFullyin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readFully
public void readFully(byte[] b, int off, int len) throws java.io.IOException
- Specified by:
readFullyin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readInt
public int readInt() throws java.io.IOException
- Specified by:
readIntin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readLine
public java.lang.String readLine() throws java.io.IOException
- Specified by:
readLinein interfacejava.io.DataInput- Throws:
java.io.IOException
-
readLong
public long readLong() throws java.io.IOException
- Specified by:
readLongin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readShort
public short readShort() throws java.io.IOException
- Specified by:
readShortin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readUnsignedByte
public int readUnsignedByte() throws java.io.IOException
- Specified by:
readUnsignedBytein interfacejava.io.DataInput- Throws:
java.io.IOException
-
readUnsignedShort
public int readUnsignedShort() throws java.io.IOException
- Specified by:
readUnsignedShortin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readUTF
public java.lang.String readUTF() throws java.io.IOException
- Specified by:
readUTFin interfacejava.io.DataInput- Throws:
java.io.IOException
-
seek
public void seek(long pos) throws java.io.IOException
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:
java.io.IOException- ifposis less than0or if an I/O error occurs.
-
setLength
public void setLength(long newLength) throws java.io.IOException
Description copied from interface:RandomAccessContentSets the length of this content.If the
newLengthargument is smaller thanRandomAccessContent.length(), the content is truncated.If the
newLengthargument is greater thanRandomAccessContent.length(), the content grows with undefined data.- Specified by:
setLengthin interfaceRandomAccessContent- Parameters:
newLength- The desired content length- Throws:
java.io.IOException- If an I/O error occurs
-
skipBytes
public int skipBytes(int n) throws java.io.IOException
- Specified by:
skipBytesin interfacejava.io.DataInput- Throws:
java.io.IOException
-
write
public void write(byte[] b) throws java.io.IOException
- Specified by:
writein interfacejava.io.DataOutput- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
- Specified by:
writein interfacejava.io.DataOutput- Throws:
java.io.IOException
-
write
public void write(int b) throws java.io.IOException
- Specified by:
writein interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeBoolean
public void writeBoolean(boolean v) throws java.io.IOException
- Specified by:
writeBooleanin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeByte
public void writeByte(int i) throws java.io.IOException
- Specified by:
writeBytein interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeBytes
public void writeBytes(java.lang.String s) throws java.io.IOException
- Specified by:
writeBytesin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeChar
public void writeChar(int v) throws java.io.IOException
- Specified by:
writeCharin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeChars
public void writeChars(java.lang.String s) throws java.io.IOException
- Specified by:
writeCharsin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeDouble
public void writeDouble(double v) throws java.io.IOException
- Specified by:
writeDoublein interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeFloat
public void writeFloat(float v) throws java.io.IOException
- Specified by:
writeFloatin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeInt
public void writeInt(int v) throws java.io.IOException
- Specified by:
writeIntin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeLong
public void writeLong(long v) throws java.io.IOException
- Specified by:
writeLongin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeShort
public void writeShort(int v) throws java.io.IOException
- Specified by:
writeShortin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeUTF
public void writeUTF(java.lang.String str) throws java.io.IOException
- Specified by:
writeUTFin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
-