Example usage for org.apache.commons.vfs2 FileObject getType

List of usage examples for org.apache.commons.vfs2 FileObject getType

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileObject getType.

Prototype

FileType getType() throws FileSystemException;

Source Link

Document

Returns this file's type.

Usage

From source file:ShowProperties.java

public static void main(String[] args) throws FileSystemException {
    if (args.length == 0) {
        System.err.println("Please pass the name of a file as parameter.");
        System.err.println("e.g. java org.apache.commons.vfs2.example.ShowProperties LICENSE.txt");
        return;//from  w  w w  . ja v  a  2  s . c  o  m
    }
    for (int i = 0; i < args.length; i++) {
        try {
            FileSystemManager mgr = VFS.getManager();
            System.out.println();
            System.out.println("Parsing: " + args[i]);
            FileObject file = mgr.resolveFile(args[i]);
            System.out.println("URL: " + file.getURL());
            System.out.println("getName(): " + file.getName());
            System.out.println("BaseName: " + file.getName().getBaseName());
            System.out.println("Extension: " + file.getName().getExtension());
            System.out.println("Path: " + file.getName().getPath());
            System.out.println("Scheme: " + file.getName().getScheme());
            System.out.println("URI: " + file.getName().getURI());
            System.out.println("Root URI: " + file.getName().getRootURI());
            System.out.println("Parent: " + file.getName().getParent());
            System.out.println("Type: " + file.getType());
            System.out.println("Exists: " + file.exists());
            System.out.println("Readable: " + file.isReadable());
            System.out.println("Writeable: " + file.isWriteable());
            System.out.println("Root path: " + file.getFileSystem().getRoot().getName().getPath());
            if (file.exists()) {
                if (file.getType().equals(FileType.FILE)) {
                    System.out.println("Size: " + file.getContent().getSize() + " bytes");
                } else if (file.getType().equals(FileType.FOLDER) && file.isReadable()) {
                    FileObject[] children = file.getChildren();
                    System.out.println("Directory with " + children.length + " files");
                    for (int iterChildren = 0; iterChildren < children.length; iterChildren++) {
                        System.out.println("#" + iterChildren + ": " + children[iterChildren].getName());
                        if (iterChildren > 5) {
                            break;
                        }
                    }
                }
                System.out.println("Last modified: "
                        + DateFormat.getInstance().format(new Date(file.getContent().getLastModifiedTime())));
            } else {
                System.out.println("The file does not exist");
            }
            file.close();
        } catch (FileSystemException ex) {
            ex.printStackTrace();
        }
    }
}

From source file:architecture.common.util.vfs.VFSUtils.java

public static boolean isFile(FileObject fo) {
    try {//w w  w  . j ava 2  s  .c  om
        if (fo.getType() == FileType.FILE)
            return true;
    } catch (FileSystemException e) {
        log.warn(e);
    }
    return false;
}

From source file:architecture.common.util.vfs.VFSUtils.java

public static boolean isFolder(FileObject fo) {
    try {/*from   w ww .j  a  v a  2  s . c  o  m*/
        if (fo.getType() == FileType.FOLDER)
            return true;
    } catch (FileSystemException e) {
        log.warn(e);
    }
    return false;
}

From source file:com.stratuscom.harvester.Utils.java

public static List<FileObject> findChildrenWithSuffix(FileObject dir, String suffix)
        throws FileSystemException {

    List<FileObject> ret = new ArrayList<FileObject>();

    for (FileObject fo : dir.getChildren()) {
        if (fo.getType() == FileType.FILE && fo.getName().getBaseName().endsWith(suffix)) {
            ret.add(fo);/*from w  w  w.  j  a v  a2  s .  c  o  m*/
        }
    }
    return ret;
}

From source file:com.googlecode.vfsjfilechooser2.utils.VFSUtils.java

/**
 * Returns whether a file object is a directory
 * @param fileObject A file object representation
 * @return whether a file object is a directory
 *//*from  w  ww.ja v a2 s  . c  om*/
public static boolean isDirectory(FileObject fileObject) {
    try {
        return fileObject.getType().equals(FileType.FOLDER);
    } catch (FileSystemException ex) {
        return false;
    }
}

From source file:com.app.server.EARDeployer.java

public static void getClassList(FileObject jarFile, CopyOnWriteArrayList classList,
        StandardFileSystemManager fsManager) throws FileSystemException {
    // log.info(jarFile);
    FileObject nestedFS = null;//from  w  w w. j a va2 s .com
    FileObject[] children = null;
    if (jarFile.getURL().toString().trim().endsWith(".jar")) {
        nestedFS = fsManager.createFileSystem(jarFile);
        children = nestedFS.resolveFile("/").getChildren();
    } else if (jarFile.getType() == FileType.FOLDER) {
        children = jarFile.getChildren();
    }
    // log.info();
    // log.info( "Children of " + jarFile.getName().getURI() );
    if (children == null)
        return;
    for (int i = 0; i < children.length; i++) {
        // log.info(children[i].+" "+
        // children[i].getName().getBaseName() );
        if (children[i].getType() == FileType.FILE && children[i].getName().getBaseName().endsWith(".class"))
            classList.add(children[i].toString().substring(children[i].toString().lastIndexOf('!') + 2));
        getClassList(children[i], classList, fsManager);
    }
}

From source file:com.web.server.EARDeployer.java

public static void getClassList(FileObject jarFile, CopyOnWriteArrayList classList,
        StandardFileSystemManager fsManager) throws FileSystemException {
    // System.out.println(jarFile);
    FileObject nestedFS = null;// w  ww.  j  a  v  a  2 s . co m
    FileObject[] children = null;
    if (jarFile.getURL().toString().trim().endsWith(".jar")) {
        nestedFS = fsManager.createFileSystem(jarFile);
        children = nestedFS.resolveFile("/").getChildren();
    } else if (jarFile.getType() == FileType.FOLDER) {
        children = jarFile.getChildren();
    }
    // System.out.println();
    // System.out.println( "Children of " + jarFile.getName().getURI() );
    if (children == null)
        return;
    for (int i = 0; i < children.length; i++) {
        // System.out.println(children[i].+" "+
        // children[i].getName().getBaseName() );
        if (children[i].getType() == FileType.FILE && children[i].getName().getBaseName().endsWith(".class"))
            classList.add(children[i].toString().substring(children[i].toString().lastIndexOf('!') + 2));
        getClassList(children[i], classList, fsManager);
    }
}

From source file:com.sonicle.webtop.vfs.bol.js.JsGridFile.java

private String getFileType(FileObject fo) {
    try {/*from www.  ja v  a  2 s  .c o  m*/
        if (fo.getType().equals(FileType.FOLDER)) {
            return "folder";
        } else {
            return "file";
        }
    } catch (FileSystemException ex) {
        return "file";
    }
}

From source file:com.stratuscom.harvester.PropertiesFileReader.java

@Init
public void initialize() {
    try {//  ww  w .  j a va 2  s .  c  o  m
        FileObject[] childFiles = fileUtility.getProfileDirectory().getChildren();
        for (FileObject fo : childFiles) {
            if (fo.getName().getBaseName().endsWith(Strings.DOT_PROPERTIES) && fo.getType() == FileType.FILE) {
                readPropertiesFile(fo);
            }
        }
    } catch (Exception ex) {
        throw new LocalizedRuntimeException(ex, MessageNames.BUNDLE_NAME, MessageNames.FAILED_READ_PROPERTIES);
    }
}

From source file:com.flicklib.folderscanner.MovieNameExtractor.java

public String removeCrap(FileObject file) throws FileSystemException {
    return removeCrap(file.getName().getBaseName(), file.getType().hasChildren());
}