case STATE_INITIAL: if (b != LZFChunk.BYTE_Z) { _reportBadHeader(comp, offset, len, 0); _reportBadHeader(comp, offset, len, 1); continue; _reportBadBlockType(comp, offset, len, type); offset = _handleCompressed(comp, --offset, end); offset = _handleUncompressed(comp, --offset, end); if (_terminated) { break;
private final int _handleCompressed(byte[] comp, int offset, int end) throws IOException { // One special case: if we get the whole block, can avoid buffering: int available = end-offset; if (_bytesReadFromBlock == 0 && available >= _compressedLength) { _uncompress(comp, offset, _compressedLength); offset += _compressedLength; _state = STATE_INITIAL; return offset; } // otherwise need to buffer if (_inputBuffer == null) { _inputBuffer = _recycler.allocInputBuffer(LZFChunk.MAX_CHUNK_LEN); } int amount = Math.min(available, _compressedLength - _bytesReadFromBlock); System.arraycopy(comp, offset, _inputBuffer, _bytesReadFromBlock, amount); offset += amount; _bytesReadFromBlock += amount; // Got it all? if (_bytesReadFromBlock == _compressedLength) { _uncompress(_inputBuffer, 0, _compressedLength); _state = STATE_INITIAL; } return offset; }
/** * Method called in cases where the compressed file can be fully read * in a single buffer, to be uncompressed and written. */ protected void _readAllWriteAllCompressed(final OutputStream out, final byte[] copyBuffer, final long offset, final long dataLength) throws IOException { // important: specify no offset, file length; data offset/length is for _uncompressed_ int inputLength = (int) _fileLength; _readAll(out, copyBuffer, 0L, inputLength); // Compress-Ning package allows "push" style uncompression (yay!) Uncompressor uncomp; DataHandler h = new RangedDataHandler(out, offset, dataLength); if (_compression == Compression.LZF) { uncomp = new LZFUncompressor(h); } else if (_compression == Compression.GZIP) { uncomp = new GZIPUncompressor(h); } else { // otherwise, must use bulk operations? // TODO: currently we do not have other codecs throw new UnsupportedOperationException("No Uncompressor for compression type: "+_compression); } final long start = (_diagnostics == null) ? 0L : _timeMaster.nanosForDiagnostics(); uncomp.feedCompressedData(copyBuffer, 0, inputLength); uncomp.complete(); if (_diagnostics != null) { _diagnostics.addResponseWriteTime(start, _timeMaster); } }
case STATE_INITIAL: if (b != LZFChunk.BYTE_Z) { _reportBadHeader(comp, offset, len, 0); _reportBadHeader(comp, offset, len, 1); continue; _reportBadBlockType(comp, offset, len, type); offset = _handleCompressed(comp, --offset, end); offset = _handleUncompressed(comp, --offset, end); if (_terminated) { break;
private final int _handleCompressed(byte[] comp, int offset, int end) throws IOException { // One special case: if we get the whole block, can avoid buffering: int available = end-offset; if (_bytesReadFromBlock == 0 && available >= _compressedLength) { _uncompress(comp, offset, _compressedLength); offset += _compressedLength; _state = STATE_INITIAL; return offset; } // otherwise need to buffer if (_inputBuffer == null) { _inputBuffer = _recycler.allocInputBuffer(LZFChunk.MAX_CHUNK_LEN); } int amount = Math.min(available, _compressedLength - _bytesReadFromBlock); System.arraycopy(comp, offset, _inputBuffer, _bytesReadFromBlock, amount); offset += amount; _bytesReadFromBlock += amount; // Got it all? if (_bytesReadFromBlock == _compressedLength) { _uncompress(_inputBuffer, 0, _compressedLength); _state = STATE_INITIAL; } return offset; }
case STATE_INITIAL: if (b != LZFChunk.BYTE_Z) { _reportBadHeader(comp, offset, len, 0); _reportBadHeader(comp, offset, len, 1); continue; _reportBadBlockType(comp, offset, len, type); offset = _handleCompressed(comp, --offset, end); offset = _handleUncompressed(comp, --offset, end); if (_terminated) { break;
private final int _handleCompressed(byte[] comp, int offset, int end) throws IOException { // One special case: if we get the whole block, can avoid buffering: int available = end-offset; if (_bytesReadFromBlock == 0 && available >= _compressedLength) { _uncompress(comp, offset, _compressedLength); offset += _compressedLength; _state = STATE_INITIAL; return offset; } // otherwise need to buffer if (_inputBuffer == null) { _inputBuffer = _recycler.allocInputBuffer(LZFChunk.MAX_CHUNK_LEN); } int amount = Math.min(available, _compressedLength - _bytesReadFromBlock); System.arraycopy(comp, offset, _inputBuffer, _bytesReadFromBlock, amount); offset += amount; _bytesReadFromBlock += amount; // Got it all? if (_bytesReadFromBlock == _compressedLength) { _uncompress(_inputBuffer, 0, _compressedLength); _state = STATE_INITIAL; } return offset; }