public static void main(String[] args) throws IOException {
    System.out.println("Input Stream:");
    long start = System.currentTimeMillis();
    Path filename = Paths.get(args[0]);
    long crcValue = checksumInputStream(filename);
    long end = System.currentTimeMillis();
    System.out.println(Long.toHexString(crcValue));
    System.out.println((end - start) + " milliseconds");

    System.out.println("Buffered Input Stream:");
    start = System.currentTimeMillis();
    crcValue = checksumBufferedInputStream(filename);
    end = System.currentTimeMillis();
    System.out.println(Long.toHexString(crcValue));
    System.out.println((end - start) + " milliseconds");

    System.out.println("Random Access File:");
    start = System.currentTimeMillis();
    crcValue = checksumRandomAccessFile(filename);
    end = System.currentTimeMillis();
    System.out.println(Long.toHexString(crcValue));
    System.out.println((end - start) + " milliseconds");

    System.out.println("Mapped File:");
    start = System.currentTimeMillis();
    crcValue = checksumMappedFile(filename);
    end = System.currentTimeMillis();
    System.out.println(Long.toHexString(crcValue));
    System.out.println((end - start) + " milliseconds");
  }
Esempio n. 2
0
 public static String calculateCrc32(String source) {
   CRC32 crc32 = new CRC32();
   Adler32 adler32 = new Adler32();
   adler32.update(source.getBytes());
   System.out.println(adler32.getValue());
   crc32.update(source.getBytes());
   StringBuilder builder = new StringBuilder(8);
   System.out.println(crc32.getValue());
   System.out.println(Long.toHexString(crc32.getValue()));
   builder.append(Long.toHexString(crc32.getValue()));
   if (builder.length() < 8) {
     builder.append(CHAR_TEMPLATE, 0, 8 - builder.length());
   }
   System.out.println(builder.toString());
   return builder.toString();
 }