Example usage for org.apache.commons.codec.digest DigestUtils sha

List of usage examples for org.apache.commons.codec.digest DigestUtils sha

Introduction

In this page you can find the example usage for org.apache.commons.codec.digest DigestUtils sha.

Prototype

@Deprecated
    public static byte[] sha(String data) 

Source Link

Usage

From source file:v7db.files.mongodb.MongoReferenceTrackingTest.java

public void testPurge() throws MongoException, IOException, DecoderException {
    Mongo mongo = getMongo();/*  www  .  ja va 2s .  c  o  m*/

    DBCollection contents = mongo.getDB("test").getCollection("v7files.content");
    ContentStorage storage = new MongoContentStorage(contents);

    byte[] data = "abcdefghijklmnopqrstuvwxyz".getBytes();

    ContentPointer pointer = storage.storeContent(new ByteArrayInputStream(data));

    DBCollection references = mongo.getDB("test").getCollection("v7files.refs");
    ReferenceTracking refs = new MongoReferenceTracking(references);

    Object owner = new DBRef(null, "test", "test");

    refs.updateReferences(owner, pointer);

    refs.purge(owner);

    SimpleGarbageCollector.purge(contents, references);

    assertMockMongoDoesNotContainDocument("test.v7files.refs", owner);
    assertMockMongoDoesNotContainDocument("test.v7files.content", DigestUtils.sha(data));

    mongo.close();
}

From source file:v7db.files.spi.ContentSHA.java

public static ContentSHA calculate(byte[] data) {
    return new ContentSHA(DigestUtils.sha(data), data.length);
}

From source file:v7db.files.spi.ContentSHA.java

public static ContentSHA calculate(byte[] data, int offset, int length) {
    try {//from   w  w w  . j a va 2  s  .  c om
        return new ContentSHA(DigestUtils.sha(new ByteArrayInputStream(data, offset, length)), length);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:v7db.files.spi.ContentSHA.java

public boolean contentEquals(ContentPointer otherContent) {
    if (otherContent == null || otherContent.getLength() != length)
        return false;
    if (otherContent instanceof ContentSHA)
        return Arrays.equals(sha, ((ContentSHA) otherContent).sha);
    if (otherContent instanceof StoredContent) {
        StoredContent s = (StoredContent) otherContent;
        return s.getOffset() == 0 && Arrays.equals(s.getBaseSHA(), sha);
    }/*w w  w  . j av  a 2s  .  co m*/
    if (otherContent instanceof InlineContent)
        try {
            return Arrays.equals(sha, DigestUtils.sha(((InlineContent) otherContent).getInputStream()));
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    return false;
}

From source file:v7db.files.spi.InlineContent.java

public byte[] getSHA() {
    if (sha != null)
        return sha.clone();
    try {//  www .  ja  v a  2 s .c  o  m
        sha = DigestUtils.sha(getInputStream());
        return sha.clone();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:v7db.files.spi.StoredContent.java

public boolean contentEquals(ContentPointer otherContent) {
    if (otherContent == null || otherContent.getLength() != length)
        return false;
    if (otherContent instanceof StoredContent) {
        StoredContent sc = (StoredContent) otherContent;
        return getOffset() == sc.getOffset() && Arrays.equals(sha, sc.sha);
    }/*from w  w  w .  j a  v  a  2  s .co  m*/
    if (otherContent instanceof InlineContent)
        try {
            return Arrays.equals(sha, DigestUtils.sha(((InlineContent) otherContent).getInputStream()));
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    return false;
}