Search in sources :

Example 1 with FileSystemResource

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

the class InMemBundlePersistenceManager method storeContents.

/**
 * Writes the content of the hash maps stores to the file system.
 *
 * @throws Exception if an error occurs
 */
public synchronized void storeContents() throws Exception {
    // write bundles
    FileSystemResource fsRes = new FileSystemResource(wspFS, BUNDLE_FILE_PATH);
    fsRes.makeParentDirs();
    BufferedOutputStream bos = new BufferedOutputStream(fsRes.getOutputStream());
    DataOutputStream out = new DataOutputStream(bos);
    try {
        // number of entries
        out.writeInt(bundleStore.size());
        // entries
        for (NodeId id : bundleStore.keySet()) {
            // id
            out.writeUTF(id.toString());
            byte[] data = bundleStore.get(id);
            // data length
            out.writeInt(data.length);
            // data
            out.write(data);
        }
    } finally {
        out.close();
    }
    // write references
    fsRes = new FileSystemResource(wspFS, REFS_FILE_PATH);
    fsRes.makeParentDirs();
    bos = new BufferedOutputStream(fsRes.getOutputStream());
    out = new DataOutputStream(bos);
    try {
        // number of entries
        out.writeInt(refsStore.size());
        // entries
        for (NodeId id : refsStore.keySet()) {
            // target id
            out.writeUTF(id.toString());
            byte[] data = refsStore.get(id);
            // data length
            out.writeInt(data.length);
            // data
            out.write(data);
        }
    } finally {
        out.close();
    }
    if (!useFileBlobStore) {
        // write blobs
        fsRes = new FileSystemResource(wspFS, BLOBS_FILE_PATH);
        fsRes.makeParentDirs();
        bos = new BufferedOutputStream(fsRes.getOutputStream());
        out = new DataOutputStream(bos);
        try {
            // number of entries
            out.writeInt(blobs.size());
            // entries
            for (String id : blobs.keySet()) {
                // id
                out.writeUTF(id);
                byte[] data = blobs.get(id);
                // data length
                out.writeInt(data.length);
                // data
                out.write(data);
            }
        } finally {
            out.close();
        }
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) NodeId(org.apache.jackrabbit.core.id.NodeId) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 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(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.debug(msg);
        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 3 with FileSystemResource

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

the class ObjectPersistenceManager method store.

/**
 * {@inheritDoc}
 */
protected void store(NodeState state) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    String nodeFilePath = buildNodeFilePath(state.getNodeId());
    FileSystemResource nodeFile = new FileSystemResource(itemStateFS, nodeFilePath);
    try {
        nodeFile.makeParentDirs();
        BufferedOutputStream out = new BufferedOutputStream(nodeFile.getOutputStream());
        try {
            // serialize node state
            Serializer.serialize(state, out);
        } finally {
            out.close();
        }
    } catch (Exception e) {
        String msg = "failed to write node state: " + state.getNodeId();
        log.debug(msg);
        throw new ItemStateException(msg, e);
    }
}
Also used : FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) BufferedOutputStream(java.io.BufferedOutputStream) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 4 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 5 with FileSystemResource

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

the class ObjectPersistenceManager method destroy.

/**
 * {@inheritDoc}
 */
protected void destroy(NodeState state) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    String nodeFilePath = buildNodeFilePath(state.getNodeId());
    FileSystemResource nodeFile = new FileSystemResource(itemStateFS, nodeFilePath);
    try {
        if (nodeFile.exists()) {
            // delete resource and prune empty parent folders
            nodeFile.delete(true);
        }
    } catch (FileSystemException fse) {
        String msg = "failed to delete node state: " + state.getNodeId();
        log.debug(msg);
        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)

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