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"); }
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(); }
/** Prints entry information. */ void printEntry(ZipEntry e) throws IOException { if (vflag) { StringBuilder sb = new StringBuilder(); String s = Long.toString(e.getSize()); for (int i = 6 - s.length(); i > 0; --i) { sb.append(' '); } sb.append(s).append(' ').append(new Date(e.getTime()).toString()); sb.append(' ').append(e.getName()); output(sb.toString()); } else { output(e.getName()); } }
/** Sets the total length of the file being imported. */ public void setLength(long length) { props.put(KEY_LENGTH, Long.toString(length)); }
@Override public int compare(VisorLogFile f1, VisorLogFile f2) { return Long.compare(f2.lastModified(), f1.lastModified()); }
@Override public int compare(Event o1, Event o2) { return Long.compare(o1.localOrder(), o2.localOrder()); }