Package org.rabinfingerprint.fingerprint

Examples of org.rabinfingerprint.fingerprint.RabinFingerprintLong


    // Create new random irreducible polynomial
    // These can also be created from Longs or hex Strings
    Polynomial polynomial = Polynomial.createIrreducible(53);
   
    // Create a fingerprint object
    RabinFingerprintLong rabin = new RabinFingerprintLong(polynomial);
   
    // Push bytes from a file stream
    rabin.pushBytes(ByteStreams.toByteArray(new FileInputStream("file.test")));
   
    // Get fingerprint value and output
    System.out.println(Long.toString(rabin.getFingerprintLong(), 16));
  }
View Full Code Here


public class Main {

  public void fingerprintFiles(List<String> paths, Polynomial p) throws FileNotFoundException,
      IOException {
    final RabinFingerprintLong rabin = new RabinFingerprintLong(p);
    for (String path : paths) {
      File file = new File(path);
      if (file.exists()) {
        rabin.reset();
        rabin.pushBytes(ByteStreams.toByteArray(new FileInputStream(file)));
        System.out.println(String.format("%X %s", rabin.getFingerprintLong(), file.getAbsolutePath()));
        System.out.flush();
      } else {
        System.err.print(String.format("Could not find file %s", path));
        System.err.flush();
      }
View Full Code Here

      }
    }
  }

  public void fingerprintStdin(Polynomial p) throws IOException {
    final RabinFingerprintLong rabin = new RabinFingerprintLong(p);
    rabin.pushBytes(ByteStreams.toByteArray(System.in));
    System.out.println(String.format("%X", rabin.getFingerprintLong()));
  }
View Full Code Here

  private final RabinFingerprintLong finger;
  private final RabinFingerprintLongWindowed fingerWindow;
  private final ChunkBoundaryDetector boundaryDetector;

  public FingerFactory(Polynomial p, long bytesPerWindow, ChunkBoundaryDetector boundaryDetector) {
    this.finger = new RabinFingerprintLong(p);
    this.fingerWindow = new RabinFingerprintLongWindowed(p, bytesPerWindow);
    this.boundaryDetector = boundaryDetector;
  }
View Full Code Here

    this.fingerWindow = new RabinFingerprintLongWindowed(p, bytesPerWindow);
    this.boundaryDetector = boundaryDetector;
  }

  private RabinFingerprintLong newFingerprint() {
    return new RabinFingerprintLong(finger);
  }
View Full Code Here

   * efficiently discovered.
   */
  public void getChunkFingerprints(InputStream is, ChunkVisitor visitor) throws IOException {
    // windowing fingerprinter for finding chunk boundaries. this is only
    // reset at the beginning of the file
    final RabinFingerprintLong window = newWindowedFingerprint();

    // fingerprinter for chunks. this is reset after each chunk
    final RabinFingerprintLong finger = newFingerprint();

    // counters
    long chunkStart = 0;
    long chunkEnd = 0;

    /*
     * fingerprint one byte at a time. we have to use this granularity to
     * ensure that, for example, a one byte offset at the beginning of the
     * file won't effect the chunk boundaries
     */
    for (byte b : ByteStreams.toByteArray(is)) {
      // push byte into fingerprints
      window.pushByte(b);
      finger.pushByte(b);
      chunkEnd++;

      /*
       * if we've reached a boundary (which we will at some probability
       * based on the boundary pattern and the size of the fingerprint
       * window), we store the current chunk fingerprint and reset the
       * chunk fingerprinter.
       */
      if (boundaryDetector.isBoundary(window)) {
        visitor.visit(finger.getFingerprintLong(), chunkStart, chunkEnd);
        finger.reset();
       
        // store last chunk offset
        chunkStart = chunkEnd;
      }
    }

    // final chunk
    visitor.visit(finger.getFingerprintLong(), chunkStart, chunkEnd);
  }
View Full Code Here

  /**
   * Rapidly fingerprint an entire stream's contents.
   */
  public long getFullFingerprint(InputStream is) throws IOException {
    final RabinFingerprintLong finger = newFingerprint();
    finger.pushBytes(ByteStreams.toByteArray(is));
    return finger.getFingerprintLong();
  }
View Full Code Here

    random.nextBytes(data);

    // generate random irreducible polynomial
    Polynomial p = Polynomial.createIrreducible(53);
    final Fingerprint<Polynomial> rabin0 = new RabinFingerprintPolynomial(p);
    final Fingerprint<Polynomial> rabin1 = new RabinFingerprintLong(p);
    rabin0.pushBytes(data);
    rabin1.pushBytes(data);
    assertEquals(0, rabin0.getFingerprint().compareTo(rabin1.getFingerprint()));
  }
View Full Code Here

      if (usePolynomials) {
        rabin0 = new RabinFingerprintPolynomial(p, windowSize);
        rabin1 = new RabinFingerprintPolynomial(p);
      } else {
        rabin0 = new RabinFingerprintLongWindowed(p, windowSize);
        rabin1 = new RabinFingerprintLong(p);
      }

      // Generate Random Data
      byte[] data = new byte[windowSize * 5];
      random.nextBytes(data);
 
View Full Code Here

TOP

Related Classes of org.rabinfingerprint.fingerprint.RabinFingerprintLong

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.