/** * Helper method called when it is determined that the target buffer can not * hold all data to copy or uncompress */ protected void _reportArrayOverflow(byte[] targetBuffer, int outPtr, int dataLen) throws LZFException { throw new LZFException("Target buffer too small ("+targetBuffer.length+"): can not copy/uncompress " +dataLen+" bytes to offset "+outPtr); } }
/** * Helper method called when it is determined that the target buffer can not * hold all data to copy or uncompress */ protected void _reportArrayOverflow(byte[] targetBuffer, int outPtr, int dataLen) throws LZFException { throw new LZFException("Target buffer too small ("+targetBuffer.length+"): can not copy/uncompress " +dataLen+" bytes to offset "+outPtr); } }
/** * Helper method called when it is determined that the target buffer can not * hold all data to copy or uncompress */ protected void _reportArrayOverflow(byte[] targetBuffer, int outPtr, int dataLen) throws LZFException { throw new LZFException("Target buffer too small ("+targetBuffer.length+"): can not copy/uncompress " +dataLen+" bytes to offset "+outPtr); } }
protected void _reportCorruptHeader() throws LZFException { throw new LZFException("Corrupt input data, block did not start with 2 byte signature ('ZV') followed by type byte, 2-byte length)"); }
protected void _reportCorruptHeader() throws LZFException { throw new LZFException("Corrupt input data, block did not start with 2 byte signature ('ZV') followed by type byte, 2-byte length)"); }
protected void _reportCorruptHeader() throws LZFException { throw new LZFException("Corrupt input data, block did not start with 2 byte signature ('ZV') followed by type byte, 2-byte length)"); }
protected final static void skipFully(final InputStream is, int amount) throws IOException { final int orig = amount; while (amount > 0) { long skipped = is.skip(amount); if (skipped <= 0) { throw new LZFException("Input problem: failed to skip "+orig+" bytes in input stream, only skipped " +(orig-amount)); } amount -= (int) skipped; } }
protected void _reportBadBlockType(byte[] comp, int nextOffset, int len, int type) throws IOException { throw new LZFException("Bad block: unrecognized type 0x"+Integer.toHexString(type & 0xFF) +" (at "+(nextOffset-1)+"/"+len+")"); } }
protected final static void skipFully(final InputStream is, int amount) throws IOException { final int orig = amount; while (amount > 0) { long skipped = is.skip(amount); if (skipped <= 0) { throw new LZFException("Input problem: failed to skip "+orig+" bytes in input stream, only skipped " +(orig-amount)); } amount -= (int) skipped; } }
protected final static void skipFully(final InputStream is, int amount) throws IOException { final int orig = amount; while (amount > 0) { long skipped = is.skip(amount); if (skipped <= 0) { throw new LZFException("Input problem: failed to skip "+orig+" bytes in input stream, only skipped " +(orig-amount)); } amount -= (int) skipped; } }
protected void _reportBadBlockType(byte[] comp, int nextOffset, int len, int type) throws IOException { throw new LZFException("Bad block: unrecognized type 0x"+Integer.toHexString(type & 0xFF) +" (at "+(nextOffset-1)+"/"+len+")"); } }
protected void _reportBadBlockType(byte[] comp, int nextOffset, int len, int type) throws IOException { throw new LZFException("Bad block: unrecognized type 0x"+Integer.toHexString(type & 0xFF) +" (at "+(nextOffset-1)+"/"+len+")"); } }
protected final static void readFully(InputStream is, boolean compressed, byte[] outputBuffer, int offset, int len) throws IOException { int left = len; while (left > 0) { int count = is.read(outputBuffer, offset, left); if (count < 0) { // EOF not allowed here throw new LZFException("EOF in "+len+" byte (" +(compressed ? "" : "un")+"compressed) block: could only read " +(len-left)+" bytes"); } offset += count; left -= count; } }
protected final static void readFully(InputStream is, boolean compressed, byte[] outputBuffer, int offset, int len) throws IOException { int left = len; while (left > 0) { int count = is.read(outputBuffer, offset, left); if (count < 0) { // EOF not allowed here throw new LZFException("EOF in "+len+" byte (" +(compressed ? "" : "un")+"compressed) block: could only read " +(len-left)+" bytes"); } offset += count; left -= count; } }
protected final static void readFully(InputStream is, boolean compressed, byte[] outputBuffer, int offset, int len) throws IOException { int left = len; while (left > 0) { int count = is.read(outputBuffer, offset, left); if (count < 0) { // EOF not allowed here throw new LZFException("EOF in "+len+" byte (" +(compressed ? "" : "un")+"compressed) block: could only read " +(len-left)+" bytes"); } offset += count; left -= count; } }
protected void _reportBadHeader(byte[] comp, int nextOffset, int len, int relative) throws IOException { char exp = (relative == 0) ? 'Z' : 'V'; --nextOffset; throw new LZFException("Bad block: byte #"+relative+" of block header not '" +exp+"' (0x"+Integer.toHexString(exp) +") but 0x"+Integer.toHexString(comp[nextOffset] & 0xFF) +" (at "+(nextOffset-1)+"/"+(len)+")"); }
protected void _reportBadHeader(byte[] comp, int nextOffset, int len, int relative) throws IOException { char exp = (relative == 0) ? 'Z' : 'V'; --nextOffset; throw new LZFException("Bad block: byte #"+relative+" of block header not '" +exp+"' (0x"+Integer.toHexString(exp) +") but 0x"+Integer.toHexString(comp[nextOffset] & 0xFF) +" (at "+(nextOffset-1)+"/"+(len)+")"); }
protected void _reportBadHeader(byte[] comp, int nextOffset, int len, int relative) throws IOException { char exp = (relative == 0) ? 'Z' : 'V'; --nextOffset; throw new LZFException("Bad block: byte #"+relative+" of block header not '" +exp+"' (0x"+Integer.toHexString(exp) +") but 0x"+Integer.toHexString(comp[nextOffset] & 0xFF) +" (at "+(nextOffset-1)+"/"+(len)+")"); }
@Override public void complete() throws IOException { byte[] b = _inputBuffer; if (b != null) { _inputBuffer = null; _recycler.releaseInputBuffer(b); } b = _decodeBuffer; if (b != null) { _decodeBuffer = null; _recycler.releaseDecodeBuffer(b); } // 24-May-2012, tatu: Should we call this here; or fail with exception? _handler.allDataHandled(); if (!_terminated) { if (_state != STATE_INITIAL) { if (_state == STATE_HEADER_COMPRESSED_BUFFERING) { throw new LZFException("Incomplete compressed LZF block; only got "+_bytesReadFromBlock +" bytes, needed "+_compressedLength); } if (_state == STATE_HEADER_UNCOMPRESSED_STREAMING) { throw new LZFException("Incomplete uncompressed LZF block; only got "+_bytesReadFromBlock +" bytes, needed "+_uncompressedLength); } throw new LZFException("Incomplete LZF block; decoding state = "+_state); } } }
@Override public void complete() throws IOException { byte[] b = _inputBuffer; if (b != null) { _inputBuffer = null; _recycler.releaseInputBuffer(b); } b = _decodeBuffer; if (b != null) { _decodeBuffer = null; _recycler.releaseDecodeBuffer(b); } // 24-May-2012, tatu: Should we call this here; or fail with exception? _handler.allDataHandled(); if (!_terminated) { if (_state != STATE_INITIAL) { if (_state == STATE_HEADER_COMPRESSED_BUFFERING) { throw new LZFException("Incomplete compressed LZF block; only got "+_bytesReadFromBlock +" bytes, needed "+_compressedLength); } if (_state == STATE_HEADER_UNCOMPRESSED_STREAMING) { throw new LZFException("Incomplete uncompressed LZF block; only got "+_bytesReadFromBlock +" bytes, needed "+_uncompressedLength); } throw new LZFException("Incomplete LZF block; decoding state = "+_state); } } }