public class DeflatedChunksSet extends Object
The inflated stream is intented to be read as a sequence of "rows", of which the caller knows the lengths (not necessary equal) and number.
Eg: For IDAT non-interlaced images, a row has bytesPerRow + 1 filter byte
For interlaced images, the lengths are variable.
This class can work in sync (polled) mode or async (callback) mode. But for callback mode the method processRowCallback() must be overriden
See IdatSet
, which is mostly used and has a slightly simpler use.
See DeflatedChunkSetTest
for example of use.
Modifier and Type | Field and Description |
---|---|
String |
chunkid
All IDAT-like chunks that form a same DeflatedChunksSet should have the same id
|
protected byte[] |
row |
Constructor and Description |
---|
DeflatedChunksSet(String chunkid,
int initialRowLen,
int maxRowLen) |
DeflatedChunksSet(String chunkid,
int initialRowLen,
int maxRowLen,
Inflater inflater,
byte[] buffer) |
Modifier and Type | Method and Description |
---|---|
boolean |
ackNextChunkId(String id)
This will be called by the owner to report us the next chunk to come.
|
boolean |
allowOtherChunksInBetween(String id)
Some IDAT-like set can allow other chunks in between (APGN?).
|
protected void |
appendNewChunk(DeflatedChunkReader cr) |
void |
close()
This should be called when discarding this object, or for aborting.
|
void |
done()
Forces the DONE state, this object won't uncompress more data.
|
long |
getBytesIn()
total number of bytes that have been fed to this object
|
long |
getBytesOut()
total number of bytes that have been uncompressed
|
byte[] |
getInflatedRow()
Inflated buffer.
|
int |
getRowFilled()
This the amount of valid bytes in the buffer
|
int |
getRowLen()
Target size of the current row, including filter byte.
|
int |
getRown()
Get current (last) row number.
|
boolean |
isCallbackMode()
Callback mode = async processing
|
boolean |
isDone()
In this state, all relevant data has been uncompressed and retrieved (exceptionally, the reading has ended
prematurely).
|
boolean |
isRowReady()
In this state, the object is waiting the caller to retrieve inflated data
|
boolean |
isTerminated() |
boolean |
isWaitingForMoreInput()
In this state, the object is waiting for more input to deflate.
|
void |
prepareForNextRow(int len)
Should be called after the previous row was processed
|
protected void |
preProcessRow()
Called automatically in all modes when a full row has been inflated.
|
protected void |
processBytes(byte[] buf,
int off,
int len)
Feeds the inflater with the compressed bytes
In poll mode, the caller should not call repeatedly this, without consuming first, checking
isDataReadyForConsumer()
|
protected void |
processDoneCallback()
Callback, to be implemented in callbackMode
|
protected int |
processRowCallback()
Callback, must be implemented in callbackMode
|
void |
setCallbackMode(boolean callbackMode) |
protected void |
terminate() |
String |
toString() |
protected byte[] row
public final String chunkid
public DeflatedChunksSet(String chunkid, int initialRowLen, int maxRowLen, Inflater inflater, byte[] buffer)
initialRowLen
- Length in bytes of first "row" (see description)maxRowLen
- Max length in bytes of "rows"inflater
- Can be null. If not null, must be already reset (and it must be closed/released by caller!)public DeflatedChunksSet(String chunkid, int initialRowLen, int maxRowLen)
protected void appendNewChunk(DeflatedChunkReader cr)
protected void processBytes(byte[] buf, int off, int len)
buf
- off
- len
- protected void preProcessRow()
protected int processRowCallback()
This should use getRowFilled()
and getInflatedRow()
to access the row.
Must return byes of next row, for next callback.
protected void processDoneCallback()
This will be called once to notify state done
public byte[] getInflatedRow()
getRowFilled()
public void prepareForNextRow(int len)
Pass 0 or negative to signal that we are done (not expecting more bytes)
This resets rowfilled
The
public boolean isWaitingForMoreInput()
Only in this state it's legal to feed this
public boolean isRowReady()
Effective length: see getRowFilled()
public boolean isDone()
We can still feed this object, but the bytes will be swallowed/ignored.
public boolean isTerminated()
public boolean ackNextChunkId(String id)
protected void terminate()
public void close()
done()
public void done()
public int getRowLen()
public int getRowFilled()
public int getRown()
This corresponds to the raw numeration of rows as seen by the deflater. Not the same as the real image row, if interlaced.
public boolean allowOtherChunksInBetween(String id)
Normally false.
id
- Id of the other chunk that appeared in middel of this set.public boolean isCallbackMode()
public void setCallbackMode(boolean callbackMode)
public long getBytesIn()
public long getBytesOut()
Copyright © 2014. All rights reserved.