public class ChunkSeqReader extends Object implements IBytesConsumer
This has little intelligence, it's quite low-level and general (it could even be used for a MNG stream, for example). It supports signature recognition.
| Modifier and Type | Field and Description |
|---|---|
protected static int |
SIGNATURE_LEN |
protected boolean |
withSignature |
| Constructor and Description |
|---|
ChunkSeqReader()
Creates a ChunkSeqReader (with signature)
|
ChunkSeqReader(boolean withSignature) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
checkSignature(byte[] buf)
Throws PngjInputException if bad signature
|
void |
close()
Forces a closing (abort)
|
int |
consume(byte[] buffer,
int offset,
int len)
Consumes (in general, partially) a number of bytes.
|
protected DeflatedChunksSet |
createIdatSet(String id)
DeflatedChunksSet factory.
|
protected String |
endChunkId()
Which should be the id of the last chunk
|
boolean |
feedAll(byte[] buf,
int off,
int len)
Trys to feeds exactly len bytes, calling
consume(byte[], int, int) retrying if necessary. |
protected String |
firstChunkId()
Which should be the id of the first chunk
|
long |
getBytesCount()
total of bytes read (buffered or not)
|
int |
getChunkCount() |
ChunkReader |
getCurChunkReader()
Currently reading chunk, or just ended reading
|
DeflatedChunksSet |
getCurReaderDeflatedSet()
The current deflated set (typically IDAT chunks) reader.
|
boolean |
isAtChunkBoundary()
Returns true if we are not in middle of a chunk: we have just ended
reading past chunk , or we are at the start, or end of signature, or we
are done
|
boolean |
isDone()
If true, we either have processe the IEND chunk, or close() has been
called, or a fatal error has happened
|
protected boolean |
isIdatKind(String id)
Decides if this Chunk is of "IDAT" kind (in concrete: if it is, and if
it's not to be skiped, a DeflatedChunksSet will be created to deflate it
and process+ the deflated data)
This implementation return false.
|
boolean |
isSignatureDone()
If false, we are still reading the signature
|
protected void |
postProcessChunk(ChunkReader chunkR)
This is called after a chunk is read, in all modes.
|
protected boolean |
shouldCheckCrc(int len,
String id) |
protected boolean |
shouldSkipContent(int len,
String id)
Chunks can be skipped depending on id and/or length.
|
protected void |
startNewChunk(int len,
String id,
long offset)
Called when a chunk start has been read (id and length), before the chunk
data itself is read.
|
protected static final int SIGNATURE_LEN
protected final boolean withSignature
public ChunkSeqReader()
public ChunkSeqReader(boolean withSignature)
withSignature - If true, the stream is assumed be prepended by 8 bit signaturepublic int consume(byte[] buffer,
int offset,
int len)
startNewChunk(int, String, long)
When data from a chunk is being read, it delegates to
ChunkReader.feedBytes(byte[], int, int)
The caller might want to call this method more than once in succesion
This should rarely be overridenconsume in interface IBytesConsumerbuffer - offset - Offset in bufferlen - Valid bytes that can be consumedpublic boolean feedAll(byte[] buf,
int off,
int len)
consume(byte[], int, int) retrying if necessary.
This should only be used in callback modeprotected void startNewChunk(int len,
String id,
long offset)
getCurChunkReader()) in the corresponding mode, and eventually a
curReaderDeflatedSet.(field accesible via
getCurReaderDeflatedSet())
To decide the mode and options, it calls
shouldCheckCrc(int, String),
shouldSkipContent(int, String), isIdatKind(String).
Those methods should be overriden in preference to this.
The respective ChunkReader.chunkDone() method is directed to this
postProcessChunk(ChunkReader).protected void postProcessChunk(ChunkReader chunkR)
protected DeflatedChunksSet createIdatSet(String id)
protected boolean isIdatKind(String id)
id - protected boolean shouldSkipContent(int len,
String id)
len - id - protected boolean shouldCheckCrc(int len,
String id)
protected void checkSignature(byte[] buf)
buf - Signature. Should be of length 8public boolean isSignatureDone()
public boolean isDone()
public long getBytesCount()
public int getChunkCount()
public ChunkReader getCurChunkReader()
public DeflatedChunksSet getCurReaderDeflatedSet()
public void close()
public boolean isAtChunkBoundary()
protected String firstChunkId()
protected String endChunkId()
Copyright © 2013. All rights reserved.