use of org.apache.commons.vfs2.FileObject in project zeppelin by apache.
the class VFSNotebookRepo method list.
@Override
public List<NoteInfo> list(AuthenticationInfo subject) throws IOException {
FileObject rootDir = getRootDir();
FileObject[] children = rootDir.getChildren();
List<NoteInfo> infos = new LinkedList<>();
for (FileObject f : children) {
String fileName = f.getName().getBaseName();
if (f.isHidden() || fileName.startsWith(".") || fileName.startsWith("#") || fileName.startsWith("~")) {
// skip hidden, temporary files
continue;
}
if (!isDirectory(f)) {
// so it must be a directory
continue;
}
NoteInfo info = null;
try {
info = getNoteInfo(f);
if (info != null) {
infos.add(info);
}
} catch (Exception e) {
LOG.error("Can't read note " + f.getName().toString(), e);
}
}
return infos;
}
use of org.apache.commons.vfs2.FileObject in project zeppelin by apache.
the class VFSNotebookRepo method save.
@Override
public synchronized void save(Note note, AuthenticationInfo subject) throws IOException {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setPrettyPrinting();
Gson gson = gsonBuilder.create();
String json = gson.toJson(note);
FileObject rootDir = getRootDir();
FileObject noteDir = rootDir.resolveFile(note.getId(), NameScope.CHILD);
if (!noteDir.exists()) {
noteDir.createFolder();
}
if (!isDirectory(noteDir)) {
throw new IOException(noteDir.getName().toString() + " is not a directory");
}
FileObject noteJson = noteDir.resolveFile(".note.json", NameScope.CHILD);
// false means not appending. creates file if not exists
OutputStream out = noteJson.getContent().getOutputStream(false);
out.write(json.getBytes(conf.getString(ConfVars.ZEPPELIN_ENCODING)));
out.close();
noteJson.moveTo(noteDir.resolveFile("note.json", NameScope.CHILD));
}
use of org.apache.commons.vfs2.FileObject in project zeppelin by apache.
the class VFSNotebookRepo method setNotebookDirectory.
private void setNotebookDirectory(String notebookDirPath) throws IOException {
try {
if (conf.isWindowsPath(notebookDirPath)) {
filesystemRoot = new File(notebookDirPath).toURI();
} else {
filesystemRoot = new URI(notebookDirPath);
}
} catch (URISyntaxException e1) {
throw new IOException(e1);
}
if (filesystemRoot.getScheme() == null) {
// it is local path
File f = new File(conf.getRelativeDir(filesystemRoot.getPath()));
this.filesystemRoot = f.toURI();
}
fsManager = VFS.getManager();
FileObject file = fsManager.resolveFile(filesystemRoot.getPath());
if (!file.exists()) {
LOG.info("Notebook dir doesn't exist, create on is {}.", file.getName());
file.createFolder();
}
}
use of org.apache.commons.vfs2.FileObject in project jackrabbit by apache.
the class VFSBackend method copyFileContentToRecord.
/**
* Copy the content of the local file ({@code srcFile}) to the record identified by the {@code identifier}.
* @param srcFile source local file
* @param identifier record identifier
* @throws IOException if any IO exception occurs
* @throws DataStoreException if any file system exception occurs
*/
private void copyFileContentToRecord(File srcFile, DataIdentifier identifier) throws IOException, DataStoreException {
String relPath = resolveFileObjectRelPath(identifier);
String[] segments = relPath.split("/");
InputStream input = null;
OutputStream output = null;
try {
FileObject baseFolderObject = getBaseFolderObject();
FileObject folderObject = null;
for (int i = 0; i < segments.length - 1; i++) {
folderObject = VFSUtils.createChildFolder(baseFolderObject, segments[i]);
baseFolderObject = folderObject;
}
FileObject destFileObject = VFSUtils.createChildFile(folderObject, segments[segments.length - 1]);
input = new FileInputStream(srcFile);
output = destFileObject.getContent().getOutputStream();
IOUtils.copy(input, output);
} finally {
IOUtils.closeQuietly(output);
IOUtils.closeQuietly(input);
}
}
use of org.apache.commons.vfs2.FileObject in project jackrabbit by apache.
the class VFSBackend method deleteRecord.
/**
* {@inheritDoc}
*/
@Override
public void deleteRecord(DataIdentifier identifier) throws DataStoreException {
FileObject fileObject = getExistingFileObject(identifier);
if (fileObject != null) {
deleteRecordFileObject(fileObject);
deleteEmptyParentFolders(fileObject);
}
}
Aggregations