Search in sources :

Example 1 with OffsetAndLength

use of v7db.files.spi.OffsetAndLength in project v7files by thiloplanz.

the class MongoContentStorage method getContent.

public Content getContent(ContentPointer pointer) throws IOException {
    if (pointer == null)
        return null;
    if (pointer instanceof InlineContent)
        return (Content) pointer;
    if (pointer instanceof ContentSHA) {
        ContentSHA p = (ContentSHA) pointer;
        byte[] sha = p.getSHA();
        Content base = getContent(sha);
        if (base == null)
            throw new IllegalArgumentException("base SHA not found: " + Hex.encodeHexString(sha));
        return base;
    }
    if (pointer instanceof StoredContent) {
        StoredContent p = (StoredContent) pointer;
        byte[] sha = p.getBaseSHA();
        Content base = getContent(sha);
        if (base == null)
            throw new IllegalArgumentException("base SHA not found: " + Hex.encodeHexString(sha));
        if (p.getLength() != base.getLength()) {
            return new OffsetAndLength(base, 0, p.getLength());
        }
        return base;
    }
    throw new IllegalArgumentException(pointer.getClass().toString());
}
Also used : OffsetAndLength(v7db.files.spi.OffsetAndLength) ContentSHA(v7db.files.spi.ContentSHA) InlineContent(v7db.files.spi.InlineContent) GzippedContent(v7db.files.spi.GzippedContent) Content(v7db.files.spi.Content) StoredContent(v7db.files.spi.StoredContent) InlineContent(v7db.files.spi.InlineContent) StoredContent(v7db.files.spi.StoredContent)

Aggregations

Content (v7db.files.spi.Content)1 ContentSHA (v7db.files.spi.ContentSHA)1 GzippedContent (v7db.files.spi.GzippedContent)1 InlineContent (v7db.files.spi.InlineContent)1 OffsetAndLength (v7db.files.spi.OffsetAndLength)1 StoredContent (v7db.files.spi.StoredContent)1