|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.entityfs.util.io.InputStreamBackedRandomAccess
public class InputStreamBackedRandomAccess
This is a read only RandomAccess that reads its data from a backing
InputStream. Since input streams only can be read forwards, this
object discards and creates input streams as needed using a
ObjectFactory for InputStream:s.
The InputStreamBackedRandomAccess can be used to use a file in a file
system that does not support the FSCRandomAccessFiles capability as a
read only RandomAccess anyway. See also the
TempFileBackedRandomAccess class that supports writing and may be
faster if there are many random reads.
This object is not thread safe. Depending on the type of ObjectFactory used, it may be possible to make it thread safe by using an
appropriate synchronization strategy.
TempFileBackedRandomAccess| Constructor Summary | |
|---|---|
InputStreamBackedRandomAccess(ObjectFactory<? extends InputStream> isf)
Create a InputStreamBackedRandomAccess that is backed by the
input streams created by the supplied factory. |
|
InputStreamBackedRandomAccess(ObjectFactory<? extends InputStream> isf,
long fileLen)
Create a InputStreamBackedRandomAccess that is backed by the
input streams created by the supplied factory. |
|
| Method Summary | |
|---|---|
void |
addCloseObserver(RandomAccessCloseObserver raco)
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. |
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 off,
int len)
Read up to len bytes of data from the source into the array. |
void |
seek(long pos)
Set the file pointer offset, measured from the beginning of the file. |
void |
setLength(long l)
Set the length of the file. |
long |
skipBytes(long n)
Attempt to skip over n bytes in the source. |
void |
write(byte[] barr)
Write the contents of the array to the sink, starting at the current file pointer. |
void |
write(byte[] barr,
int off,
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public InputStreamBackedRandomAccess(ObjectFactory<? extends InputStream> isf)
InputStreamBackedRandomAccess that is backed by the
input streams created by the supplied factory.
If you know how much data that can be read from the backing streams, use
the InputStreamBackedRandomAccess(ObjectFactory, long)
constructor instead.
isf - A factory for input streams.
public InputStreamBackedRandomAccess(ObjectFactory<? extends InputStream> isf,
long fileLen)
InputStreamBackedRandomAccess that is backed by the
input streams created by the supplied factory.
isf - A factory for input streams.fileLen - The amount of data that can be read from the backing
streams. By setting this, the length() method does not have to
calculate the file length.| Method Detail |
|---|
public int available()
DataSource
available in interface DataSourceInputStream.available()public long getFilePointer()
RandomAccess
getFilePointer in interface RandomAccesspublic long length()
RandomAccess
length in interface RandomAccesspublic int read()
DataSource0x00-0x0ff).
read in interface DataSource-1 if the end of the source has
been reached.public int read(byte[] barr)
DataSourceb.length bytes of data from the source into the array.
read in interface DataSourcebarr - 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.
public int read(byte[] barr,
int off,
int len)
DataSourcelen bytes of data from the source into the array.
read in interface DataSourcebarr - The byte array into which data is read.off - 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.public void seek(long pos)
RandomAccess
seek in interface RandomAccesspos - The new file pointer offset, measured from the beginning of
the file.DataSource.skipBytes(long)
public void setLength(long l)
throws ReadOnlyException
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 RandomAccessl - The new length of the file.
ReadOnlyException - Always.public long skipBytes(long n)
DataSourcen 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 DataSourcen - The number of bytes to increment the source pointer with.
RandomAccess.seek(long)
public void write(byte[] barr)
throws ReadOnlyException
DataSink
write in interface DataSinkbarr - The array to write.
ReadOnlyException - Always.
public void write(byte[] barr,
int off,
int len)
throws ReadOnlyException
DataSinklen bytes from the array, starting at the offset off to this sink.
write in interface DataSinkbarr - The byte array.off - The starting offset in the array.len - The number of bytes to write.
ReadOnlyException - Always.
public void write(int b)
throws ReadOnlyException
DataSink
write in interface DataSinkb - The byte to write.
ReadOnlyException - Always.
public void flush()
throws ReadOnlyException
DataSinkReadOnlyException.
flush in interface DataSinkReadOnlyException - Always.public void close()
DataSink
close in interface DataSinkclose in interface DataSourcepublic void addCloseObserver(RandomAccessCloseObserver raco)
RandomAccessRandomAccess is
closed. The observers are called just after the RandomAccess has
been closed.
addCloseObserver in interface RandomAccessraco - The observer.public RandomAccessMode getMode()
RandomAccessRandomAccess was opened in.
This method does not throw an IllegalStateException if it is
called after the RandomAccess has been closed.
getMode in interface RandomAccessRandomAccess was opened in.
protected void finalize()
throws Throwable
finalize in class ObjectThrowable
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||