Package javax.jcr

Examples of javax.jcr.Binary


     * mechanism to provide random access defined on {@link Binary}.
     *
     * @see QValue#getBinary()
     */
    public Binary getBinary() throws RepositoryException {
        return new Binary() {
            public InputStream getStream() throws RepositoryException {
                return AbstractQValue.this.getStream();
            }

            public int read(byte[] b, long position) throws IOException, RepositoryException {
View Full Code Here


     * {{@link #toString(Item)} method.
     */
    private static void append(StringBuilder builder, Value value)
            throws RepositoryException {
        if (value.getType() == PropertyType.BINARY) {
            Binary binary = value.getBinary();
            try {
                builder.append("<");
                builder.append(binary.getSize());
                builder.append(" bytes>");
            } finally {
                binary.dispose();
            }
        } else {
            String string = value.getString();
            if (string.length() > 40) {
                builder.append(string.substring(0, 37));
View Full Code Here

    /** Wrapper around {@link #setProperty(String, Value)} */
    public Property setProperty(String name, InputStream value)
            throws RepositoryException {
        if (value != null) {
            Binary binary = getValueFactory().createBinary(value);
            try {
                return setProperty(name, getValueFactory().createValue(binary));
            } finally {
                binary.dispose();
            }
        } else {
            return setProperty(name, (Value) null);
        }
    }
View Full Code Here

        InputStreamWrapper in = new InputStreamWrapper(new ByteArrayInputStream(binaryValue));
        valueFactory.createValue(in);
        assertTrue("ValueFactory.createValue(InputStream) is expected to close the passed input stream", in.isClosed());

        in = new InputStreamWrapper(new ByteArrayInputStream(binaryValue));
        Binary bin = valueFactory.createBinary(in);
        assertTrue("ValueFactory.createBinary(InputStream) is expected to close the passed input stream", in.isClosed());
        bin.dispose();
    }
View Full Code Here

     *                             or updated
     */
    public static Node putFile(
            Node parent, String name, String mime,
            InputStream data, Calendar date) throws RepositoryException {
        Binary binary = parent.getSession().getValueFactory().createBinary(data);
        try {
            Node file = getOrAddNode(parent, name, NodeType.NT_FILE);
            Node content = getOrAddNode(file, Node.JCR_CONTENT, NodeType.NT_RESOURCE);

            content.setProperty(Property.JCR_MIMETYPE, mime);
            String[] parameters = mime.split(";");
            for (int i = 1; i < parameters.length; i++) {
                int equals = parameters[i].indexOf('=');
                if (equals != -1) {
                    String parameter = parameters[i].substring(0, equals);
                    if ("charset".equalsIgnoreCase(parameter.trim())) {
                        content.setProperty(
                                Property.JCR_ENCODING,
                                parameters[i].substring(equals + 1).trim());
                    }
                }
            }

            content.setProperty(Property.JCR_LAST_MODIFIED, date);
            content.setProperty(Property.JCR_DATA, binary);
            return file;
        } finally {
            binary.dispose();
        }
    }
View Full Code Here

     * @throws RepositoryException if the file can not be accessed
     */
    public InputStream readFile(Node node) throws RepositoryException {
        if (node.hasProperty(Property.JCR_DATA)) {
            Property data = node.getProperty(Property.JCR_DATA);
            final Binary binary = data.getBinary();
            return new FilterInputStream(binary.getStream()) {
                @Override
                public void close() throws IOException {
                    super.close();
                    binary.dispose();
                }
            };
        } else if (node.hasNode(Node.JCR_CONTENT)) {
            return readFile(node.getNode(Node.JCR_CONTENT));
        } else {
View Full Code Here

    }

    public void testRevertSettingExistingBinary() throws Exception {
        Node test = testRootNode.addNode("test");

        Binary b = superuser.getValueFactory().createBinary(generateValue());
        Property p = test.setProperty("prop", b);
        QValue qv1 = getQValue(p);
        superuser.save();

        Binary b2 = superuser.getValueFactory().createBinary(generateValue());
        test.setProperty("prop", b2);
        QValue qv2 = getQValue(p);

        assertFalse(qv1.equals(qv2));
View Full Code Here

        assertFalse(qv2.equals(getQValue(p)));
    }

    protected void checkBinary(Property p) throws Exception {
        for (int i = 0; i < 3; i++) {
            Binary bin = p.getBinary();
            try {
                //System.out.println(bin.getClass() + "@" + System.identityHashCode(bin));
                bin.read(new byte[1], 0);
            } finally {
                bin.dispose();
            }
        }
    }
View Full Code Here

      break;
    case BINARY: {
        Object obj = element.getObject(name);
        if (obj == null) return null;
        if (obj instanceof InputStream) {
          Binary binary = node.getSession().getValueFactory().createBinary((InputStream)obj);
          value = node.getSession().getValueFactory().createValue(binary);
        } else
        if (obj instanceof String) {
          Binary binary = node.getSession().getValueFactory().createBinary(new StringInputStream((String)obj));
          value = node.getSession().getValueFactory().createValue(binary);
        }
      }
      break;
    case ELEMENT: {
View Full Code Here

     * (do NOT use text).
     */
    public PackageItem updateCompiledPackage(InputStream data) {
        checkout();
        try {
          Binary binary = this.node.getSession().getValueFactory().createBinary(data);
            this.node.setProperty( COMPILED_PACKAGE_PROPERTY_NAME, binary );
            this.node.setProperty( LAST_MODIFIED_PROPERTY_NAME,
                                   Calendar.getInstance() );
            return this;
        } catch (RepositoryException e ) {
View Full Code Here

TOP

Related Classes of javax.jcr.Binary

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.