本文整理了Java中org.modeshape.jcr.api.Binary.getHexHash()
方法的一些代码示例,展示了Binary.getHexHash()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Binary.getHexHash()
方法的具体详情如下:
包路径:org.modeshape.jcr.api.Binary
类名称:Binary
方法名:getHexHash
[英]Get the hexadecimal form of the SHA-1 hash of the contents. This hash can be used to determine whether two Binary instances contain the same content.
Repeatedly calling this method should generally be efficient, as it most implementations will compute the hash only once.
[中]获取内容的SHA-1哈希的十六进制形式。此哈希可用于确定两个二进制实例是否包含相同的内容。
重复调用此方法通常是有效的,因为大多数实现只会计算一次哈希。
代码示例来源:origin: ModeShape/modeshape
/**
* Get the hexadecimal form of the SHA-1 hash of the contents.
*
* @return the hexadecimal form of hash, or a null string if the hash could not be computed or is not known
*/
private String getHash() {
try {
Node contentNode = getContextNode();
Property data = contentNode.getProperty(Property.JCR_DATA);
Binary bin = (Binary) data.getBinary();
return String.format("{%s}%s", HASH_ALGORITHM, bin.getHexHash());
} catch (RepositoryException e) {
return "";
}
}
}
代码示例来源:origin: org.fcrepo/fcrepo-kernel-modeshape
/**
* Add necessary information to node
* @param dsNode The target binary node to add information to
* @param descNode The description node associated with the binary node
* @param checksums The checksum information
* @throws RepositoryException on error
*/
private static void decorateContentNode(final Node dsNode, final Node descNode, final Collection<URI> checksums)
throws RepositoryException {
if (dsNode == null) {
LOGGER.warn("{} node appears to be null!", JCR_CONTENT);
return;
}
if (dsNode.hasProperty(JCR_DATA)) {
final Property dataProperty = dsNode.getProperty(JCR_DATA);
final Binary binary = (Binary) dataProperty.getBinary();
final String dsChecksum = binary.getHexHash();
checksums.add(ContentDigest.asURI(SHA1.algorithm, dsChecksum));
final String[] checksumArray = new String[checksums.size()];
checksums.stream().map(Object::toString).collect(Collectors.toSet()).toArray(checksumArray);
if (descNode != null) {
descNode.setProperty(CONTENT_DIGEST, checksumArray);
descNode.setProperty(CONTENT_SIZE, dataProperty.getLength());
}
LOGGER.debug("Decorated data property at path: {}", dataProperty.getPath());
}
}
代码示例来源:origin: org.fcrepo/fcrepo-kernel-modeshape
final String dsSHA1 = ((Binary) dataProperty.getBinary()).getHexHash();
final URI dsSHA1Uri = ContentDigest.asURI(SHA1.algorithm, dsSHA1);
代码示例来源:origin: org.fcrepo/modeshape-jcr
sha1 = fieldValue.toString();
} else if (fieldValue instanceof org.modeshape.jcr.api.Binary && !(fieldValue instanceof InMemoryBinaryValue)) {
sha1 = ((org.modeshape.jcr.api.Binary)fieldValue).getHexHash();
代码示例来源:origin: ModeShape/modeshape
sha1 = fieldValue.toString();
} else if (fieldValue instanceof org.modeshape.jcr.api.Binary && !(fieldValue instanceof InMemoryBinaryValue)) {
sha1 = ((org.modeshape.jcr.api.Binary)fieldValue).getHexHash();
代码示例来源:origin: ModeShape/modeshape
private void assertLargeFile(String childName) throws RepositoryException {
Session session = (Session)testRoot.getSession();
String path = testRoot.getPath() + "/" + childName;
Node files = session.getNode(path);
assertThat(files.getName(), is(childName));
assertThat(files.getPrimaryNodeType().getName(), is("nt:folder"));
long before = System.currentTimeMillis();
Node node1 = session.getNode(path + "/large-file1.png");
long after = System.currentTimeMillis();
long elapsed = after - before;
assertThat(node1.getName(), is("large-file1.png"));
assertThat(node1.getPrimaryNodeType().getName(), is("nt:file"));
before = System.currentTimeMillis();
Node node1Content = node1.getNode("jcr:content");
after = System.currentTimeMillis();
elapsed = after - before;
assertThat(node1Content.getName(), is("jcr:content"));
assertThat(node1Content.getPrimaryNodeType().getName(), is("nt:resource"));
Binary binary = (Binary)node1Content.getProperty("jcr:data").getBinary();
before = System.currentTimeMillis();
String dsChecksum = binary.getHexHash();
after = System.currentTimeMillis();
assertThat(dsChecksum, is(notNullValue()));
elapsed = after - before;
before = System.currentTimeMillis();
dsChecksum = binary.getHexHash();
after = System.currentTimeMillis();
elapsed = after - before;
assertTrue(elapsed < 1000);
}
代码示例来源:origin: ModeShape/modeshape
@Test
public void shouldCreateTrashFilesForUnusedBinaries() throws Exception {
Set<String> storedSha1s = new HashSet<String>();
for (int i = 0; i != CONTENT.length; ++i) {
Binary binary = storeAndCheck(i);
if (binary instanceof StoredBinaryValue) storedSha1s.add(binary.getHexHash());
}
// Make sure there are files for all stored values ...
assertThat(countStoredFiles(), is(storedSha1s.size()));
assertThat(countTrashFiles(), is(0));
// Mark one of the files as being unused ...
String unused = storedSha1s.iterator().next();
store.markAsUnused(Collections.singleton(new BinaryKey(unused)));
// Make sure the trash file was created
assertThat(countStoredFiles(), is(storedSha1s.size()));
assertThat(countTrashFiles(), is(1));
// Check that the name of the trash file is the SHA1
File trashFile = collectFiles(trash).get(0);
assertNotNull(trashFile);
assertEquals(unused, trashFile.getName());
Thread.sleep(1100L); // Sleep more than a second, since modified times may only be accurate to nearest second ...
store.removeValuesUnusedLongerThan(1, TimeUnit.SECONDS);
// Make sure the file was removed from the trash ...
assertThat(countStoredFiles(), is(storedSha1s.size() - 1));
assertThat(countTrashFiles(), is(0));
// And that all directories in the trash were removed (since they should be empty) ...
assertThat(trash.listFiles().length, is(0));
}
代码示例来源:origin: org.modeshape/modeshape-sequencer-teiid
protected VdbManifest readManifest(Binary binaryValue, InputStream inputStream, Node outputNode, Context context) throws Exception {
VdbManifest manifest;
LOGGER.debug("----before reading vdb.xml");
manifest = VdbManifest.read(inputStream, context);
assert (manifest != null) : "manifest is null";
// Create the output node for the VDB ...
outputNode.setPrimaryType(VdbLexicon.Vdb.VIRTUAL_DATABASE);
outputNode.addMixin(JcrConstants.MIX_REFERENCEABLE);
outputNode.setProperty(VdbLexicon.Vdb.VERSION, manifest.getVersion());
outputNode.setProperty(VdbLexicon.Vdb.ORIGINAL_FILE, outputNode.getPath());
outputNode.setProperty(JcrConstants.MODE_SHA1, ((org.modeshape.jcr.api.Binary)binaryValue).getHexHash());
setProperty(outputNode, VdbLexicon.Vdb.NAME, manifest.getName());
setProperty(outputNode, VdbLexicon.Vdb.DESCRIPTION, manifest.getDescription());
setProperty(outputNode, VdbLexicon.Vdb.CONNECTION_TYPE, manifest.getConnectionType());
// create imported VDBs child nodes
sequenceImportVdbs(manifest, outputNode);
// create translator child nodes
sequenceTranslators(manifest, outputNode);
// create data role child nodes
sequenceDataRoles(manifest, outputNode);
// create entry child nodes
sequenceEntries(manifest, outputNode);
// create properties child nodes
sequenceProperties(manifest, outputNode);
// create child nodes for declarative models
sequenceDeclarativeModels(manifest, outputNode);
LOGGER.debug(">>>>done reading vdb.xml\n\n");
return manifest;
}
代码示例来源:origin: org.teiid.modeshape/teiid-modeshape-sequencer-vdb
outputNode.setProperty( JcrConstants.MODE_SHA1, ( ( org.modeshape.jcr.api.Binary )binaryValue ).getHexHash() );
代码示例来源:origin: ModeShape/modeshape
protected Binary storeAndCheck( int contentIndex,
Class<? extends Binary> valueClass ) throws Exception {
String content = CONTENT[contentIndex];
String sha1 = CONTENT_HASHES[contentIndex];
InputStream stream = new ByteArrayInputStream(content.getBytes());
Stopwatch sw = new Stopwatch();
sw.start();
Binary binary = store.storeValue(stream, false);
sw.stop();
if (print) System.out.println("Time to store 18MB file: " + sw.getTotalDuration());
if (valueClass != null) {
assertThat(binary, is(instanceOf(valueClass)));
}
if (content.length() == 0) {
assertThat(binary, is(instanceOf(EmptyBinaryValue.class)));
} else if (content.length() < MIN_BINARY_SIZE) {
assertThat(binary, is(instanceOf(InMemoryBinaryValue.class)));
} else {
assertThat(binary, is(instanceOf(StoredBinaryValue.class)));
}
assertThat(binary.getHexHash(), is(sha1));
String binaryContent = IoUtil.read(binary.getStream());
assertThat(binaryContent, is(content));
return binary;
}
代码示例来源:origin: ModeShape/modeshape
assertThat(binary, is(instanceOf(StoredBinaryValue.class)));
assertThat(binary.getHexHash(), is(expectedSha1));
assertThat(binary.getSize(), is(numBytes));
代码示例来源:origin: ModeShape/modeshape
String unused = binaries.iterator().next().getHexHash();
BinaryKey unusedKey = new BinaryKey(unused);
store.markAsUnused(Collections.singleton(unusedKey));
内容来源于网络,如有侵权,请联系作者删除!