Package org.modeshape.jcr.value

Examples of org.modeshape.jcr.value.BinaryValue


                problems.addError(msg, key.toString(), repositoryName(), backupLocation());
            }
            try {
                InputStream stream = new FileInputStream(binaryFile);
                try {
                    BinaryValue stored = binaryStore.storeValue(stream, false);
                    assert stored.getKey().equals(binaryKeyFor(binaryFile));
                } finally {
                    stream.close();
                }
            } catch (FileNotFoundException e) {
                // We already checked that it exists and is readable, so this shouldn't happen. But ...
View Full Code Here


            } else if (Double.class.equals(type)) {
                convertedValue = context().getValueFactories().getDoubleFactory().create(value);
            } else if (BigDecimal.class.equals(type)) {
                convertedValue = context().getValueFactories().getDecimalFactory().create(value);
            } else if (java.io.InputStream.class.equals(type)) {
                BinaryValue binary = context().getValueFactories().getBinaryFactory().create(value);
                convertedValue = binary.getStream();
            } else if (javax.jcr.Binary.class.isAssignableFrom(type)) {
                convertedValue = context().getValueFactories().getBinaryFactory().create(value);
            } else if (Node.class.equals(type)) {
                convertedValue = valueToNode(value);
            } else if (NodeIterator.class.equals(type)) {
View Full Code Here

        writer.setPrimaryType(NodeType.NT_RESOURCE);
        writer.setParent(id);

        if (doc.getContentStream() != null) {
            InputStream is = doc.getContentStream().getStream();
            BinaryValue content = factories.getBinaryFactory().create(is);
            writer.addProperty(JcrConstants.JCR_DATA, content);
            writer.addProperty(JcrConstants.JCR_MIME_TYPE, doc.getContentStream().getMimeType());
        }

        Property<Object> lastModified = doc.getProperty(PropertyIds.LAST_MODIFICATION_DATE);
View Full Code Here

        while (iter.hasNext()) {
            Property prop = iter.next();
            if (prop.isEmpty()) continue;
            for (Object value : prop) {
                if (value instanceof BinaryValue) {
                    BinaryValue binary = (BinaryValue)value;
                    // we don't care about the string encoding, as long as its consistent and will change if a property changes
                    sb.append(binary.getHexHash());
                }
            }
        }
        return sb.toString();
    }
View Full Code Here

                    writer.addProperty(GitLexicon.TITLE, fileCommit.getShortMessage());
                    // Create the BinaryValue ...
                    ObjectId fileObjectId = tw.getObjectId(0);
                    ObjectLoader fileLoader = repository.open(fileObjectId);
                    BinaryKey key = new BinaryKey(fileObjectId.getName());
                    BinaryValue value = values.binaryFor(key, fileLoader.getSize());
                    if (value == null) {
                        // It wasn't found in the binary store ...
                        if (fileLoader.isLarge()) {
                            // Too large to hold in memory, so use the binary store (which reads the file immediately) ...
                            value = values.binaryFrom(fileLoader.openStream());
                        } else {
                            // This is small enough to fit into a byte[], but it still may be pretty big ...
                            value = new GitBinaryValue(fileObjectId, fileLoader, connector.getSourceName(), name,
                                                       connector.getMimeTypeDetector());
                        }
                    }
                    writer.addProperty(JcrLexicon.DATA, value);
                    if (connector.includeMimeType()) {
                        try {
                            String filename = spec.parameter(spec.parameterCount() - 1); // the last is 'jcr:content'
                            String mimeType = value.getMimeType(filename);
                            if (mimeType != null) writer.addProperty(JcrLexicon.MIMETYPE, mimeType);
                        } catch (RepositoryException e) {
                            // do nothing
                        } catch (IOException e) {
                            // do nothing
View Full Code Here

    @Override
    public InputStream getStream() throws RepositoryException {
        checkSession();
        try {
            BinaryValue binary = context().getValueFactories().getBinaryFactory().create(property().getFirstValue());
            return binary.getStream();
        } catch (org.modeshape.jcr.value.ValueFormatException e) {
            throw new ValueFormatException(e.getMessage(), e);
        }
    }
View Full Code Here

        }
        checkSession();
        checkForLock();
        checkForCheckedOut();

        BinaryValue binary = null;
        if (value instanceof BinaryValue) {
            binary = (BinaryValue)value;
        } else {
            // Otherwise, this isn't our instance, so copy the data ...
            binary = context().getValueFactories().getBinaryFactory().create(value.getStream());
View Full Code Here

        int repCount = 5;
        for (int i = 0; i < repCount; i++) {
            // upload a file which should mark the binary as used
            tools.uploadFile(session, "/file1.txt", resourceStream("io/file1.txt"));
            session.save();
            BinaryValue storedValue = (BinaryValue)session.getProperty("/file1.txt/jcr:content/jcr:data").getBinary();
            BinaryKey key = storedValue.getKey();
            assertTrue("Binary not stored", binaryStore().hasBinary(key));

            // remove the file, which should move the binary to trash
            session.getNode("/file1.txt").remove();
            session.save();
View Full Code Here

TOP

Related Classes of org.modeshape.jcr.value.BinaryValue

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.