Search in sources :

Example 16 with FileSystemResource

use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.

the class Serializer method deserialize.

/**
     * Deserializes a <code>PropertyState</code> object from the given binary
     * <code>stream</code>. Binary values are retrieved from the specified
     * <code>BLOBStore</code>.
     *
     * @param state     <code>state</code> to deserialize
     * @param stream    the stream where the <code>state</code> should be
     *                  deserialized from
     * @param blobStore handler for BLOB data
     * @throws Exception if an error occurs during the deserialization
     * @see #serialize(PropertyState, OutputStream, BLOBStore)
     */
public static void deserialize(PropertyState state, InputStream stream, BLOBStore blobStore) throws Exception {
    DataInputStream in = new DataInputStream(stream);
    // type
    int type = in.readInt();
    state.setType(type);
    // multiValued
    boolean multiValued = in.readBoolean();
    state.setMultiValued(multiValued);
    // definitionId
    in.readUTF();
    // modCount
    short modCount = in.readShort();
    state.setModCount(modCount);
    // values
    // count
    int count = in.readInt();
    InternalValue[] values = new InternalValue[count];
    for (int i = 0; i < count; i++) {
        InternalValue val;
        if (type == PropertyType.BINARY) {
            // value (i.e. blobId)
            String s = in.readUTF();
            // in the BLOB store
            if (blobStore instanceof ResourceBasedBLOBStore) {
                // optimization: if the BLOB store is resource-based
                // retrieve the resource directly rather than having
                // to read the BLOB from an input stream
                FileSystemResource fsRes = ((ResourceBasedBLOBStore) blobStore).getResource(s);
                val = InternalValue.create(fsRes);
            } else {
                InputStream is = blobStore.get(s);
                try {
                    val = InternalValue.create(is);
                } finally {
                    try {
                        is.close();
                    } catch (IOException e) {
                    // ignore
                    }
                }
            }
        } else {
            /**
                 * because writeUTF(String) has a size limit of 65k,
                 * Strings are serialized as <length><byte[]>
                 */
            //s = in.readUTF();   // value
            // lenght of byte[]
            int len = in.readInt();
            byte[] bytes = new byte[len];
            // byte[]
            in.readFully(bytes);
            String s = new String(bytes, ENCODING);
            val = InternalValue.valueOf(s, type);
        }
        values[i] = val;
    }
    state.setValues(values);
}
Also used : DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) InternalValue(org.apache.jackrabbit.core.value.InternalValue)

Example 17 with FileSystemResource

use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.

the class XMLPersistenceManager method exists.

/**
     * {@inheritDoc}
     */
public synchronized boolean exists(PropertyId id) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    try {
        String propFilePath = buildPropFilePath(id);
        FileSystemResource propFile = new FileSystemResource(itemStateFS, propFilePath);
        return propFile.exists();
    } catch (FileSystemException fse) {
        String msg = "failed to check existence of item state: " + id;
        log.error(msg, fse);
        throw new ItemStateException(msg, fse);
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 18 with FileSystemResource

use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.

the class ObjectPersistenceManager method exists.

/**
     * {@inheritDoc}
     */
public synchronized boolean exists(NodeId id) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    try {
        String nodeFilePath = buildNodeFilePath(id);
        FileSystemResource nodeFile = new FileSystemResource(itemStateFS, nodeFilePath);
        return nodeFile.exists();
    } catch (FileSystemException fse) {
        String msg = "failed to check existence of item state: " + id;
        log.error(msg, fse);
        throw new ItemStateException(msg, fse);
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 19 with FileSystemResource

use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.

the class FileSystemBLOBStore method remove.

/**
     * {@inheritDoc}
     */
public boolean remove(String blobId) throws Exception {
    // the blobId is an absolute file system path
    FileSystemResource res = new FileSystemResource(fs, blobId);
    if (!res.exists()) {
        return false;
    }
    // delete resource and prune empty parent folders
    res.delete(true);
    return true;
}
Also used : FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource)

Example 20 with FileSystemResource

use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.

the class FileSystemBLOBStore method put.

/**
     * {@inheritDoc}
     */
public void put(String blobId, InputStream in, long size) throws Exception {
    // the blobId is an absolute file system path
    FileSystemResource internalBlobFile = new FileSystemResource(fs, blobId);
    internalBlobFile.makeParentDirs();
    OutputStream out = internalBlobFile.getOutputStream();
    try {
        IOUtils.copy(in, out);
    } finally {
        out.close();
    }
}
Also used : OutputStream(java.io.OutputStream) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource)

Aggregations

FileSystemResource (org.apache.jackrabbit.core.fs.FileSystemResource)37 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)23 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)19 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)19 OutputStream (java.io.OutputStream)9 IOException (java.io.IOException)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)7 RepositoryException (javax.jcr.RepositoryException)7 NodeId (org.apache.jackrabbit.core.id.NodeId)7 InputStream (java.io.InputStream)6 InternalValue (org.apache.jackrabbit.core.value.InternalValue)6 BufferedOutputStream (java.io.BufferedOutputStream)5 OutputStreamWriter (java.io.OutputStreamWriter)5 BufferedWriter (java.io.BufferedWriter)4 DataInputStream (java.io.DataInputStream)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 FileSystem (org.apache.jackrabbit.core.fs.FileSystem)4 DataOutputStream (java.io.DataOutputStream)3 Writer (java.io.Writer)3 ArrayList (java.util.ArrayList)3