|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.io.InputStream
it.unimi.dsi.fastutil.io.MeasurableInputStream
it.unimi.dsi.fastutil.io.InspectableFileCachedInputStream
public class InspectableFileCachedInputStream
A repositionable MeasurableInputStream based on
cached data received by a WritableByteChannel whose first bytes can be inspected directly.
An instance of this class acts as a buffer holding the bytes written through its
WritableByteChannel interface (which can be easily turned into an OutputStream using
Channels.newOutputStream(WritableByteChannel)). The data can be discarded at any time using
clear(). The first inspectable bytes of buffer contains the first
bytes written. When buffer is full, the bytes are written to an overflow
file.
At any time, the stream of bytes written since creation (or since the last clear())
are available as a fully implemented MeasurableInputStream which also implements
RepositionableStream and supports marking.
Note that you must arbitrate carefully write and read accesses,
as it is always possible to call write(ByteBuffer)
and thus modify the length of the MeasurableInputStream.
The method close() makes the MeasurableInputStream and WritableByteChannel state-changing methods temporarily throw an IOException, but
does not otherwise modify the state of the stream (i.e., the stream can be cleared again). The method dispose() can be used to release
the resources associated with the stream.
This class provides no form of buffering except for the memory buffer described above, both
when reading and when writing. Users should consider wrapping instances of this class with a
FastBufferedInputStream, as reads after the buffer has been exhausted will be performed
directly on a RandomAccessFile.
| Field Summary | |
|---|---|
byte[] |
buffer
The inspection buffer. |
static boolean |
DEBUG
|
static int |
DEFAULT_BUFFER_SIZE
The default buffer size (64KiB). |
int |
inspectable
The number of valid bytes currently in buffer. |
| Constructor Summary | |
|---|---|
InspectableFileCachedInputStream()
Creates a new instance with default buffer size and overflow-file directory. |
|
InspectableFileCachedInputStream(int bufferSize)
Creates a new instance with specified buffer size and default overflow-file directory. |
|
InspectableFileCachedInputStream(int bufferSize,
java.io.File overflowFile)
Creates a new instance with specified buffer size and overlow-file directory. |
|
| Method Summary | |
|---|---|
int |
available()
|
void |
clear()
Clears the content of this InspectableFileCachedInputStream, zeroing the length of the represented
stream. |
void |
close()
Makes the stream unreadable until the next clear(). |
void |
dispose()
Disposes this stream, deleting the overflow file. |
boolean |
isOpen()
|
long |
length()
Returns the overall length of this stream (optional operation). |
void |
mark(int readlimit)
|
boolean |
markSupported()
|
long |
position()
Returns the current stream position. |
void |
position(long position)
Positions the input stream. |
int |
read()
|
int |
read(byte[] b)
|
int |
read(byte[] b,
int offset,
int length)
|
void |
reset()
|
long |
skip(long n)
|
void |
truncate(long size)
Truncates the overflow file to a given size if possible. |
int |
write(java.nio.ByteBuffer byteBuffer)
Appends the content of a specified buffer to the end of the currently represented stream. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final boolean DEBUG
public static final int DEFAULT_BUFFER_SIZE
public final byte[] buffer
inspectable bytes contain the first part of the input stream.
The buffer is available for inspection, but users should not modify its content.
public int inspectable
buffer.
| Constructor Detail |
|---|
public InspectableFileCachedInputStream(int bufferSize,
java.io.File overflowFile)
throws java.io.IOException
bufferSize - the buffer size, in bytes.overflowFile - the directory where the overflow file should be created, or null for the default temporary directory.
java.io.IOException
public InspectableFileCachedInputStream(int bufferSize)
throws java.io.IOException
bufferSize - the buffer size, in bytes.
java.io.IOException
public InspectableFileCachedInputStream()
throws java.io.IOException
java.io.IOException| Method Detail |
|---|
public void clear()
throws java.io.IOException
InspectableFileCachedInputStream, zeroing the length of the represented
stream.
java.io.IOException
public int write(java.nio.ByteBuffer byteBuffer)
throws java.io.IOException
write in interface java.nio.channels.WritableByteChannelbyteBuffer - a byte buffer.
byteBuffer.remaining()).
java.io.IOException
public void truncate(long size)
throws java.io.FileNotFoundException,
java.io.IOException
size - the new size; the final size is the maximum between the current write position (i.e., the length
of the represented stream minus the length of the inspection buffer) and this value.
java.io.FileNotFoundException
java.io.IOException
public void close()
throws java.io.IOException
clear().
close in interface java.io.Closeableclose in interface java.nio.channels.Channelclose in class java.io.InputStreamjava.io.IOException
public void dispose()
throws java.io.IOException
java.io.IOException
public int available()
throws java.io.IOException
available in class java.io.InputStreamjava.io.IOException
public int read(byte[] b,
int offset,
int length)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOException
public int read(byte[] b)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOException
public long skip(long n)
throws java.io.IOException
skip in class java.io.InputStreamjava.io.IOException
public int read()
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOException
public long length()
throws java.io.IOException
MeasurableStream
length in interface MeasurableStreamjava.io.IOException
public long position()
throws java.io.IOException
RepositionableStream
position in interface MeasurableStreamposition in interface RepositionableStreamjava.io.IOException
public void position(long position)
throws java.io.IOException
position in interface RepositionableStreamposition - the new position (will be minimized with length()).
java.io.IOExceptionpublic boolean isOpen()
isOpen in interface java.nio.channels.Channelpublic void mark(int readlimit)
mark in class java.io.InputStream
public void reset()
throws java.io.IOException
reset in class java.io.InputStreamjava.io.IOExceptionpublic boolean markSupported()
markSupported in class java.io.InputStream
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||