org.apache.commons.vfs2.provider.AbstractFileObject Java Examples

The following examples show how to use org.apache.commons.vfs2.provider.AbstractFileObject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileContent.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the content of a file as a byte array.
 *
 * @return The content as a byte array.
 * @throws IOException if the file content cannot be accessed.
 * @since 2.4
 */
default byte[] getByteArray() throws IOException {
    final long sizeL = getSize();
    if (sizeL > Integer.MAX_VALUE) {
        throw new IllegalStateException(String.format("File content is too large for a byte array: %,d", sizeL));
    }
    final boolean sizeUndefined = sizeL < 0;
    final int size = sizeUndefined ? AbstractFileObject.DEFAULT_BUFFER_SIZE : (int) sizeL;
    final byte[] buf = new byte[size];
    int pos;
    try (final InputStream in = getInputStream(size)) {
        int read = 0;
        for (pos = 0; pos < size && read >= 0; pos += read) {
            read = in.read(buf, pos, size - pos);
        }
    }
    return sizeUndefined && pos < buf.length ? Arrays.copyOf(buf, ++pos) : buf;
}
 
Example #2
Source File: FileObjectUtils.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Gets access to the base object even if decorated.
 *
 * @param fileObject The FileObject.
 * @return The decorated FileObject or null.
 * @throws FileSystemException if an error occurs.
 */
public static AbstractFileObject getAbstractFileObject(final FileObject fileObject) throws FileSystemException {
    Object searchObject = fileObject;
    while (searchObject instanceof DecoratedFileObject) {
        searchObject = ((DecoratedFileObject) searchObject).getDecoratedFileObject();
    }
    if (searchObject instanceof AbstractFileObject) {
        return (AbstractFileObject) searchObject;
    }
    if (searchObject == null) {
        return null;
    }

    throw new FileSystemException("vfs.util/find-abstract-file-object.error",
        fileObject == null ? "null" : fileObject.getClass().getName());
}
 
Example #3
Source File: VerifyingFileSelector.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Determines whether a folder should be traversed.
 */
@Override
public boolean traverseDescendents(final FileSelectInfo fileInfo) throws FileSystemException {
    // Check that the given file is a folder
    final FileObject folder = FileObjectUtils.getAbstractFileObject(fileInfo.getFile());
    assertSame(FileType.FOLDER, folder.getType());
    assertTrue(folder.isFolder());

    // Locate the info for the folder
    final String baseName = folder.getName().getBaseName();
    if (currentFolder == null) {
        assertEquals(rootFile.baseName, baseName);
        currentFolderInfo = rootFile;
    } else {
        final AbstractFileObject parent = FileObjectUtils.getAbstractFileObject(folder.getParent());
        assertSame(currentFolder, parent);

        // Locate the info for the child, and make sure it is folder
        currentFolderInfo = getChild(baseName);
        assertSame(FileType.FOLDER, currentFolderInfo.type);
    }

    // Push the folder
    stack.add(0, children);
    children = new HashSet<>(currentFolderInfo.children.keySet());
    currentFolder = folder;

    return true;
}
 
Example #4
Source File: ConnectionFileObject.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public ConnectionFileObject( AbstractFileName name, ConnectionFileSystem fs, AbstractFileObject resolvedFileObject,
                             String domain ) {
  super( name, fs );
  this.resolvedFileObject = resolvedFileObject;
  this.domain = domain;
}