protected void makeRegularImage(Node node, String name, InputStream istream, String mimeType, Calendar lastModified) throws RepositoryException { if (!node.hasNode(name)) { Node child = node.addNode(name); child.setProperty(JcrConstants.JCR_DATA, getValueFactory(node).createBinary(istream)); child.setProperty(JcrConstants.JCR_MIMETYPE, mimeType); child.setProperty(JcrConstants.JCR_LASTMODIFIED, lastModified); } }
private static void setEmptyHippoTextBinary(final Node node) { String nodePath = null; try { nodePath = node.getPath(); final ByteArrayInputStream emptyByteArrayInputStream = new ByteArrayInputStream(new byte[0]); node.setProperty(HippoNodeType.HIPPO_TEXT, getValueFactory(node).createBinary(emptyByteArrayInputStream)); } catch (RepositoryException e) { log.error("Unable to store empty hippo:text binary for node '"+nodePath+"'", e); } }
private void populateCacheKey() throws RepositoryException, IOException { final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); final ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(cacheKey); objectOutputStream.close(); try(ByteArrayInputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray())){ final Binary binary = session.getValueFactory().createBinary(inputStream); entryNode.setProperty(JCRHttpCacheStoreConstants.PN_CACHEKEY, binary); } } }
@Override public void initGalleryResource(Node node, InputStream data, String mimeType, String fileName, Calendar lastModified) throws GalleryException, RepositoryException { node.setProperty(JcrConstants.JCR_MIMETYPE, mimeType); node.setProperty(JcrConstants.JCR_DATA, getValueFactory(node).createBinary(data)); node.setProperty(JcrConstants.JCR_LASTMODIFIED, lastModified); }
/** * Stores the content of the given InputStream into a binary "jcr:data" property of the given Node, then closes * the InputStream. * @param is the InputStream whose contents will be stored * @param resourceNode the JCR Node where the content will be stored */ protected void storeBinary(InputStream is, Node resourceNode) throws IOException, RepositoryException { // store content as Binary BufferedInputStream bis = new BufferedInputStream(is); Binary bin = resourceNode.getSession().getValueFactory().createBinary(bis); resourceNode.setProperty(JcrConstants.JCR_DATA, bin); }
private void makeRegularImage(Node node, String name, InputStream istream, String mimeType, Calendar lastModified) throws RepositoryException { if (!node.hasNode(name)) { Node child = node.addNode(name); child.setProperty(JcrConstants.JCR_DATA, node.getSession().getValueFactory().createBinary(istream)); child.setProperty(JcrConstants.JCR_MIMETYPE, mimeType); child.setProperty(JcrConstants.JCR_LASTMODIFIED, lastModified); } }
protected void makeThumbnailImage(Node node, InputStream resourceData, String mimeType) throws RepositoryException, GalleryException { if (mimeType.startsWith("image")) { InputStream thumbNail = createThumbnail(resourceData, thumbnailSize, mimeType); node.setProperty(JcrConstants.JCR_DATA, getValueFactory(node).createBinary(thumbNail)); } else { node.setProperty(JcrConstants.JCR_DATA, getValueFactory(node).createBinary(resourceData)); } node.setProperty(JcrConstants.JCR_MIMETYPE, mimeType); }
private void setDefaultResourceProperties(Node node, String mimeType, InputStream inputStream) throws RepositoryException { try{ setDefaultResourceProperties(node, mimeType, node.getSession().getValueFactory().createBinary(inputStream)); } finally { IOUtils.closeQuietly(inputStream); } }
private javax.jcr.Value createValue(ValueFactory factory, int type, String asString) throws RepositoryException { if (type == PropertyType.BINARY) { byte[] bytes = Base64.decodeBase64(asString); final Binary binary = factory.createBinary(new ByteArrayInputStream(bytes)); return factory.createValue(binary); } else { return factory.createValue(asString, type); } } }
public void testBinaryLength() throws RepositoryException { byte[] data = "abc".getBytes(); Binary b = vf.createBinary(new ByteArrayInputStream(data)); try { node.setProperty(propertyName1, b); } finally { b.dispose(); } superuser.save(); checkOperators(propertyName1, node.getProperty(propertyName1).getLength()); }
private void addFile(Node parent, String fileName) throws RepositoryException { Node file = getOrAddNode(parent, fileName, NodeType.NT_FILE); Node content = getOrAddNode(file, Node.JCR_CONTENT, contentNodeType); content.setProperty(Property.JCR_MIMETYPE, "text/plain"); content.setProperty(Property.JCR_LAST_MODIFIED, Calendar.getInstance()); Binary binary = parent.getSession().getValueFactory().createBinary(new ByteArrayInputStream("hello".getBytes())); content.setProperty(Property.JCR_DATA, binary); binary.dispose(); }
public void testLengthBinaryLiteral() throws RepositoryException { node.setProperty(propertyName1, "abc"); superuser.save(); String length = String.valueOf(node.getProperty(propertyName1).getLength()); Binary b = vf.createBinary(new ByteArrayInputStream(length.getBytes())); try { executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(b)); } finally { b.dispose(); } }
/** * Serialize the given <code>object</code> into a binary JCR value. * * @param session to use * @param object to serialize * @return a binary value containing the serialized object * @throws RepositoryException */ public static Value createBinaryValueFromObject(Session session, Object object) throws RepositoryException { final ValueFactory valueFactory = session.getValueFactory(); return valueFactory.createValue(valueFactory.createBinary(new ByteArrayInputStream(objectToBytes(object)))); }
private Node createJsonNode(String name) throws RepositoryException, UnsupportedEncodingException { Node test = testRootNode.addNode(name, JcrConstants.NT_FILE); Node content = test.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE); content.setProperty(JcrConstants.JCR_DATA, test.getSession().getValueFactory().createBinary(new ByteArrayInputStream(jsondata.getBytes("UTF-8")))); test.getSession().save(); return test; } }
protected Property setProperty(Node node, int length) throws RepositoryException { Random rand = new Random(); byte[] data = new byte[length]; rand.nextBytes(data); Binary b = vf.createBinary(new ByteArrayInputStream(data)); //System.out.println(b.getClass() + ": " + System.identityHashCode(b)); try { return node.setProperty(propertyName1, b); } finally { b.dispose(); } }
/** Creates an nt:file based on the content, saves the session and retrieves the Binary value again. */ public static Binary storeBinaryAndRetrieve(Session session, String path, Content content) throws RepositoryException { Binary binary = session.getValueFactory().createBinary(content.getStream()); storeBinary(session, path, binary); return getBinary(session, path); }
@Test public void addBinaryProperty() throws RepositoryException, IOException { Node parentNode = getNode(TEST_PATH); InputStream is = new ByteArrayInputStream("foo\"".getBytes()); Binary bin = getAdminSession().getValueFactory().createBinary(is); addProperty(parentNode, "binary", getAdminSession().getValueFactory().createValue(bin)); }
@Test public void testCreateValueFromBytesArray() throws Exception { byte[] bytes = new byte[]{'a', 'b'}; ByteArrayInputStream is = new ByteArrayInputStream(bytes); Binary binary = valueFactory.createBinary(is); Value v = syncCtx.createValue(bytes); assertNotNull(v); assertEquals(PropertyType.BINARY, v.getType()); assertEquals(binary, v.getBinary()); }
@Test public void addSmallBinaryProperty() throws RepositoryException, IOException { Node parentNode = getNode(TEST_PATH); InputStream is = new NumberStream(1234); Binary bin = getAdminSession().getValueFactory().createBinary(is); addProperty(parentNode, "bigBinary", getAdminSession().getValueFactory().createValue(bin)); }
@Test public void addBigBinaryProperty() throws RepositoryException, IOException { Node parentNode = getNode(TEST_PATH); InputStream is = new NumberStream(123456); Binary bin = getAdminSession().getValueFactory().createBinary(is); addProperty(parentNode, "bigBinary", getAdminSession().getValueFactory().createValue(bin)); }