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;
}
}
}
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();
}
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);
}
}
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;
}
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;
}
Aggregations