Package javax.jcr

Examples of javax.jcr.Binary


        return getValue().getString();
    }

    /** Wrapper around {@link #getValue()} */
    public InputStream getStream() throws RepositoryException {
        final Binary binary = getValue().getBinary();
        // make sure binary is disposed after stream had been consumed
        return new AutoCloseInputStream(binary.getStream()) {
            public void close() throws IOException {
                super.close();
                binary.dispose();
            }
        };
    }
View Full Code Here


    }

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

                }
                pack = new ZipVaultPackage(archive, true);
            } else {
                File tmpFile = File.createTempFile("vaultpack", ".zip");
                FileOutputStream out = FileUtils.openOutputStream(tmpFile);
                Binary bin = getData().getBinary();
                InputStream in = null;
                try {
                    in = bin.getStream();
                    IOUtils.copy(in, out);
                } finally {
                    IOUtils.closeQuietly(in);
                    IOUtils.closeQuietly(out);
                    bin.dispose();
                }
                pack = new ZipVaultPackage(tmpFile, true);
            }
        }
        return pack;
View Full Code Here

            case SPOOL:
                // we can't support spool
            case STREAM:
                InputStream in = a.getInputStream();
                Binary b = content.getSession().getValueFactory().createBinary(in);
                content.setProperty(JcrConstants.JCR_DATA, b);
                b.dispose();
                in.close();
                break;
        }
        Calendar now = Calendar.getInstance();
        if (a.getLastModified() >= 0) {
View Full Code Here

            if (local.hasNode(JcrConstants.JCR_CONTENT)) {
                content = local.getNode(JcrConstants.JCR_CONTENT);
            } else {
                content = local.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
            }
            Binary b = content.getSession().getValueFactory().createBinary(in);
            content.setProperty(JcrConstants.JCR_DATA, b);
            content.setProperty(JcrConstants.JCR_LASTMODIFIED, Calendar.getInstance());
            if (!content.hasProperty(JcrConstants.JCR_MIMETYPE)){
                content.setProperty(JcrConstants.JCR_MIMETYPE, "application/octet-stream");
            }
            b.dispose();
            in.close();
        } catch (RepositoryException e) {
            IOException io = new IOException("Error while writing file " + relPath);
            io.initCause(e);
            throw io;
View Full Code Here

        }
    }

    private void writeFile(SyncResult res, Entry e) throws IOException, RepositoryException {
        String action = e.file.exists() ? "U" : "A";
        Binary bin = null;
        InputStream in = null;
        OutputStream out = null;
        try {
            bin = e.node.getProperty("jcr:content/jcr:data").getBinary();
            in = bin.getStream();
            out = FileUtils.openOutputStream(e.file);
            IOUtils.copy(in, out);
            if (preserveFileDate) {
                Calendar lastModified = e.node.getProperty("jcr:content/jcr:lastModified").getDate();
                e.file.setLastModified(lastModified.getTimeInMillis());
            }
            syncLog.log("%s file://%s", action, e.file.getAbsolutePath());
            res.addEntry(e.getJcrPath(), e.getFsPath(), SyncResult.Operation.UPDATE_FS);
        } finally {
            IOUtils.closeQuietly(in);
            IOUtils.closeQuietly(out);
            if (bin != null) {
                bin.dispose();
            }
        }
    }
View Full Code Here

        Calendar cal = Calendar.getInstance();
        if (preserveFileDate) {
            cal.setTimeInMillis(e.file.lastModified());
        }
        InputStream in = FileUtils.openInputStream(e.file);
        Binary bin = content.getSession().getValueFactory().createBinary(in);
        content.setProperty(Property.JCR_DATA, bin);
        content.setProperty(Property.JCR_LAST_MODIFIED, cal);
        content.setProperty(Property.JCR_MIMETYPE, MimeTypes.getMimeType(e.file.getName(), MimeTypes.APPLICATION_OCTET_STREAM));
        syncLog.log("%s jcr://%s", action, ntFile.getPath());
        res.addEntry(e.getJcrPath(), e.getFsPath(), SyncResult.Operation.UPDATE_JCR);
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

     * {{@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

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.