Search in sources :

Example 21 with FileObject

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;
}
Also used : NoteInfo(org.apache.zeppelin.notebook.NoteInfo) FileObject(org.apache.commons.vfs2.FileObject) LinkedList(java.util.LinkedList) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 22 with FileObject

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));
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) OutputStream(java.io.OutputStream) Gson(com.google.gson.Gson) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException)

Example 23 with FileObject

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();
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) FileObject(org.apache.commons.vfs2.FileObject) File(java.io.File) URI(java.net.URI)

Example 24 with FileObject

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);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileObject(org.apache.commons.vfs2.FileObject) FileInputStream(java.io.FileInputStream)

Example 25 with FileObject

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);
    }
}
Also used : FileObject(org.apache.commons.vfs2.FileObject)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)39 FileSystemException (org.apache.commons.vfs2.FileSystemException)14 IOException (java.io.IOException)8 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)8 Session (org.ow2.proactive_grid_cloud_portal.common.Session)7 ArrayList (java.util.ArrayList)4 InputStream (java.io.InputStream)3 URI (java.net.URI)3 HttpSession (javax.servlet.http.HttpSession)3 FileSystemManager (org.apache.commons.vfs2.FileSystemManager)3 FileType (org.apache.commons.vfs2.FileType)3 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 FileInputStream (java.io.FileInputStream)2 OutputStream (java.io.OutputStream)2 URISyntaxException (java.net.URISyntaxException)2 LinkedList (java.util.LinkedList)2 ExecutionException (java.util.concurrent.ExecutionException)2 FileSelector (org.apache.commons.vfs2.FileSelector)2