private InputStream retrieveInputStream() throws RepositoryException { if(entryNode.hasNode(JCRHttpCacheStoreConstants.PATH_CONTENTS)){ final Node contentsNode = entryNode.getNode(JCRHttpCacheStoreConstants.PATH_CONTENTS); final Node jcrContent = contentsNode.getNode(JcrConstants.JCR_CONTENT); final Property binaryProperty = jcrContent.getProperty(JcrConstants.JCR_DATA); binary = binaryProperty.getBinary(); return binary.getStream(); } return null; }
@Override public InputStream getResourceContent( Node node ) throws RepositoryException { if (!node.hasNode(CONTENT_NODE_NAME)) return null; return node.getProperty(CONTENT_NODE_NAME + "/" + DATA_PROP_NAME).getBinary().getStream(); }
public static InputStream getNTFileAsInputStream(final Resource resource) throws RepositoryException { final Node node = resource.adaptTo(Node.class); final Node jcrContent = node.getNode(JcrConstants.JCR_CONTENT); return jcrContent.getProperty(JcrConstants.JCR_DATA).getBinary().getStream(); }
public static InputStream getNTFileAsInputStream(final Resource resource) throws RepositoryException { final Node node = resource.adaptTo(Node.class); final Node jcrContent = node.getNode(JcrConstants.JCR_CONTENT); return jcrContent.getProperty(JcrConstants.JCR_DATA).getBinary().getStream(); }
private InputStream getInputStream() { Property prop = getProperty(); try { return prop.getBinary().getStream(); } catch (RepositoryException re) { LOGGER.error("getInputStream: Problem accessing the property " + getPath() + " stream", re); } // fall back to none in case of an error return null; }
public long getSize() { int size = 0; final Property p = renditionData.getValueMap().get(JCR_DATA, Property.class); try { return (null != p) ? p.getBinary().getSize() : 0; } catch (RepositoryException e) { LOG.error("Failed to get the Rendition binary size in bytes [{}]: ", getPath(), e); } return size; } }
/** Retrieves the Binary from the jcr:data of an nt:file */ public static Binary getBinary(Session session, String ntFilePath) throws RepositoryException { return session.getNode(ntFilePath) .getNode(JcrConstants.JCR_CONTENT) .getProperty(JcrConstants.JCR_DATA) .getBinary(); }
@Override public InputStream getContentStream() { try { Node node = AssetNodeTypes.AssetResource.getResourceNodeFromAsset(getNode()); if (node != null) { return node.getProperty(AssetNodeTypes.AssetResource.DATA).getBinary().getStream(); } } catch (RepositoryException e) { throw new RuntimeRepositoryException(e); } return null; }
private boolean equalBinaryContents(Node binaryNode, Resource binaryResource) throws RepositoryException { try (final InputStream nodeStream = binaryNode.getProperty(JcrConstants.JCR_DATA).getBinary().getStream(); final InputStream resourceStream = binaryResource.openStream()) { return IOUtils.contentEquals(nodeStream, resourceStream); } catch (IOException e) { log.error("Cannot read contents of '{}:{}'.", binaryResource.getOrigin().getName(), binaryResource.getName(), e); } return false; }
@Override public boolean execute( Property inputProperty, Node outputNode, Context context ) throws Exception { Binary binaryValue = inputProperty.getBinary(); CheckArg.isNotNull(binaryValue, "binary"); try (InputStream stream = binaryValue.getStream()) { ClassMetadata classMetadata = ClassFileMetadataReader.instance(stream); classFileRecorder.recordClass(context, outputNode, classMetadata); return true; } }
@Override public boolean execute( Property inputProperty, Node outputNode, Context context ) throws Exception { Binary binaryValue = inputProperty.getBinary(); CheckArg.isNotNull(binaryValue, "binary"); try (InputStream stream = binaryValue.getStream()) { ClassMetadata classMetadata = ClassFileMetadataReader.instance(stream); classFileRecorder.recordClass(context, outputNode, classMetadata); return true; } }
@Override public boolean execute( Property inputProperty, Node outputNode, Context context ) throws Exception { Binary binaryValue = (Binary) inputProperty.getBinary(); CheckArg.isNotNull(binaryValue, "binary"); String mimeType = binaryValue.getMimeType(); Node sequencedNode = getMetadataNode(outputNode); setPropertyIfMetadataPresent(sequencedNode, JcrConstants.JCR_MIME_TYPE, mimeType); return processBasicMetadata(sequencedNode, binaryValue); }
protected void checkProperty(Property prop) throws Exception { for (int i = 0; i < 3; i++) { Binary b = prop.getBinary(); try { //System.out.println(b.getClass() + ": " + System.identityHashCode(b)); b.read(new byte[1], 0); } finally { b.dispose(); } } } }
@Override public boolean execute( Property inputProperty, Node outputNode, Context context ) throws Exception { Binary binaryValue = (Binary) inputProperty.getBinary(); CheckArg.isNotNull(binaryValue, "binary"); String mimeType = binaryValue.getMimeType(); Node sequencedNode = getMetadataNode(outputNode); setPropertyIfMetadataPresent(sequencedNode, JcrConstants.JCR_MIME_TYPE, mimeType); return processBasicMetadata(sequencedNode, binaryValue); }
@Override public boolean execute( Property inputProperty, Node outputNode, Context context ) throws Exception { Binary binaryValue = (Binary) inputProperty.getBinary(); CheckArg.isNotNull(binaryValue, "binary"); String mimeType = binaryValue.getMimeType(); Node sequencedNode = getMetadataNode(outputNode); setPropertyIfMetadataPresent(sequencedNode, JcrConstants.JCR_MIME_TYPE, mimeType); return processBasicMetadata(sequencedNode, binaryValue); }
public void testCopyJson() throws Exception { Node test = createJsonNode("test.json"); test.getSession().getWorkspace().copy(test.getPath(), test.getParent().getPath() + "/target.json"); Session s = getHelper().getReadOnlySession(); try { Property p = s.getNode(testRoot).getNode("target.json").getNode(JcrConstants.JCR_CONTENT) .getProperty(JcrConstants.JCR_DATA); assertEquals(jsondata, IOUtils.toString(p.getBinary().getStream(), "UTF-8")); } finally { s.logout(); } }
public void testCreateJson() throws Exception { createJsonNode("test.json"); Session s = getHelper().getReadOnlySession(); try { Property p = s.getNode(testRoot).getNode("test.json").getNode(JcrConstants.JCR_CONTENT) .getProperty(JcrConstants.JCR_DATA); assertEquals(jsondata, IOUtils.toString(p.getBinary().getStream(), "UTF-8")); } finally { s.logout(); } }
public void testGetBinary() throws RepositoryException, IOException { Binary binary = prop.getBinary(); byte[] bytes = new byte[(int) binary.getSize()]; binary.read(bytes, 0); binary.dispose(); assertEquals(prop.getString(), new String(bytes, "UTF-8")); }
private void readLargeBinary() throws Exception { Node commit = session.getNode("/repos/git-modeshape-remote/tree/master/modeshape-jcr/src/test/resources/docs/postgresql-8.4.1-US.pdf"); assertNotNull(commit); Binary data = commit.getNode("jcr:content").getProperty("jcr:data").getBinary(); long size = data.getSize(); assertTrue(size > 0); //simply read the stream to make sure it's valid ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(baos); IoUtil.write(data.getStream(), bos); assertEquals("invalid binary stream", size, baos.toByteArray().length); }
private InputStream storeBinaryProperty( byte[] data, String nodeName ) throws RepositoryException { Node testRoot = jcrSession().getRootNode().addNode(nodeName); testRoot.setProperty("binary", session.getValueFactory().createValue(new ByteArrayInputStream(data))); jcrSession().save(); Property binary = jcrSession().getNode("/" + nodeName).getProperty("binary"); Assert.assertNotNull(binary); return binary.getBinary().getStream(); }