Refine search
/** Returns a CRC of the remaining bytes in the stream. */ public String crc (InputStream input) { if (input == null) return "" + System.nanoTime(); // fallback CRC32 crc = new CRC32(); byte[] buffer = new byte[4096]; try { while (true) { int length = input.read(buffer); if (length == -1) break; crc.update(buffer, 0, length); } } catch (Exception ex) { try { input.close(); } catch (Exception ignored) { } } return Long.toString(crc.getValue()); }
if (inf.needsInput()) { in.mark(buf.length); bufUsed = in.read(buf); if (bufUsed == -1) { throw new EOFException(); inf.setInput(buf, 0, bufUsed); ret = inf.inflate(b, off, len); } catch (final DataFormatException e) { throw new IOException("Gzip-compressed data is corrupt"); crc.update(b, off, ret); off += ret; len -= ret; in.reset(); final int skipAmount = bufUsed - inf.getRemaining(); if (crcStored != crc.getValue()) { throw new IOException("Gzip-compressed data is corrupt " + "(CRC32 error)");
final InputStream markableInputStream = in.markSupported() ? in : new BufferedInputStream(in); final CRC32 cal = new CRC32(); markableInputStream.mark(Integer.MAX_VALUE); final byte[] buffer = new byte[BUFFER_SIZE]; int count = 0; do { size += count; cal.update(buffer, 0, count); count = markableInputStream.read(buffer, 0, buffer.length); } while (count != -1); markableInputStream.reset(); ze.setSize(size); ze.setCrc(cal.getValue());
/** * Calculate checksum on all the data read from input stream. * * This should be more efficient than the equivalent code * {@code IOUtils.calculateChecksum(IOUtils.toByteArray(stream))} */ public static long calculateChecksum(InputStream stream) throws IOException { Checksum sum = new CRC32(); byte[] buf = new byte[4096]; int count; while ((count = stream.read(buf)) != -1) { if (count > 0) { sum.update(buf, 0, count); } } return sum.getValue(); }
super(is, new Inflater(true), size); byte[] header = new byte[10]; readFully(header, 0, header.length); boolean hcrc = (flags & FHCRC) != 0; if (hcrc) { crc.update(header, 0, header.length); crc.update(header, 0, 2); int result = in.read(buf, 0, max); if (result == -1) { throw new EOFException(); crc.update(buf, 0, result); readFully(header, 0, 2); short crc16 = Memory.peekShort(header, 0, ByteOrder.LITTLE_ENDIAN); if ((short) crc.getValue() != crc16) { throw new IOException("CRC mismatch"); crc.reset();
Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount); if (inf.finished() || currentEntry == null) { return -1; if ((len = in.read(buf)) == -1) { eof = true; return -1; lastRead += toRead; inRead += toRead; crc.update(buffer, byteOffset, toRead); return toRead; if (inf.needsInput()) { fill(); if (len > 0) { read = inf.inflate(buffer, byteOffset, byteCount); } catch (DataFormatException e) { throw new ZipException(e.getMessage()); return -1; crc.update(buffer, byteOffset, read); return read;
final int height = image.getHeight(null); scrunch.finish(); bytePos = writeInt4(pngBytes, height, bytePos); bytePos = writeBytes(pngBytes, new byte[]{8, 2, 0, 0, 0}, bytePos); final CRC32 crc = new CRC32(); crc.reset(); crc.update(pngBytes, startPos, bytePos - startPos); bytePos = writeInt4(pngBytes, (int) crc.getValue(), bytePos); crc.reset(); bytePos = writeInt4(pngBytes, nCompressed, bytePos); bytePos = writeBytes(pngBytes, IDAT, bytePos); crc.update(IDAT); System.arraycopy(outBytes.toByteArray(), 0, pngBytes, bytePos, outBytes.size()); outBytes.close(); outBytes = null; crc.update(pngBytes, bytePos, nCompressed); bytePos += nCompressed; bytePos = writeInt4(pngBytes, (int) crc.getValue(), bytePos); bytePos = writeInt4(pngBytes, 0, bytePos); bytePos = writeBytes(pngBytes, IEND, bytePos); crc.reset(); crc.update(IEND); bytePos = writeInt4(pngBytes, (int) crc.getValue(), bytePos); return pngBytes;
deflater.finish(); while (!deflater.finished()) { deflate(footer); if (!footer.isWritable()) { int crcValue = (int) crc.getValue(); int uncBytes = deflater.getTotalIn(); footer.writeByte(crcValue); footer.writeByte(crcValue >>> 8);
private JdkZlibDecoder(ZlibWrapper wrapper, byte[] dictionary, boolean decompressConcatenated) { if (wrapper == null) { throw new NullPointerException("wrapper"); } this.decompressConcatenated = decompressConcatenated; switch (wrapper) { case GZIP: inflater = new Inflater(true); crc = ByteBufChecksum.wrapChecksum(new CRC32()); break; case NONE: inflater = new Inflater(true); crc = null; break; case ZLIB: inflater = new Inflater(); crc = null; break; case ZLIB_OR_NONE: // Postpone the decision until decode(...) is called. decideZlibOrNone = true; crc = null; break; default: throw new IllegalArgumentException("Only GZIP or ZLIB is supported, but you used " + wrapper); } this.dictionary = dictionary; }
crc.update(inAry, offset, len); deflater.setInput(inAry, offset, len); for (;;) { deflate(out); if (deflater.needsInput()) {
/** * Computes the checksum of a file using the CRC32 checksum routine. * The value of the checksum is returned. * * @param file the file to checksum, must not be {@code null} * @return the checksum value * @throws NullPointerException if the file or checksum is {@code null} * @throws IllegalArgumentException if the file is a directory * @throws IOException if an IO error occurs reading the file * @since 1.3 */ public static long checksumCRC32(final File file) throws IOException { final CRC32 crc = new CRC32(); checksum(file, crc); return crc.getValue(); }
@Override public Checksum get() { return new CRC32(); } },