use of org.apache.jackrabbit.oak.plugins.memory.AbstractBlob in project jackrabbit-oak by apache.
the class JackrabbitNodeState method createBlob.
private Blob createBlob(final InternalValue value) {
checkArgument(checkNotNull(value).getType() == PropertyType.BINARY);
return new AbstractBlob() {
@Override
public long length() {
try {
return value.getLength();
} catch (RepositoryException e) {
warn("Unable to access blob length", e);
return 0;
}
}
@Nonnull
@Override
public InputStream getNewStream() {
try {
return value.getStream();
} catch (RepositoryException e) {
warn("Unable to access blob contents", e);
return new ByteArrayInputStream(new byte[0]);
}
}
@Override
public String getReference() {
if (!useBinaryReferences) {
return null;
}
try {
Binary binary = value.getBinary();
try {
if (binary instanceof ReferenceBinary) {
return ((ReferenceBinary) binary).getReference();
} else {
return null;
}
} finally {
binary.dispose();
}
} catch (RepositoryException e) {
warn("Unable to get blob reference", e);
return null;
}
}
@Override
public String getContentIdentity() {
final String reference = getReference();
if (reference != null) {
final int pos = reference.indexOf(":");
final String blobHash;
if (pos > -1) {
blobHash = reference.substring(0, pos);
} else {
blobHash = reference;
}
return blobHash + "#" + length();
}
return super.getContentIdentity();
}
};
}
Aggregations