Refine search
int bytesRead; byte[] buffer = new byte[1024]; CRC32 crc = new CRC32(); 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) {
/** * 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(); }
/** * @param crcAlgo CRC algorithm. * @param buf Input buffer. * @param len Buffer length. * * @return Crc checksum. */ private static int calcCrc(CRC32 crcAlgo, ByteBuffer buf, int len) { int initLimit = buf.limit(); buf.limit(buf.position() + len); crcAlgo.update(buf); buf.limit(initLimit); return (int)crcAlgo.getValue() ^ 0xFFFFFFFF; } }
/** 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()); }
channel.write(ByteBuffer.wrap(headerBytes)); final CRC32 crc32 = new CRC32(); crc32.update(headerBytes); .putInt((int) crc32.getValue()); crc32.reset(); crc32.update(bb.array(), SevenZFile.sevenZSignature.length + 6, 20); bb.putInt(SevenZFile.sevenZSignature.length + 2, (int) crc32.getValue()); bb.flip(); channel.write(bb);
/** * 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</code> * @return the checksum value * @throws NullPointerException if the file or checksum is <code>null</code> * @throws IllegalArgumentException if the file is a directory * @throws IOException if an IO error occurs reading the file * @since Commons IO 1.3 */ public static long checksumCRC32(File file) throws IOException { CRC32 crc = new CRC32(); checksum(file, crc); return crc.getValue(); }
/** 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()); }
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;
public static long getFileCrc32(File file) throws IOException { InputStream inputStream = null; try { inputStream = new BufferedInputStream(new FileInputStream(file)); CRC32 crc = new CRC32(); int cnt; while ((cnt = inputStream.read()) != -1) { crc.update(cnt); } return crc.getValue(); } finally { StreamUtil.closeQuietly(inputStream); } }
/** * Writes all necessary data for this entry. * * @since 1.1 * @throws IOException on error * @throws Zip64RequiredException if the entry's uncompressed or * compressed size exceeds 4 GByte and {@link #setUseZip64} * is {@link Zip64Mode#Never}. */ public void closeEntry() throws IOException { preClose(); flushDeflater(); final Zip64Mode effectiveMode = getEffectiveZip64Mode(entry.entry); long bytesWritten = written - entry.dataStart; long realCrc = crc.getValue(); crc.reset(); final boolean actuallyNeedsZip64 = handleSizesAndCrc(bytesWritten, realCrc, effectiveMode); closeEntry(actuallyNeedsZip64); }