* condense generated `static_dict_lut.h`
 * implement BrotliInputStream.close()
This commit is contained in:
Eugene Kliuchnikov 2016-11-30 13:36:20 +01:00 committed by GitHub
parent 5db62dcc9d
commit 396309a529
7 changed files with 5862 additions and 11206 deletions

View File

@ -1336,7 +1336,6 @@ void BrotliStoreSyncMetaBlock(size_t* BROTLI_RESTRICT storage_ix,
JumpToByteBoundary(storage_ix, storage);
}
#if defined(__cplusplus) || defined(c_plusplus)
} /* extern "C" */
#endif

File diff suppressed because it is too large Load Diff

View File

@ -159,6 +159,14 @@ class BitReader {
fillBitWindow(br);
}
static void close(BitReader br) throws IOException {
InputStream is = br.input;
br.input = null;
if (is != null) {
is.close();
}
}
static void jumpToByteBoundry(BitReader br) {
int padding = (64 - br.bitOffset) & 7;
if (padding != 0) {

View File

@ -104,6 +104,14 @@ public class BrotliInputStream extends InputStream {
}
}
/**
* {@inheritDoc}
*/
@Override
public void close() throws IOException {
State.close(state);
}
/**
* {@inheritDoc}
*/

View File

@ -7,6 +7,7 @@
package org.brotli.dec;
import static org.brotli.dec.RunningState.BLOCK_START;
import static org.brotli.dec.RunningState.CLOSED;
import static org.brotli.dec.RunningState.COMPRESSED_BLOCK_START;
import static org.brotli.dec.RunningState.COPY_LOOP;
import static org.brotli.dec.RunningState.COPY_UNCOMPRESSED;
@ -582,6 +583,9 @@ public final class Decode {
if (state.runningState == UNINITIALIZED) {
throw new IllegalStateException("Can't decompress until initialized");
}
if (state.runningState == CLOSED) {
throw new IllegalStateException("Can't decompress after close");
}
final BitReader br = state.br;
int ringBufferMask = state.ringBufferSize - 1;
byte[] ringBuffer = state.ringBuffer;

View File

@ -21,5 +21,6 @@ enum RunningState {
COPY_WRAP_BUFFER,
TRANSFORM,
FINISHED,
CLOSED,
WRITE
}

View File

@ -7,8 +7,10 @@
package org.brotli.dec;
import static org.brotli.dec.RunningState.BLOCK_START;
import static org.brotli.dec.RunningState.CLOSED;
import static org.brotli.dec.RunningState.UNINITIALIZED;
import java.io.IOException;
import java.io.InputStream;
final class State {
@ -93,7 +95,7 @@ final class State {
*/
static void setInput(State state, InputStream input) {
if (state.runningState != UNINITIALIZED) {
throw new IllegalStateException("State is MUST be uninitialized");
throw new IllegalStateException("State MUST be uninitialized");
}
BitReader.init(state.br, input);
int windowBits = decodeWindowBits(state.br);
@ -104,4 +106,15 @@ final class State {
state.maxBackwardDistance = state.maxRingBufferSize - 16;
state.runningState = BLOCK_START;
}
static void close(State state) throws IOException {
if (state.runningState == UNINITIALIZED) {
throw new IllegalStateException("State MUST be initialized");
}
if (state.runningState == CLOSED) {
return;
}
state.runningState = CLOSED;
BitReader.close(state.br);
}
}