Package com.twelvemonkeys.imageio.stream
Class MemoryCache
- java.lang.Object
-
- com.twelvemonkeys.imageio.stream.MemoryCache
-
- All Implemented Interfaces:
Cache
,java.io.Closeable
,java.lang.AutoCloseable
,java.nio.channels.ByteChannel
,java.nio.channels.Channel
,java.nio.channels.ReadableByteChannel
,java.nio.channels.SeekableByteChannel
,java.nio.channels.WritableByteChannel
final class MemoryCache extends java.lang.Object implements Cache
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static int
BLOCK_SIZE
private java.util.List<byte[]>
cache
private java.nio.channels.ReadableByteChannel
channel
private long
length
private int
maxBlock
private static byte[]
NULL_BLOCK
private long
position
private long
start
-
Constructor Summary
Constructors Constructor Description MemoryCache(java.io.InputStream stream)
MemoryCache(java.nio.channels.ReadableByteChannel channel)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
(package private) byte[]
fetchBlock()
void
flushBefore(long pos)
boolean
isOpen()
long
position()
java.nio.channels.SeekableByteChannel
position(long newPosition)
int
read(java.nio.ByteBuffer dest)
private int
readBlock(byte[] block)
long
size()
java.nio.channels.SeekableByteChannel
truncate(long size)
int
write(java.nio.ByteBuffer src)
-
-
-
Field Detail
-
BLOCK_SIZE
static final int BLOCK_SIZE
- See Also:
- Constant Field Values
-
NULL_BLOCK
private static final byte[] NULL_BLOCK
-
cache
private final java.util.List<byte[]> cache
-
channel
private final java.nio.channels.ReadableByteChannel channel
-
maxBlock
private int maxBlock
-
length
private long length
-
position
private long position
-
start
private long start
-
-
Method Detail
-
fetchBlock
byte[] fetchBlock() throws java.io.IOException
- Throws:
java.io.IOException
-
readBlock
private int readBlock(byte[] block) throws java.io.IOException
- Throws:
java.io.IOException
-
isOpen
public boolean isOpen()
- Specified by:
isOpen
in interfacejava.nio.channels.Channel
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.nio.channels.Channel
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
read
public int read(java.nio.ByteBuffer dest) throws java.io.IOException
- Specified by:
read
in interfacejava.nio.channels.ReadableByteChannel
- Specified by:
read
in interfacejava.nio.channels.SeekableByteChannel
- Throws:
java.io.IOException
-
position
public long position() throws java.io.IOException
- Specified by:
position
in interfacejava.nio.channels.SeekableByteChannel
- Throws:
java.io.IOException
-
position
public java.nio.channels.SeekableByteChannel position(long newPosition) throws java.io.IOException
- Specified by:
position
in interfacejava.nio.channels.SeekableByteChannel
- Throws:
java.io.IOException
-
size
public long size() throws java.io.IOException
- Specified by:
size
in interfacejava.nio.channels.SeekableByteChannel
- Throws:
java.io.IOException
-
write
public int write(java.nio.ByteBuffer src)
- Specified by:
write
in interfacejava.nio.channels.SeekableByteChannel
- Specified by:
write
in interfacejava.nio.channels.WritableByteChannel
-
truncate
public java.nio.channels.SeekableByteChannel truncate(long size)
- Specified by:
truncate
in interfacejava.nio.channels.SeekableByteChannel
-
flushBefore
public void flushBefore(long pos)
- Specified by:
flushBefore
in interfaceCache
-
-