Refine search
public long computeCrc() throws IOException { byte[] buffer = new byte[BUFFER_SIZE]; Checksum checksum = new Adler32(); for (File file : _files) { try (InputStream input = new FileInputStream(file)) { int len; while ((len = input.read(buffer)) > 0) { checksum.update(buffer, 0, len); } } } return checksum.getValue(); }
/** * Calculates the checksum for the <code>.dex</code> file in the * given array, and modify the array to contain it. * * @param bytes non-null; the bytes of the file */ public static void calcChecksum(byte[] bytes) { Adler32 a32 = new Adler32(); a32.update(bytes, 12, bytes.length - 12); int sum = (int) a32.getValue(); bytes[8] = (byte) sum; bytes[9] = (byte) (sum >> 8); bytes[10] = (byte) (sum >> 16); bytes[11] = (byte) (sum >> 24); }
private long computeClassPathHash(final URL... classpathEntry) { final Adler32 adler32 = new Adler32(); for (final URL url : classpathEntry) { try (CheckedInputStream inputStream = new CheckedInputStream(url.openStream(), adler32)) { // Just read it, the CheckedInputStream will update the checksum on it's own while (IOUtils.skip(inputStream, Long.MAX_VALUE) == Long.MAX_VALUE) { // just loop } } catch (final FileNotFoundException ignored) { LOG.warning("Auxclasspath entry " + url.toString() + " doesn't exist, ignoring it"); } catch (final IOException e) { // Can this even happen? LOG.log(Level.SEVERE, "Incremental analysis can't check auxclasspath contents", e); throw new RuntimeException(e); } } return adler32.getValue(); }
private static long computeFileChecksum(final File sourceFile) { try ( CheckedInputStream stream = new CheckedInputStream( new BufferedInputStream(Files.newInputStream(sourceFile.toPath())), new Adler32()); ) { // Just read it, the CheckedInputStream will update the checksum on it's own IOUtils.skipFully(stream, sourceFile.length()); return stream.getChecksum().getValue(); } catch (final IOException ignored) { // We don't really care, if it's unreadable // the analysis will fail and report the error on it's own since the checksum won't match } return 0; }
@Override public Checksum get() { return new Adler32(); } };
byte[] bytes = "some data".getBytes(); // Compute Adler-32 checksum Checksum checksumEngine = new Adler32(); checksumEngine.update(bytes, 0, bytes.length); long checksum = checksumEngine.getValue(); // Compute CRC-32 checksum checksumEngine = new CRC32(); checksumEngine.update(bytes, 0, bytes.length); checksum = checksumEngine.getValue(); // The checksum engine can be reused again for a different byte array by calling reset() checksumEngine.reset();
/** * Update this {@code Adler32} checksum using the contents of {@code buf}. * * @param buf * bytes to update checksum with. */ public void update(byte[] buf) { update(buf, 0, buf.length); }
@Override public void reset() { checkSumGenerator.reset(); }
public static long getChecksum(String test) { try { byte buffer[] = test.getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(buffer); CheckedInputStream cis = new CheckedInputStream(bais, new Adler32()); byte readBuffer[] = new byte[buffer.length]; cis.read(readBuffer); return cis.getChecksum().getValue(); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Creates a FastLZ decoder with calculation of checksums as specified. * * @param validateChecksums * If true, the checksum field will be validated against the actual * uncompressed data, and if the checksums do not match, a suitable * {@link DecompressionException} will be thrown. * Note, that in this case decoder will use {@link java.util.zip.Adler32} * as a default checksum calculator. */ public FastLzFrameDecoder(boolean validateChecksums) { this(validateChecksums ? new Adler32() : null); }
@Override public void update(byte[] input, int startIndex, int length) { checkSumGenerator.update(input, startIndex, length); }
public void init() { unencryptedLength = 0; encrypted = null; crc.reset(); } }
/** * Returns the checksum of all but the first 12 bytes of {@code dex}. */ public int computeChecksum() throws IOException { Adler32 adler32 = new Adler32(); byte[] buffer = new byte[8192]; ByteBuffer data = this.data.duplicate(); // positioned ByteBuffers aren't thread safe data.limit(data.capacity()); data.position(CHECKSUM_OFFSET + SizeOf.CHECKSUM); while (data.hasRemaining()) { int count = Math.min(buffer.length, data.remaining()); data.get(buffer, 0, count); adler32.update(buffer, 0, count); } return (int) adler32.getValue(); }