Search in sources :

Example 6 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 7 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 8 with FileSystemResource

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

the class ObjectPersistenceManager method store.

/**
     * {@inheritDoc}
     */
protected void store(PropertyState state) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    String propFilePath = buildPropFilePath(state.getPropertyId());
    FileSystemResource propFile = new FileSystemResource(itemStateFS, propFilePath);
    try {
        propFile.makeParentDirs();
        BufferedOutputStream out = new BufferedOutputStream(propFile.getOutputStream());
        try {
            // serialize property state
            Serializer.serialize(state, out, blobStore);
        } finally {
            out.close();
        }
    } catch (Exception e) {
        String msg = "failed to store property state: " + state.getParentId() + "/" + state.getName();
        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 9 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 10 with FileSystemResource

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

the class ObjectPersistenceManager method existsReferencesTo.

/**
     * {@inheritDoc}
     */
public synchronized boolean existsReferencesTo(NodeId id) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    try {
        String refsFilePath = buildNodeReferencesFilePath(id);
        FileSystemResource refsFile = new FileSystemResource(itemStateFS, refsFilePath);
        return refsFile.exists();
    } catch (FileSystemException fse) {
        String msg = "failed to check existence of references: " + 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)

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