Package javax.jcr

Examples of javax.jcr.Binary


        }
    }

    private void spoolSingleValued(OutputStream out) throws IOException {
        try {
            Binary binary = ((Property) item).getBinary();
            try {
                InputStream in = binary.getStream();
                try {
                    IOUtil.spool(in, out);
                } finally {
                    in.close();
                }
            } finally {
                binary.dispose();
            }
        } catch (RepositoryException e) {
            log.error("Cannot obtain stream from " + item, e);
        }
    }
View Full Code Here


        MemoryArchive archive = new MemoryArchive(true);
        InputStreamPump pump = new InputStreamPump(in , archive);

        // this will cause the input stream to be consumed and the memory archive being initialized.
        Binary bin = session.getValueFactory().createBinary(pump);
        if (pump.getError() != null) {
            Exception error = pump.getError();
            log.error("Error while reading from input stream.", error);
            bin.dispose();
            throw new IOException("Error while reading from input stream", error);
        }

        if (archive.getJcrRoot() == null) {
            String msg = "Stream is not a content package. Missing 'jcr_root'.";
            log.error(msg);
            bin.dispose();
            throw new IOException(msg);
        }

        final MetaInf inf = archive.getMetaInf();
        PackagePropertiesImpl props = new PackagePropertiesImpl() {
            @Override
            protected Properties getPropertiesMap() {
                return inf.getProperties();
            }
        };
        PackageId pid = props.getId();

        // invalidate pid if path is unknown
        if (pid == null || pid.getInstallationPath().equals(ZipVaultPackage.UNKNOWN_PATH)) {
            bin.dispose();
            throw new IOException("Package does not contain a path specification or valid package id.");
        }
        if (!pid.isValid()) {
            throw new RepositoryException("Unable to create package. Illegal package name.");
        }

        // create parent node
        String path = pid.getInstallationPath() + ".zip";
        String parentPath = Text.getRelativeParent(path, 1);
        String name = Text.getName(path);
        Node parent = mkdir(parentPath, false);

        // remember installation state properties (GRANITE-2018)
        JcrPackageDefinitionImpl.State state = null;

        if (parent.hasNode(name)) {
            JcrPackage oldPackage = new JcrPackageImpl(parent.getNode(name));
            JcrPackageDefinitionImpl oldDef = (JcrPackageDefinitionImpl) oldPackage.getDefinition();
            if (oldDef != null) {
                state = oldDef.getState();
            }

            if (replace) {
                parent.getNode(name).remove();
            } else {
                throw new ItemExistsException("Package already exists: " + path);
            }
        }
        JcrPackage jcrPack = null;
        try {
            jcrPack = JcrPackageImpl.createNew(parent, pid, bin, archive);
            if (jcrPack != null) {
                JcrPackageDefinitionImpl def = (JcrPackageDefinitionImpl) jcrPack.getDefinition();
                if (state != null) {
                    def.setState(state);
                }
            }
            return jcrPack;
        } finally {
            bin.dispose();
            if (jcrPack == null) {
                session.refresh(false);
            } else {
                session.save();
            }
View Full Code Here

            // compile the properties
            setProperties(contentNode, typeId, properties);

            // write content, if available
            Binary binary = contentStream == null || contentStream.getStream() == null
                    ? JcrBinary.EMPTY
                    : new JcrBinary(new BufferedInputStream(contentStream.getStream()));
            try {
                contentNode.setProperty(Property.JCR_DATA, binary);
                if (contentStream != null && contentStream.getMimeType() != null) {
                    contentNode.setProperty(Property.JCR_MIMETYPE, contentStream.getMimeType());
                }
            }
            finally {
                binary.dispose();
            }

            fileNode.getSession().save();
            JcrNode jcrFileNode = create(fileNode);
            if (versioningState == VersioningState.NONE) {
View Full Code Here

            if (autoCheckout) {
                jcrVersion.checkout();
            }

            // write content, if available
            Binary binary = contentStream == null || contentStream.getStream() == null
                    ? JcrBinary.EMPTY
                    : new JcrBinary(new BufferedInputStream(contentStream.getStream()));
            try {
                contentNode.setProperty(Property.JCR_DATA, binary);
                if (contentStream != null && contentStream.getMimeType() != null) {
                    contentNode.setProperty(Property.JCR_MIMETYPE, contentStream.getMimeType());
                }
            }
            finally {
                binary.dispose();
            }

            contentNode.getSession().save();

            if (autoCheckout) {
View Full Code Here

                            blob = BLOBInDataStore.getInstance(store, identifier);
                        }
                    }
                }
                if (blob == null) {
                    Binary b = value.getBinary();
                    boolean dispose = false;
                    try {
                        if (b instanceof BLOBFileValue) {
                            // use as is
                            blob = (BLOBFileValue) b;
                        } else {
                            // create a copy from the stream
                            dispose = true;
                            blob = getBLOBFileValue(store, b.getStream(), true);
                        }
                    } finally {
                        if (dispose) {
                            b.dispose();
                        }
                    }
                }
                return new InternalValue(blob);
            case PropertyType.BOOLEAN:
View Full Code Here

    private Value createValue(Value value, int type)
            throws RepositoryException {
        switch (type) {
        case PropertyType.BINARY:
            Binary binary = value.getBinary();
            try {
                return createValue(binary.getStream());
            } finally {
                binary.dispose();
            }
        case PropertyType.BOOLEAN:
            return createValue(value.getBoolean());
        case PropertyType.DATE:
            return createValue(value.getDate());
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

        if (getType() == PropertyType.NAME || getType() == PropertyType.PATH) {
            // qualified name/path value needs to be resolved,
            // delegate conversion to getString() method
            try {
                final byte[] value = getString().getBytes("UTF-8");
                return new Binary() {
                    public int read(byte[] b, long position) {
                        if (position >= value.length) {
                            return -1;
                        } else {
                            int p = (int) position;
View Full Code Here

    public void setValue(InputStream value) throws RepositoryException {
        if (value == null) {
            setValue((Value) null);
        } else {
            ValueFactory factory = getSession().getValueFactory();
            Binary binary = factory.createBinary(value);
            try {
                setValue(factory.createValue(binary));
            } finally {
                binary.dispose();
            }
        }
    }
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.