use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.
the class DatabaseFileSystem method getInputStream.
/**
* {@inheritDoc}
*/
public InputStream getInputStream(String filePath) throws FileSystemException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
FileSystemPathUtil.checkFormat(filePath);
String parentDir = FileSystemPathUtil.getParentDir(filePath);
String name = FileSystemPathUtil.getName(filePath);
synchronized (selectDataSQL) {
try {
final ResultSet rs = conHelper.exec(selectDataSQL, new Object[] { parentDir, name }, false, 0);
if (!rs.next()) {
throw new FileSystemException("no such file: " + filePath);
}
InputStream in = rs.getBinaryStream(1);
/**
* return an InputStream wrapper in order to
* close the ResultSet when the stream is closed
*/
return new FilterInputStream(in) {
public void close() throws IOException {
super.close();
// close ResultSet
DbUtility.close(rs);
}
};
} catch (SQLException e) {
String msg = "failed to retrieve data of file: " + filePath;
log.error(msg, e);
throw new FileSystemException(msg, e);
}
}
}
use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.
the class DatabaseFileSystem method listFiles.
/**
* {@inheritDoc}
*/
public String[] listFiles(String folderPath) throws FileSystemException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
FileSystemPathUtil.checkFormat(folderPath);
if (!isFolder(folderPath)) {
throw new FileSystemException("no such folder: " + folderPath);
}
synchronized (selectFileNamesSQL) {
ResultSet rs = null;
try {
rs = conHelper.exec(selectFileNamesSQL, new Object[] { folderPath }, false, 0);
ArrayList<String> names = new ArrayList<String>();
while (rs.next()) {
names.add(rs.getString(1));
}
return names.toArray(new String[names.size()]);
} catch (SQLException e) {
String msg = "failed to list file entries of folder: " + folderPath;
log.error(msg, e);
throw new FileSystemException(msg, e);
} finally {
DbUtility.close(rs);
}
}
}
use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.
the class DatabaseFileSystem method length.
/**
* {@inheritDoc}
*/
public long length(String filePath) throws FileSystemException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
FileSystemPathUtil.checkFormat(filePath);
String parentDir = FileSystemPathUtil.getParentDir(filePath);
String name = FileSystemPathUtil.getName(filePath);
synchronized (selectLengthSQL) {
ResultSet rs = null;
try {
rs = conHelper.exec(selectLengthSQL, new Object[] { parentDir, name }, false, 0);
if (!rs.next()) {
throw new FileSystemException("no such file: " + filePath);
}
return rs.getLong(1);
} catch (SQLException e) {
String msg = "failed to determine length of file: " + filePath;
log.error(msg, e);
throw new FileSystemException(msg, e);
} finally {
DbUtility.close(rs);
}
}
}
use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.
the class DatabaseFileSystem method deleteFolder.
/**
* {@inheritDoc}
*/
public void deleteFolder(String folderPath) throws FileSystemException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
FileSystemPathUtil.checkFormat(folderPath);
if (folderPath.equals(FileSystem.SEPARATOR)) {
throw new FileSystemException("cannot delete root");
}
String parentDir = FileSystemPathUtil.getParentDir(folderPath);
String name = FileSystemPathUtil.getName(folderPath);
int count = 0;
synchronized (deleteFolderSQL) {
try {
count = conHelper.update(deleteFolderSQL, new Object[] { parentDir, name, folderPath, folderPath + FileSystem.SEPARATOR + "%" });
} catch (SQLException e) {
String msg = "failed to delete folder: " + folderPath;
log.error(msg, e);
throw new FileSystemException(msg, e);
}
}
if (count == 0) {
throw new FileSystemException("no such folder: " + folderPath);
}
}
use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.
the class DatabaseFileSystem method isFile.
/**
* {@inheritDoc}
*/
public boolean isFile(String path) throws FileSystemException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
FileSystemPathUtil.checkFormat(path);
String parentDir = FileSystemPathUtil.getParentDir(path);
String name = FileSystemPathUtil.getName(path);
synchronized (selectFileExistSQL) {
ResultSet rs = null;
try {
rs = conHelper.exec(selectFileExistSQL, new Object[] { parentDir, name }, false, 0);
// a file exists if the result set has at least one entry
return rs.next();
} catch (SQLException e) {
String msg = "failed to check existence of file: " + path;
log.error(msg, e);
throw new FileSystemException(msg, e);
} finally {
DbUtility.close(rs);
}
}
}
Aggregations