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); } }
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; }
InputArchive ia = BinaryInputArchive.getArchive(crcIn); deserialize(dt, sessions, ia); long checkSum = crcIn.getChecksum().getValue(); long val = ia.readLong("val"); if (val != checkSum) {
/** * Computes a value for a file content with the specified checksum algorithm. * @param file File object for which the value should be evaluated. * @return The value for that file */ @Override public String getValue(File file) { initChecksum(); if (file.canRead()) { checksum.reset(); try (CheckedInputStream check = new CheckedInputStream( new BufferedInputStream(Files.newInputStream(file.toPath())), checksum)) { // Read the file while (check.read() != -1) { } return Long.toString(check.getChecksum().getValue()); } catch (Exception ignored) { } } return null; }
} while ( readSize >= 0 ); checksum = cis.getChecksum().getValue();
readSize = cis.read( buf ); } while ( readSize >= 0 ); checksum = cis.getChecksum().getValue();
InputArchive ia = BinaryInputArchive.getArchive(crcIn); deserialize(dt,sessions, ia); long checkSum = crcIn.getChecksum().getValue(); long val = ia.readLong("val"); if (val != checkSum) {
Element ruleSetElement = document.getDocumentElement(); RuleSetBuilder ruleSetBuilder = new RuleSetBuilder(inputStream.getChecksum().getValue()) .withFileName(ruleSetReferenceId.getRuleSetFileName());
/** return if checksum matches for a snapshot **/ private boolean getCheckSum(FileSnap snap, File snapFile) throws IOException { DataTree dt = new DataTree(); Map<Long, Integer> sessions = new ConcurrentHashMap<Long, Integer>(); InputStream snapIS = new BufferedInputStream(new FileInputStream( snapFile)); CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32()); InputArchive ia = BinaryInputArchive.getArchive(crcIn); try { snap.deserialize(dt, sessions, ia); } catch (IOException ie) { // we failed on the most recent snapshot // must be incomplete // try reading the next one // after corrupting snapIS.close(); crcIn.close(); throw ie; } long checksum = crcIn.getChecksum().getValue(); long val = ia.readLong("val"); snapIS.close(); crcIn.close(); return (val != checksum); }
final long checksumResult = in.getChecksum().getValue(); if (checksumResult == states.get(filePath).getExpectedRecoveryChecksum()) {
StreamUtils.copy(in, new NullOutputStream(), position); final long checksumResult = in.getChecksum().getValue(); if (checksumResult == expectedChecksum) { getLogger().debug("Checksum for {} matched expected checksum. Will skip first {} bytes", new Object[]{firstFile, position});
public static Long getCRCValue(InputStream inputStream) { if (inputStream instanceof CheckedInputStream) { return ((CheckedInputStream) inputStream).getChecksum().getValue(); } return null; }
private long computeChecksum(File file) throws IOException { CheckedInputStream checkedInput = new CheckedInputStream(new FileInputStream(file), new CRC32()); try { while (checkedInput.read() > -1); } finally { checkedInput.close(); } return checkedInput.getChecksum().getValue(); }
private long computeChecksum(File file) throws IOException { CheckedInputStream checkedInput = new CheckedInputStream(new FileInputStream(file), new CRC32()); try { while (checkedInput.read() > -1); } finally { checkedInput.close(); } return checkedInput.getChecksum().getValue(); }
public static long calcCRC(InputStream in) { CheckedInputStream cis = new CheckedInputStream(in, new CRC32()); byte[] buf = new byte[1024]; try { while(cis.read(buf) >= 0) { } } catch (IOException e) { throw new OkapiIOException(e); } return cis.getChecksum().getValue(); }
public void validate() throws IOException { CheckedInputStream checkedInputStream = new CheckedInputStream(dataReader, checksum); byte[] chunk = new byte[64 * 1024]; while( checkedInputStream.read(chunk) > 0 ) { } long calculatedDigestValue = checkedInputStream.getChecksum().getValue(); if (storedDigestValue != calculatedDigestValue) { throw new IOException("Corrupted SSTable : " + descriptor.filenameFor(Component.DATA)); } }
public void validate() throws IOException { CheckedInputStream checkedInputStream = new CheckedInputStream(dataReader, checksum); byte[] chunk = new byte[64 * 1024]; while( checkedInputStream.read(chunk) > 0 ) { } long calculatedDigestValue = checkedInputStream.getChecksum().getValue(); if (storedDigestValue != calculatedDigestValue) { throw new IOException("Corrupted SSTable : " + descriptor.filenameFor(Component.DATA)); } }
public void validate() throws IOException { CheckedInputStream checkedInputStream = new CheckedInputStream(dataReader, checksum); byte[] chunk = new byte[64 * 1024]; while( checkedInputStream.read(chunk) > 0 ) { } long calculatedDigestValue = checkedInputStream.getChecksum().getValue(); if (storedDigestValue != calculatedDigestValue) { throw new IOException("Corrupted SSTable : " + descriptor.filenameFor(Component.DATA)); } }
public static <ResultType extends GenericResult> void setCRC(ResultType result, ResponseMessage response) { InputStream inputStream = response.getRequest().getContent(); if (inputStream instanceof CheckedInputStream) { CheckedInputStream checkedInputStream = (CheckedInputStream) inputStream; result.setClientCRC(checkedInputStream.getChecksum().getValue()); } String strSrvCrc = response.getHeaders().get(OSSHeaders.OSS_HASH_CRC64_ECMA); if (strSrvCrc != null) { BigInteger bi = new BigInteger(strSrvCrc); result.setServerCRC(bi.longValue()); } }
private void writeTrailer(final byte[] buf, final int offset) { writeInt((int) ((CheckedInputStream) in).getChecksum().getValue(), buf, offset); // CRC-32 of uncompr. data writeInt(compressor.getTotalIn(), buf, offset + 4); // Number of uncompr. bytes } }