|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.entityfs.util.io.RandomAccessToDataInputOutputAdapter
public class RandomAccessToDataInputOutputAdapter
This object adapts any RandomAccess
implementation to implement the
DataInput
and DataOutput
interfaces.
Methods defined in the DataInput
and DataOutput
interfaces
throw IOException
:s on errors. Methods defined in the
RandomAccess
interface throw WrappedIOException
:s.
The static fromModifiedUtf8(byte[])
and
toModifiedUtf(String)
can be used to convert strings from and to the
modified UTF-8 data format defined in the DataInput
interface.
Constructor Summary | |
---|---|
RandomAccessToDataInputOutputAdapter(RandomAccess adapted)
|
Method Summary | |
---|---|
void |
addCloseObserver(RandomAccessCloseObserver obs)
Add an observer that is notified when this RandomAccess is
closed. |
int |
available()
Returns an estimate of the number of bytes that can be read from this data source without blocking by the next invocation of a method for this data source. |
void |
close()
Close the sink and free all resources associated with it. |
protected void |
finalize()
|
void |
flush()
Flush changes made to the sink to the underlying storage. |
static String |
fromModifiedUtf8(byte[] barr)
Interpret the supplied byte array as modified UTF-8 data as described in the DataInput interface. |
long |
getFilePointer()
Get the current offset in the file. |
RandomAccessMode |
getMode()
Get the mode that this RandomAccess was opened in. |
long |
length()
Get the file's current length. |
int |
read()
Read a byte of data from the source. |
int |
read(byte[] barr)
Read up to b.length bytes of data from the source into the array. |
int |
read(byte[] barr,
int offset,
int len)
Read up to len bytes of data from the source into the array. |
boolean |
readBoolean()
|
byte |
readByte()
|
char |
readChar()
|
double |
readDouble()
|
float |
readFloat()
|
void |
readFully(byte[] barr)
|
void |
readFully(byte[] barr,
int offset,
int len)
|
int |
readInt()
|
String |
readLine()
|
long |
readLong()
|
short |
readShort()
|
int |
readUnsignedByte()
|
int |
readUnsignedShort()
|
String |
readUTF()
|
void |
seek(long pos)
Set the file pointer offset, measured from the beginning of the file. |
void |
setLength(long newlen)
Set the length of the file. |
int |
skipBytes(int no)
|
long |
skipBytes(long n)
Attempt to skip over n bytes in the source. |
static byte[] |
toModifiedUtf(String s)
Convert the supplied string to the modified UTF-8 format described in DataInput . |
void |
write(byte[] barr)
Write the contents of the array to the sink, starting at the current file pointer. |
void |
write(byte[] barr,
int offset,
int len)
Write len bytes from the array, starting at the offset off to this sink. |
void |
write(int b)
Write a byte to the sink. |
void |
writeBoolean(boolean b)
|
void |
writeByte(int v)
|
void |
writeBytes(String s)
|
void |
writeChar(int v)
|
void |
writeChars(String s)
|
void |
writeDouble(double d)
|
void |
writeFloat(float f)
|
void |
writeInt(int i)
|
void |
writeLong(long l)
|
void |
writeShort(int v)
|
void |
writeUTF(String s)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public RandomAccessToDataInputOutputAdapter(RandomAccess adapted)
Method Detail |
---|
public boolean readBoolean() throws IOException
readBoolean
in interface DataInput
IOException
public void writeBoolean(boolean b) throws IOException
writeBoolean
in interface DataOutput
IOException
public byte readByte() throws IOException
readByte
in interface DataInput
IOException
public int readUnsignedByte() throws IOException
readUnsignedByte
in interface DataInput
IOException
public void writeByte(int v) throws IOException
writeByte
in interface DataOutput
IOException
public void writeBytes(String s) throws IOException
writeBytes
in interface DataOutput
IOException
public char readChar() throws IOException
readChar
in interface DataInput
IOException
public void writeChar(int v) throws IOException
writeChar
in interface DataOutput
IOException
public void writeChars(String s) throws IOException
writeChars
in interface DataOutput
IOException
public double readDouble() throws IOException
readDouble
in interface DataInput
IOException
public void writeDouble(double d) throws IOException
writeDouble
in interface DataOutput
IOException
public long readLong() throws IOException
readLong
in interface DataInput
IOException
public void writeLong(long l) throws IOException
writeLong
in interface DataOutput
IOException
public float readFloat() throws IOException
readFloat
in interface DataInput
IOException
public void writeFloat(float f) throws IOException
writeFloat
in interface DataOutput
IOException
public int readInt() throws IOException
readInt
in interface DataInput
IOException
public void writeInt(int i) throws IOException
writeInt
in interface DataOutput
IOException
public short readShort() throws IOException
readShort
in interface DataInput
IOException
public void writeShort(int v) throws IOException
writeShort
in interface DataOutput
IOException
public int readUnsignedShort() throws IOException
readUnsignedShort
in interface DataInput
IOException
public void readFully(byte[] barr) throws IOException
readFully
in interface DataInput
IOException
public void readFully(byte[] barr, int offset, int len) throws IOException
readFully
in interface DataInput
IOException
public int skipBytes(int no) throws IOException
skipBytes
in interface DataInput
no
- Number of bytes to skip. No bytes are skipped if no
is
negative.
IOException
public String readLine()
readLine
in interface DataInput
public static String fromModifiedUtf8(byte[] barr) throws UTFDataFormatException
DataInput
interface.
barr
- The modified UTF-8 data.
UTFDataFormatException
- If the byte array cannot be interpreted as
a UTF-8 string.public String readUTF() throws IOException
readUTF
in interface DataInput
IOException
public static byte[] toModifiedUtf(String s) throws UTFDataFormatException
DataInput
.
s
- The string to convert.
UTFDataFormatException
- If the supplied string cannot be converted
to a byte array that is shorter than 65535 bytes.public void writeUTF(String s) throws IOException
writeUTF
in interface DataOutput
IOException
public RandomAccessMode getMode()
RandomAccess
RandomAccess
was opened in.
This method does not throw an IllegalStateException
if it is
called after the RandomAccess
has been closed.
getMode
in interface RandomAccess
RandomAccess
was opened in.public long getFilePointer() throws WrappedIOException
RandomAccess
getFilePointer
in interface RandomAccess
WrappedIOException
public void write(int b) throws WrappedIOException
DataSink
write
in interface DataOutput
write
in interface DataSink
b
- The byte to write.
WrappedIOException
- On I/O errors.public void write(byte[] barr) throws WrappedIOException
DataSink
write
in interface DataOutput
write
in interface DataSink
barr
- The array to write.
WrappedIOException
- On I/O errors.public void write(byte[] barr, int offset, int len) throws WrappedIOException
DataSink
len
bytes from the array, starting at the offset off
to this sink.
write
in interface DataOutput
write
in interface DataSink
barr
- The byte array.offset
- The starting offset in the array.len
- The number of bytes to write.
WrappedIOException
- On I/O errors.public void flush() throws WrappedIOException
DataSink
ReadOnlyException
.
flush
in interface DataSink
WrappedIOException
- On I/O errors.public int read() throws WrappedIOException
DataSource
0x00-0x0ff
).
read
in interface DataSource
-1
if the end of the source has
been reached.
WrappedIOException
- On I/O errors.public int read(byte[] barr) throws WrappedIOException
DataSource
b.length
bytes of data from the source into the array.
read
in interface DataSource
barr
- The byte array into which data is read.
-1
if
no data could be read because the the end of the source was reached
before the read started.
WrappedIOException
- On I/O errors.public int read(byte[] barr, int offset, int len) throws WrappedIOException
DataSource
len
bytes of data from the source into the array.
read
in interface DataSource
barr
- The byte array into which data is read.offset
- The start offset in the array b
at which data is
written.len
- The maximum number of bytes to read.
-1
if
no data could be read because the end of the source was reached before
the read started.
WrappedIOException
- On I/O errors.public void close() throws WrappedIOException
DataSink
close
in interface DataSink
close
in interface DataSource
WrappedIOException
- On I/O errors.public void addCloseObserver(RandomAccessCloseObserver obs)
RandomAccess
RandomAccess
is
closed. The observers are called just after the RandomAccess
has
been closed.
addCloseObserver
in interface RandomAccess
obs
- The observer.protected void finalize() throws Throwable
finalize
in class Object
Throwable
public int available() throws WrappedIOException
DataSource
available
in interface DataSource
WrappedIOException
- On I/O errors.InputStream.available()
public long length() throws WrappedIOException
RandomAccess
length
in interface RandomAccess
WrappedIOException
public void setLength(long newlen) throws WrappedIOException
RandomAccess
If the present length of the file is greater than the l
argument,
the file will be truncated.
If the new length is bigger than the current length of the file, the file will be extended. The contents of the extended portion of the file are not defined.
The current file pointer is not changed, unless the file pointer offset is greater than the new file length. If so, it will be set to the new length.
setLength
in interface RandomAccess
newlen
- The new length of the file.
WrappedIOException
public void seek(long pos) throws WrappedIOException
RandomAccess
seek
in interface RandomAccess
pos
- The new file pointer offset, measured from the beginning of
the file.
WrappedIOException
DataSource.skipBytes(long)
public long skipBytes(long n) throws WrappedIOException
DataSource
n
bytes in the source. If n
is
negative, no bytes are skipped.
The pointer in the source cannot be moved beyond EOF using this method
(unlike RandomAccess.seek(long)
).
skipBytes
in interface DataSource
n
- The number of bytes to increment the source pointer with.
WrappedIOException
RandomAccess.seek(long)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |