Refine search
/** * Compute CRC32 code for byte[]. * * @param array * @param offset * @param length * @return */ public static final int crc32(byte[] array, int offset, int length) { CRC32 crc32 = CRC_32_THREAD_LOCAL.get(); crc32.update(array, offset, length); int ret = (int) crc32.getValue(); crc32.reset(); return ret; }
@Override public ByteBuffer compress(ByteBuffer in) throws IOException { ByteBuffer out = ByteBuffer.allocate(Snappy.maxCompressedLength(in.remaining())+4); int size = Snappy.compress(in.array(), in.position(), in.remaining(), out.array(), 0); crc32.reset(); crc32.update(in.array(), in.position(), in.remaining()); out.putInt(size, (int)crc32.getValue()); out.limit(size+4); return out; }
@Override public ByteBuffer decompress(ByteBuffer in) throws IOException { ByteBuffer out = ByteBuffer.allocate (Snappy.uncompressedLength(in.array(),in.position(),in.remaining()-4)); int size = Snappy.uncompress(in.array(),in.position(),in.remaining()-4, out.array(), 0); out.limit(size); crc32.reset(); crc32.update(out.array(), 0, size); if (in.getInt(in.limit()-4) != (int)crc32.getValue()) throw new IOException("Checksum failure"); return out; }
@Override public ByteBuffer compress(ByteBuffer in) throws IOException { int offset = computeOffset(in); ByteBuffer out = ByteBuffer.allocate(Snappy.maxCompressedLength(in.remaining())+4); int size = Snappy.compress(in.array(), offset, in.remaining(), out.array(), 0); crc32.reset(); crc32.update(in.array(), offset, in.remaining()); out.putInt(size, (int)crc32.getValue()); out.limit(size+4); return out; }
@Override public ByteBuffer decompress(ByteBuffer in) throws IOException { int offset = computeOffset(in); ByteBuffer out = ByteBuffer.allocate (Snappy.uncompressedLength(in.array(), offset, in.remaining()-4)); int size = Snappy.uncompress(in.array(), offset, in.remaining()-4, out.array(), 0); out.limit(size); crc32.reset(); crc32.update(out.array(), 0, size); if (in.getInt(in.limit()-4) != (int)crc32.getValue()) throw new IOException("Checksum failure"); return out; }
/** * Write a PNG "IEND" chunk into the pngBytes array. */ protected void writeEnd() { this.bytePos = writeInt4(0, this.bytePos); this.bytePos = writeBytes(IEND, this.bytePos); this.crc.reset(); this.crc.update(IEND); this.crcValue = this.crc.getValue(); this.bytePos = writeInt4((int) this.crcValue, this.bytePos); }
for (File file : listFiles(dirPath)) { BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); crc.reset(); while ((bytesRead = bis.read(buffer)) != -1) { crc.update(buffer, 0, bytesRead); entry.setCompressedSize(file.length()); entry.setSize(file.length()); entry.setCrc(crc.getValue()); zos.putNextEntry(entry); while ((bytesRead = bis.read(buffer)) != -1) {