Search in sources :

Example 41 with DataStoreException

use of org.apache.jackrabbit.core.data.DataStoreException in project jackrabbit by apache.

the class VFSBackend method write.

/**
     * Writes {@code file}'s content to the record entry identified by {@code identifier}.
     * @param identifier record identifier
     * @param file local file to copy from
     * @param asyncUpload whether or not it should be done asynchronously
     * @param callback asynchronous uploading callback instance
     * @throws DataStoreException if any file system exception occurs
     */
private void write(DataIdentifier identifier, File file, boolean asyncUpload, AsyncUploadCallback callback) throws DataStoreException {
    AsyncUploadResult asyncUpRes = null;
    if (asyncUpload) {
        asyncUpRes = new AsyncUploadResult(identifier, file);
    }
    synchronized (this) {
        FileObject fileObject = getExistingFileObject(identifier);
        FileObject resolvedFileObject = resolveFileObject(identifier);
        try {
            if (fileObject != null) {
                updateLastModifiedTime(resolvedFileObject);
            } else {
                copyFileContentToRecord(file, identifier);
            }
            if (asyncUpRes != null && callback != null) {
                callback.onSuccess(asyncUpRes);
            }
        } catch (IOException e) {
            DataStoreException e2 = new DataStoreException("Could not get output stream to object: " + resolvedFileObject.getName().getFriendlyURI(), e);
            if (asyncUpRes != null && callback != null) {
                asyncUpRes.setException(e2);
                callback.onFailure(asyncUpRes);
            }
            throw e2;
        }
    }
}
Also used : AsyncUploadResult(org.apache.jackrabbit.core.data.AsyncUploadResult) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException)

Example 42 with DataStoreException

use of org.apache.jackrabbit.core.data.DataStoreException in project jackrabbit by apache.

the class VFSBackend method getAllIdentifiers.

/**
     * {@inheritDoc}
     */
@Override
public Iterator<DataIdentifier> getAllIdentifiers() throws DataStoreException {
    List<DataIdentifier> identifiers = new LinkedList<DataIdentifier>();
    try {
        for (FileObject fileObject : VFSUtils.getChildFolders(getBaseFolderObject())) {
            // skip top-level files
            pushIdentifiersRecursively(identifiers, fileObject);
        }
    } catch (FileSystemException e) {
        throw new DataStoreException("Object identifiers not resolved.", e);
    }
    LOG.debug("Found " + identifiers.size() + " identifiers.");
    return identifiers.iterator();
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) FileObject(org.apache.commons.vfs2.FileObject) LinkedList(java.util.LinkedList)

Example 43 with DataStoreException

use of org.apache.jackrabbit.core.data.DataStoreException in project jackrabbit by apache.

the class VFSBackend method updateLastModifiedTime.

/**
     * Set the last modified time of a fileObject, if the fileObject is writable.
     * @param fileObject the file object
     * @throws DataStoreException if the fileObject is writable but modifying the date fails
     */
private void updateLastModifiedTime(FileObject fileObject) throws DataStoreException {
    try {
        if (isTouchFilePreferred()) {
            getTouchFileObject(fileObject, true);
        } else {
            long time = System.currentTimeMillis() + ACCESS_TIME_RESOLUTION;
            fileObject.getContent().setLastModifiedTime(time);
        }
    } catch (FileSystemException e) {
        throw new DataStoreException("An IO Exception occurred while trying to set the last modified date: " + fileObject.getName().getFriendlyURI(), e);
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException)

Example 44 with DataStoreException

use of org.apache.jackrabbit.core.data.DataStoreException in project jackrabbit by apache.

the class VFSUtils method createChildFile.

/**
     * Creates a child file by the {@code name} under the {@code baseFolder} and retrieves the created file.
     * @param baseFolder base folder object
     * @param name child file name
     * @return a child file by the {@code name} under the {@code baseFolder} and retrieves the created file
     * @throws DataStoreException if any file system exception occurs
     */
static FileObject createChildFile(FileObject baseFolder, String name) throws DataStoreException {
    FileObject childFile = null;
    try {
        childFile = baseFolder.resolveFile(name);
        if (!childFile.exists()) {
            childFile.createFile();
            childFile = baseFolder.getChild(childFile.getName().getBaseName());
        }
    } catch (FileSystemException e) {
        throw new DataStoreException("Could not create a child file, '" + name + "' under " + baseFolder.getName().getFriendlyURI(), e);
    }
    return childFile;
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) FileObject(org.apache.commons.vfs2.FileObject)

Example 45 with DataStoreException

use of org.apache.jackrabbit.core.data.DataStoreException in project jackrabbit by apache.

the class VFSUtils method createChildFolder.

/**
     * Creates a child folder by the {@code name} under the {@code baseFolder} and retrieves the created folder.
     * @param baseFolder base folder object
     * @param name child folder name
     * @return a child folder by the {@code name} under the {@code baseFolder} and retrieves the created folder
     * @throws DataStoreException if any file system exception occurs
     */
static FileObject createChildFolder(FileObject baseFolder, String name) throws DataStoreException {
    FileObject childFolder = null;
    try {
        childFolder = baseFolder.resolveFile(name);
        if (!childFolder.exists()) {
            childFolder.createFolder();
            childFolder = baseFolder.getChild(childFolder.getName().getBaseName());
        }
    } catch (FileSystemException e) {
        throw new DataStoreException("Could not create a child folder, '" + name + "' under " + baseFolder.getName().getFriendlyURI(), e);
    }
    return childFolder;
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) FileObject(org.apache.commons.vfs2.FileObject)

Aggregations

DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)85 IOException (java.io.IOException)35 AmazonServiceException (com.amazonaws.AmazonServiceException)28 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)18 DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)15 File (java.io.File)14 AmazonClientException (com.amazonaws.AmazonClientException)12 StorageException (com.microsoft.azure.storage.StorageException)11 InputStream (java.io.InputStream)9 URISyntaxException (java.net.URISyntaxException)9 RepositoryException (javax.jcr.RepositoryException)9 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)7 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)7 Copy (com.amazonaws.services.s3.transfer.Copy)7 Upload (com.amazonaws.services.s3.transfer.Upload)7 FileObject (org.apache.commons.vfs2.FileObject)7 FileSystemException (org.apache.commons.vfs2.FileSystemException)7 BufferedInputStream (java.io.BufferedInputStream)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 S3Object (com.amazonaws.services.s3.model.S3Object)5