Search in sources :

Example 6 with FileObject

use of org.apache.commons.vfs2.FileObject 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 7 with FileObject

use of org.apache.commons.vfs2.FileObject 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 8 with FileObject

use of org.apache.commons.vfs2.FileObject 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 9 with FileObject

use of org.apache.commons.vfs2.FileObject 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)

Example 10 with FileObject

use of org.apache.commons.vfs2.FileObject in project zeppelin by apache.

the class VFSNotebookRepo method getNote.

private Note getNote(FileObject noteDir) throws IOException {
    if (!isDirectory(noteDir)) {
        throw new IOException(noteDir.getName().toString() + " is not a directory");
    }
    FileObject noteJson = noteDir.resolveFile("note.json", NameScope.CHILD);
    if (!noteJson.exists()) {
        throw new IOException(noteJson.getName().toString() + " not found");
    }
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setPrettyPrinting();
    Gson gson = gsonBuilder.registerTypeAdapter(Date.class, new NotebookImportDeserializer()).create();
    FileContent content = noteJson.getContent();
    InputStream ins = content.getInputStream();
    String json = IOUtils.toString(ins, conf.getString(ConfVars.ZEPPELIN_ENCODING));
    ins.close();
    Note note = gson.fromJson(json, Note.class);
    for (Paragraph p : note.getParagraphs()) {
        if (p.getStatus() == Status.PENDING || p.getStatus() == Status.RUNNING) {
            p.setStatus(Status.ABORT);
        }
        List<ApplicationState> appStates = p.getAllApplicationStates();
        if (appStates != null) {
            for (ApplicationState app : appStates) {
                if (app.getStatus() != ApplicationState.Status.ERROR) {
                    app.setStatus(ApplicationState.Status.UNLOADED);
                }
            }
        }
    }
    return note;
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) InputStream(java.io.InputStream) ApplicationState(org.apache.zeppelin.notebook.ApplicationState) Gson(com.google.gson.Gson) IOException(java.io.IOException) NotebookImportDeserializer(org.apache.zeppelin.notebook.NotebookImportDeserializer) Date(java.util.Date) Paragraph(org.apache.zeppelin.notebook.Paragraph) FileContent(org.apache.commons.vfs2.FileContent) Note(org.apache.zeppelin.notebook.Note) FileObject(org.apache.commons.vfs2.FileObject)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)19 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)8 IOException (java.io.IOException)7 FileSystemException (org.apache.commons.vfs2.FileSystemException)7 FileType (org.apache.commons.vfs2.FileType)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 URISyntaxException (java.net.URISyntaxException)2 LinkedList (java.util.LinkedList)2 DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 URI (java.net.URI)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 RepositoryException (javax.jcr.RepositoryException)1 FileContent (org.apache.commons.vfs2.FileContent)1