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

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

Introduction

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

Prototype

FileObject[] getChildren() throws FileSystemException;

Source Link

Document

Lists the children of this 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  ww w . java2 s .c om*/
    }
    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:net.dempsy.distconfig.apahcevfs.Utils.java

public static FileObject getLatest(final FileObject parent) throws FileSystemException {
    try {//from w ww  .  j  a  v  a  2  s .  co  m
        final FileObject[] children = parent.getChildren();
        if (children == null || children.length == 0)
            return null;
        return Arrays.stream(children).reduce(null, findLatest, findLatest);
    } catch (final FileNotFoundException | FileNotFolderException afnfe) {
        if (parent.exists())
            throw afnfe;
        return null;
    }
}

From source file:fi.mystes.synapse.mediator.vfs.VFSTestHelper.java

public static void assertFilesExists(String directory, int expectedCount) throws FileSystemException {
    FileSystemManager fsManager = VFS.getManager();
    FileObject file = fsManager.resolveFile(directory);
    FileObject[] children = file.getChildren();
    assertEquals("File count doesn't match", expectedCount, children.length);
}

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);/* w w  w  . j  av a2s .  c  o  m*/
        }
    }
    return ret;
}

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

/**
 * Returns all the files of a folder//from ww  w.j  a va 2 s.c  om
 * @param folder A folder
 * @return the files of a folder
 */
public static FileObject[] getFiles(FileObject folder) {
    try {
        return folder.getChildren();
    } catch (FileSystemException ex) {
        return new FileObject[0];
    }
}

From source file:fr.cls.atoll.motu.processor.wps.TestServiceMetadata.java

public static String[] getServiceMetadataSchemaAsString(String schemaPath) throws MotuException {

    List<String> stringList = new ArrayList<String>();
    String localIso19139SchemaPath = "file:///c:/tempVFS/testISO";
    String localIso19139RootSchemaRelPath = "/srv/srv.xsd";
    String localIso19139RootSchemaPath = String.format("%s%s", localIso19139SchemaPath,
            localIso19139RootSchemaRelPath);

    FileObject dest = Organizer.resolveFile(localIso19139RootSchemaPath);
    boolean hasIso19139asLocalSchema = false;
    try {/*ww  w . j  ava2  s .c om*/
        if (dest != null) {
            hasIso19139asLocalSchema = dest.exists();
        }
    } catch (FileSystemException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    if (hasIso19139asLocalSchema) {
        try {
            dest.close();
        } catch (FileSystemException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } else {

        // URL url = Organizer.findResource("schema/iso/srv/srv.xsd");
        // URL url =
        // Organizer.findResource("J:/dev/iso/19139/20070417/schema/src/main/resources/iso/19139/20070417/srv/srv.xsd");
        // URL url = Organizer.findResource("iso/19139/20070417/srv/srv.xsd");
        URL url = Organizer.findResource(schemaPath);
        System.out.println(url);

        // String[] arr = url.toString().split("!");

        // FileObject jarFile = Organizer.resolveFile(arr[0]);
        FileObject jarFile = Organizer.resolveFile(url.toString());

        // List the children of the Jar file
        FileObject[] children = null;
        try {
            children = jarFile.getChildren();
        } catch (FileSystemException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("Children of " + jarFile.getName().getURI());
        for (int i = 0; i < children.length; i++) {
            System.out.println(children[i].getName().getBaseName());
        }

        dest = Organizer.resolveFile(localIso19139SchemaPath);
        Organizer.deleteDirectory(dest);

        Organizer.copyFile(jarFile, dest);
    }

    // stringList.add(url.toString());
    // stringList.add("J:/dev/iso/19139/20070417/schema/src/main/resources/iso/19139/20070417/srv/srv.xsd");
    stringList.add(localIso19139RootSchemaPath);
    // stringList.add("C:/Documents and Settings/dearith/Mes documents/Atoll/SchemaIso/srv/serviceMetadata.xsd");
    String[] inS = new String[stringList.size()];
    inS = stringList.toArray(inS);
    return inS;
}

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  ww  w.  ja  v a  2 s.  c  om
    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:edu.scripps.fl.pubchem.app.RelationDownloader.java

public void call() throws Exception {
    Pattern pattern = Pattern.compile("^AID(\\d+)\\s+AID(\\d+)$");

    FileObject folder = VFS.getManager().resolveFile(assayNeighborURL);
    for (FileObject rFile : folder.getChildren()) {
        String name = rFile.getName().getBaseName();
        log.info("Processing file: " + name);
        BufferedReader reader = new BufferedReader(new InputStreamReader(rFile.getContent().getInputStream()));
        String line = null;/* w w  w .  j a  v a 2 s .c o  m*/
        long lastFrom = 0;
        List<Relation> relations = new ArrayList(100);
        while (null != (line = reader.readLine())) {
            Matcher matcher = pattern.matcher(line);
            if (!matcher.matches())
                throw new java.lang.UnsupportedOperationException("Cannot determine AIDs from line: " + line);
            long from = Long.parseLong(matcher.group(1));
            long to = Long.parseLong(matcher.group(2));
            if (lastFrom == 0) // very first time only.
                lastFrom = from;
            if (from != lastFrom) { // when we change to the next aid in the file
                update(from, name, relations);
                PubChemDB.getSession().clear();
                lastFrom = from;
            }
            Relation relation = new Relation();
            relation.setFromDb("pcassay");
            relation.setToDb("pcassay");
            relation.setFromId(from);
            relation.setToId(to);
            relation.setRelationName(name);
            relations.add(relation);
        }
        update(lastFrom, name, relations);
    }
}

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;/*from w  ww  .j av a2  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:net.sourceforge.fullsync.fs.connection.CommonsVfsConnection.java

@Override
public final Map<String, File> getChildren(final File dir) throws IOException {
    try {//from   w w  w  . j  av  a  2  s .c  o m
        Map<String, File> children = new HashMap<>();

        FileObject obj = base.resolveFile(dir.getPath());
        if (obj.exists() && (obj.getType() == FileType.FOLDER)) {
            FileObject[] list = obj.getChildren();
            for (FileObject element : list) {
                children.put(element.getName().getBaseName(), buildNode(dir, element));
            }
        }
        return children;
    } catch (org.apache.commons.vfs2.FileSystemException fse) {
        throw new IOException(fse.getMessage(), fse);
    }
}