Example usage for org.apache.commons.vfs2 FileType FILE

List of usage examples for org.apache.commons.vfs2 FileType FILE

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileType FILE.

Prototype

FileType FILE

To view the source code for org.apache.commons.vfs2 FileType FILE.

Click Source Link

Document

A regular file.

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 .  j a va2  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  ww .  j  a  v  a2s  .  c om*/
        if (fo.getType() == FileType.FILE)
            return true;
    } catch (FileSystemException e) {
        log.warn(e);
    }
    return false;
}

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

@Init
public void initialize() {
    try {/*from   w  ww  . ja  va  2  s  .  c om*/
        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.streamsets.pipeline.stage.origin.remote.FileFilter.java

@Override
public boolean includeFile(FileSelectInfo fileInfo) throws Exception {
    if (fileInfo.getFile().getType() == FileType.FILE) {
        Matcher matcher = regex.matcher(fileInfo.getFile().getName().getBaseName());
        if (matcher.matches()) {
            return true;
        }/*from  w w w. j a v a  2s.  co  m*/
    }
    LOG.trace("{} was not included", fileInfo.getFile().getName().getPath());
    return false;
}

From source file:com.gs.obevo.api.factory.XmlFileConfigReader.java

private FileObject getEnvFileToRead(FileObject sourcePath) {
    if (sourcePath.getType() == FileType.FILE && sourcePath.isReadable()
            && (sourcePath.getName().getExtension().equalsIgnoreCase("xml")
                    || sourcePath.getName().getExtension().equalsIgnoreCase("yaml"))) {
        return sourcePath;
    } else {/*from w w w. ja  v a2 s.c  o m*/
        return sourcePath.getChild("system-config.xml");
    }
}

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   ww  w  .ja  v  a 2  s  .c  om
        }
    }
    return ret;
}

From source file:com.github.junrar.vfs2.provider.rar.RARFileObject.java

@Override
protected FileType doGetType() {
    if (header == null || header.isDirectory()) {
        return FileType.FOLDER;
    } else {/*from   w  ww.  j a  v a  2s. co  m*/
        return FileType.FILE;
    }
}

From source file:com.mirth.connect.util.MessageImporter.java

public MessageImportResult importMessages(String path, Boolean recursive, MessageWriter messageWriter,
        String baseDir) throws InterruptedException, MessageImportException, MessageImportInvalidPathException {
    int[] result = new int[] { 0, 0 };

    if (baseDir == null) {
        baseDir = System.getProperty("user.dir");
    }//from w w  w. j  av  a 2 s  . co  m

    try {
        path = FilenameUtils.getAbsolutePath(new File(baseDir), path);

        if (!new File(path).canRead()) {
            throw new MessageImportInvalidPathException(
                    "The file/folder was not found or is not readable: " + path);
        }

        FileObject file = VfsUtils.getManager().resolveFile(VfsUtils.pathToUri(path));

        switch (file.getType()) {
        case FOLDER:
            for (FileObject child : file.getChildren()) {
                if (recursive) {
                    importVfsFileRecursive(child, messageWriter, result);
                } else if (child.getType() == FileType.FILE) {
                    importVfsFile(child, messageWriter, result);
                }
            }

            break;

        case FILE:
            importVfsFile(file, messageWriter, result);
            break;
        }

        messageWriter.finishWrite();
    } catch (Exception e) {
        throw new MessageImportException(e);
    } finally {
        try {
            messageWriter.close();
        } catch (Exception e) {
            logger.error("Failed to close message writer", e);
        }
    }

    return new MessageImportResult(result[0], result[1]);
}

From source file:com.gs.obevo.db.api.factory.DbEnvironmentXmlEnricher.java

private FileObject getEnvFileToRead(FileObject sourcePath) {
    if (sourcePath.getType() == FileType.FILE && sourcePath.isReadable()
            && sourcePath.getName().getExtension().equalsIgnoreCase("xml")) {
        return sourcePath;
    } else {//from  w  ww .  j a v  a2s  .  co m
        return sourcePath.getChild("system-config.xml");
    }
}

From source file:net.sourceforge.fullsync.fs.connection.CommonsVfsConnection.java

private File buildNode(final File parent, final FileObject file)
        throws org.apache.commons.vfs2.FileSystemException {
    String name = file.getName().getBaseName();

    File n = new AbstractFile(this, name, parent, file.getType() == FileType.FOLDER, true);
    if (file.getType() == FileType.FILE) {
        FileContent content = file.getContent();
        n.setLastModified(content.getLastModifiedTime());
        n.setSize(content.getSize());//from w ww .  j a va  2s. c  o  m
    }
    return n;
}