public final class CoalescingFileOperations extends Object implements FlushableFileOperations
FileOperations
cache.
This implementation implements a coalescing cache for
FileOperations
implementations. The cache is controlled by
configuration property blockSize
. By default property
blockSize
is initialized to 2097152
leading to a cache
size of 10 MB (multiplied by property cacheSize
which defaults to
5
). 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 |
---|
CoalescingFileOperations(org.jdtaus.core.io.FileOperations fileOperations)
Creates a new
CoalescingFileOperations instance taking the
FileOperations backing the instance. |
CoalescingFileOperations(org.jdtaus.core.io.FileOperations fileOperations,
int blockSize)
Creates a new
CoalescingFileOperations instance taking the
FileOperations backing the instance and the number of bytes
occupied by one cache block. |
CoalescingFileOperations(org.jdtaus.core.io.FileOperations fileOperations,
int blockSize,
int cacheBlocks)
Creates a new
CoalescingFileOperations instance taking the
FileOperations backing the instance, the number of bytes
occupied by one cache block and the number of cache blocks. |
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 |
getBlockSize()
Gets the number of bytes occupied by one cache block.
|
int |
getCacheBlocks()
Gets the number of blocks in the cache.
|
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 CoalescingFileOperations(org.jdtaus.core.io.FileOperations fileOperations) throws IOException
CoalescingFileOperations
instance taking the
FileOperations
backing the instance.fileOperations
- the FileOperations
backing the instance.NullPointerException
- if fileOperations
is null
.IOException
- if reading fails.public CoalescingFileOperations(org.jdtaus.core.io.FileOperations fileOperations, int blockSize) throws IOException
CoalescingFileOperations
instance taking the
FileOperations
backing the instance and the number of bytes
occupied by one cache block.fileOperations
- the FileOperations
backing the instance.blockSize
- the number of bytes occupied by one cache block.NullPointerException
- if fileOperations
is null
.IOException
- if reading fails.public CoalescingFileOperations(org.jdtaus.core.io.FileOperations fileOperations, int blockSize, int cacheBlocks) throws IOException
CoalescingFileOperations
instance taking the
FileOperations
backing the instance, the number of bytes
occupied by one cache block and the number of cache blocks.fileOperations
- the FileOperations
backing the instance.blockSize
- the number of bytes occupied by one cache block.cacheBlocks
- number of cache blocks.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 flushing or 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 writing any pending changes fails or if the
instance is closed.public org.jdtaus.core.io.FileOperations getFileOperations()
FileOperations
implementation operations are performed
with.FileOperations
implementation operations are
performed with.public int getBlockSize()
public int getCacheBlocks()
Copyright © 2005-2012 jDTAUS. All Rights Reserved.