Class LocalFileRandomAccessContent
- java.lang.Object
-
- org.apache.commons.vfs2.provider.AbstractRandomAccessContent
-
- org.apache.commons.vfs2.provider.local.LocalFileRandomAccessContent
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.DataInput
,java.io.DataOutput
,java.lang.AutoCloseable
,RandomAccessContent
final class LocalFileRandomAccessContent extends AbstractRandomAccessContent
ImplementsRandomAccessContent
for local files.
-
-
Field Summary
Fields Modifier and Type Field Description private static int
BYTE_VALUE_MASK
private java.io.RandomAccessFile
raf
private java.io.InputStream
rafis
-
Constructor Summary
Constructors Constructor Description LocalFileRandomAccessContent(java.io.File localFile, RandomAccessMode mode)
-
Method Summary
All 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()
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)
void
write(byte[] b)
void
write(byte[] b, int off, int len)
void
write(int b)
void
writeBoolean(boolean v)
void
writeByte(int v)
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)
-
Methods inherited from class org.apache.commons.vfs2.provider.AbstractRandomAccessContent
readLine
-
-
-
-
Field Detail
-
BYTE_VALUE_MASK
private static final int BYTE_VALUE_MASK
- See Also:
- Constant Field Values
-
raf
private final java.io.RandomAccessFile raf
-
rafis
private final java.io.InputStream rafis
-
-
Constructor Detail
-
LocalFileRandomAccessContent
LocalFileRandomAccessContent(java.io.File localFile, RandomAccessMode mode) throws FileSystemException
- Throws:
FileSystemException
-
-
Method Detail
-
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.
- Throws:
java.io.IOException
- if an I/O error occurs.
-
getFilePointer
public long getFilePointer() throws java.io.IOException
Description copied from interface:RandomAccessContent
Returns the current offset in this file.- 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:RandomAccessContent
Get the input stream.Notice: If you use
RandomAccessContent.seek(long)
you have to re-get the InputStream- 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:RandomAccessContent
Returns the length of this file.- 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
- Throws:
java.io.IOException
-
readByte
public byte readByte() throws java.io.IOException
- Throws:
java.io.IOException
-
readChar
public char readChar() throws java.io.IOException
- Throws:
java.io.IOException
-
readDouble
public double readDouble() throws java.io.IOException
- Throws:
java.io.IOException
-
readFloat
public float readFloat() throws java.io.IOException
- Throws:
java.io.IOException
-
readFully
public void readFully(byte[] b) throws java.io.IOException
- Throws:
java.io.IOException
-
readFully
public void readFully(byte[] b, int off, int len) throws java.io.IOException
- Throws:
java.io.IOException
-
readInt
public int readInt() throws java.io.IOException
- Throws:
java.io.IOException
-
readLong
public long readLong() throws java.io.IOException
- Throws:
java.io.IOException
-
readShort
public short readShort() throws java.io.IOException
- Throws:
java.io.IOException
-
readUnsignedByte
public int readUnsignedByte() throws java.io.IOException
- Throws:
java.io.IOException
-
readUnsignedShort
public int readUnsignedShort() throws java.io.IOException
- Throws:
java.io.IOException
-
readUTF
public java.lang.String readUTF() throws java.io.IOException
- Throws:
java.io.IOException
-
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)
- 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.
-
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.- 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
- Throws:
java.io.IOException
-
write
public void write(byte[] b) throws java.io.IOException
- Specified by:
write
in interfacejava.io.DataOutput
- Overrides:
write
in classAbstractRandomAccessContent
- 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
- Overrides:
write
in classAbstractRandomAccessContent
- Throws:
java.io.IOException
-
write
public void write(int b) throws java.io.IOException
- Specified by:
write
in interfacejava.io.DataOutput
- Overrides:
write
in classAbstractRandomAccessContent
- Throws:
java.io.IOException
-
writeBoolean
public void writeBoolean(boolean v) throws java.io.IOException
- Specified by:
writeBoolean
in interfacejava.io.DataOutput
- Overrides:
writeBoolean
in classAbstractRandomAccessContent
- Throws:
java.io.IOException
-
writeByte
public void writeByte(int v) throws java.io.IOException
- Specified by:
writeByte
in interfacejava.io.DataOutput
- Overrides:
writeByte
in classAbstractRandomAccessContent
- Throws:
java.io.IOException
-
writeBytes
public void writeBytes(java.lang.String s) throws java.io.IOException
- Specified by:
writeBytes
in interfacejava.io.DataOutput
- Overrides:
writeBytes
in classAbstractRandomAccessContent
- Throws:
java.io.IOException
-
writeChar
public void writeChar(int v) throws java.io.IOException
- Specified by:
writeChar
in interfacejava.io.DataOutput
- Overrides:
writeChar
in classAbstractRandomAccessContent
- Throws:
java.io.IOException
-
writeChars
public void writeChars(java.lang.String s) throws java.io.IOException
- Specified by:
writeChars
in interfacejava.io.DataOutput
- Overrides:
writeChars
in classAbstractRandomAccessContent
- Throws:
java.io.IOException
-
writeDouble
public void writeDouble(double v) throws java.io.IOException
- Specified by:
writeDouble
in interfacejava.io.DataOutput
- Overrides:
writeDouble
in classAbstractRandomAccessContent
- Throws:
java.io.IOException
-
writeFloat
public void writeFloat(float v) throws java.io.IOException
- Specified by:
writeFloat
in interfacejava.io.DataOutput
- Overrides:
writeFloat
in classAbstractRandomAccessContent
- Throws:
java.io.IOException
-
writeInt
public void writeInt(int v) throws java.io.IOException
- Specified by:
writeInt
in interfacejava.io.DataOutput
- Overrides:
writeInt
in classAbstractRandomAccessContent
- Throws:
java.io.IOException
-
writeLong
public void writeLong(long v) throws java.io.IOException
- Specified by:
writeLong
in interfacejava.io.DataOutput
- Overrides:
writeLong
in classAbstractRandomAccessContent
- Throws:
java.io.IOException
-
writeShort
public void writeShort(int v) throws java.io.IOException
- Specified by:
writeShort
in interfacejava.io.DataOutput
- Overrides:
writeShort
in classAbstractRandomAccessContent
- Throws:
java.io.IOException
-
writeUTF
public void writeUTF(java.lang.String str) throws java.io.IOException
- Specified by:
writeUTF
in interfacejava.io.DataOutput
- Overrides:
writeUTF
in classAbstractRandomAccessContent
- Throws:
java.io.IOException
-
-