public final class ReadAheadFileOperations extends Object implements FlushableFileOperations
FileOperations
cache.
This implementation implements a read-ahead cache for
FileOperations
implementations. The cache is controlled by
configuration property cacheSize
holding the number of bytes
to read-ahead. By default property cacheSize
is initialized to
16384
leading to a cache size of 16 kB. All memory is allocated
during instantiation so that an OutOfMemoryError
may be thrown
when constructing the cache but not when working with the instance.
Note:
This implementation is not thread-safe and concurrent changes to the
underlying FileOperations
implementation are not supported.
Constructor and Description |
---|
ReadAheadFileOperations(org.jdtaus.core.io.FileOperations fileOperations)
Creates a new
ReadAheadFileOperations instance taking the
FileOperations backing the instance. |
ReadAheadFileOperations(org.jdtaus.core.io.FileOperations fileOperations,
int cacheSize)
Creates a new
ReadAheadFileOperations instance taking the
FileOperations backing the instance and the size of the cache. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Flushes the cache and closes the
FileOperations implementation
backing the instance. |
void |
flush()
Flushes the instance.
|
int |
getCacheSize()
Gets the size of the cache in byte.
|
org.jdtaus.core.io.FileOperations |
getFileOperations()
Gets the
FileOperations implementation operations are performed
with. |
long |
getFilePointer() |
long |
getLength() |
int |
read(byte[] buf,
int off,
int len) |
void |
read(OutputStream out) |
void |
setFilePointer(long pos) |
void |
setLength(long newLength) |
void |
write(byte[] buf,
int off,
int len) |
void |
write(InputStream in) |
public ReadAheadFileOperations(org.jdtaus.core.io.FileOperations fileOperations) throws IOException
ReadAheadFileOperations
instance taking the
FileOperations
backing the instance.fileOperations
- the FileOperations
backing the instance.NullPointerException
- if fileOperations
is null
.IOException
- if reading fails.public ReadAheadFileOperations(org.jdtaus.core.io.FileOperations fileOperations, int cacheSize) throws IOException
ReadAheadFileOperations
instance taking the
FileOperations
backing the instance and the size of the cache.fileOperations
- the FileOperations
backing the instance.cacheSize
- the number of bytes to read-ahead.NullPointerException
- if fileOperations
is null
.IOException
- if reading fails.public long getLength() throws IOException
getLength
in interface org.jdtaus.core.io.FileOperations
IOException
public void setLength(long newLength) throws IOException
setLength
in interface org.jdtaus.core.io.FileOperations
IOException
public long getFilePointer() throws IOException
getFilePointer
in interface org.jdtaus.core.io.FileOperations
IOException
public void setFilePointer(long pos) throws IOException
setFilePointer
in interface org.jdtaus.core.io.FileOperations
IOException
public int read(byte[] buf, int off, int len) throws IOException
read
in interface org.jdtaus.core.io.FileOperations
IOException
public void write(byte[] buf, int off, int len) throws IOException
write
in interface org.jdtaus.core.io.FileOperations
IOException
public void read(OutputStream out) throws IOException
read
in interface org.jdtaus.core.io.FileOperations
IOException
public void write(InputStream in) throws IOException
write
in interface org.jdtaus.core.io.FileOperations
IOException
public void close() throws IOException
FileOperations
implementation
backing the instance.close
in interface org.jdtaus.core.io.FileOperations
IOException
- if closing the FileOperations
implementation
backing the instance fails or if the instance already is closed.public void flush() throws IOException
flush()
method of an underlying
FlushableFileOperations
implementation, if any.flush
in interface FlushableFileOperations
IOException
- if reading or writing fails.public org.jdtaus.core.io.FileOperations getFileOperations()
FileOperations
implementation operations are performed
with.FileOperations
implementation operations are
performed with.public int getCacheSize()
Copyright © 2005-2012 jDTAUS. All Rights Reserved.