Package java.util.zip

Examples of java.util.zip.CRC32


            for (File file : files) {
                String fileName = file.getPath();
                String entryName = removeBase(basePath, fileName);
                byte[] data = readFile(file);
                ZipEntry entry = new ZipEntry(entryName);
                CRC32 crc = new CRC32();
                crc.update(data);
                entry.setSize(file.length());
                entry.setCrc(crc.getValue());
                zipOut.putNextEntry(entry);
                zipOut.write(data);
                zipOut.closeEntry();
            }
            zipOut.closeEntry();
View Full Code Here


                    break;
                }
                s.reset();
                seek(i);
                store.readFully(s.getBytes(), 0, pageSize);
                CRC32 crc = new CRC32();
                crc.update(s.getBytes(), 4, pageSize - 4);
                int expected = (int) crc.getValue();
                int got = s.readInt();
                long writeCounter = s.readLong();
                int key = s.readInt();
                int firstTrunkPage = s.readInt();
                int firstDataPage = s.readInt();
View Full Code Here

    private static class Crc32InputStream extends FilterInputStream {
        private final CRC32 checksum;

        private Crc32InputStream(InputStream inputStream) {
            super(inputStream);
            checksum = new CRC32();
        }
View Full Code Here

    private static class Crc32OutputStream extends FilterOutputStream {
        private final CRC32 checksum;

        private Crc32OutputStream(OutputStream outputStream) {
            super(outputStream);
            this.checksum = new CRC32();
        }
View Full Code Here

            if (i == 3) {
                throw DbException.get(ErrorCode.FILE_CORRUPTED_1, fileName);
            }
            page.reset();
            readPage(i, page);
            CRC32 crc = new CRC32();
            crc.update(page.getBytes(), 4, pageSize - 4);
            int expected = (int) crc.getValue();
            int got = page.readInt();
            if (expected == got) {
                writeCountBase = page.readLong();
                logKey = page.readInt();
                logFirstTrunkPage = page.readInt();
View Full Code Here

        page.writeInt(0);
        page.writeLong(getWriteCountTotal());
        page.writeInt(logKey);
        page.writeInt(logFirstTrunkPage);
        page.writeInt(logFirstDataPage);
        CRC32 crc = new CRC32();
        crc.update(page.getBytes(), 4, pageSize - 4);
        page.setInt(0, (int) crc.getValue());
        file.seek(pageSize);
        file.write(page.getBytes(), 0, pageSize);
        file.seek(pageSize + pageSize);
        file.write(page.getBytes(), 0, pageSize);
        // don't increment the write counter, because it was just written
View Full Code Here

            FileInputStream fis = new FileInputStream(fromFile);

            byte[] bytes = new byte[1024];

            int numRead;
            CRC32 checksum = new CRC32();
            while ((numRead = fis.read(bytes)) > 0) {
                zoStream.write(bytes, 0, numRead);
                checksum.update(bytes, 0, numRead);
            }
            zEntry.setCrc(checksum.getValue());

            fis.close();
            zoStream.closeEntry();

        } catch (IOException ioe) {
View Full Code Here

  public static long gzipCalculateCRC32(File src) throws IOException {
    final byte[] b = new byte[(int) Size.OneMeg.bytes()];

    final GZIPInputStream in = new GZIPInputStream(new FileInputStream(src), 100);

    final CRC32 crc = new CRC32();
   
    int count = 0;
    int length = 0;
    while ((length = in.read(b)) != -1) {
      System.out.printf("#%d: len=%d\n", count, length);
      crc.update(b, 0, length);
      count ++;
    }

    in.close();
   
    return crc.getValue();

  }
View Full Code Here

   
    String status;
    if (data.length != length) {
      status = "data.length == " + data.length + ", should be " + length;
    } else {
      CRC32 computedCrc32 = new CRC32();
      computedCrc32.update(data);
      if (computedCrc32.getValue() != crc32) {
        status = "Computed crc32 == " + computedCrc32.getValue() + ", should be " + crc32;
      } else {
        status = "OK";
      }
    }
    return status;
View Full Code Here

  public byte[] getGDSBytes() {
    return input;
  }

  public long calcCRC() {
    CRC32 crc32 = new CRC32();
    crc32.update(input);
    return crc32.getValue();
  }
View Full Code Here

TOP

Related Classes of java.util.zip.CRC32

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.