Example usage for java.nio.file Files list

List of usage examples for java.nio.file Files list

Introduction

In this page you can find the example usage for java.nio.file Files list.

Prototype

public static Stream<Path> list(Path dir) throws IOException 

Source Link

Document

Return a lazily populated Stream , the elements of which are the entries in the directory.

Usage

From source file:org.simmi.GeneSetHead.java

License:asdf

public void fetchGenomes() {
    if (geneset.zippath == null) {
        newFile();//from   ww w. ja  v a2 s .  co m
    }

    VBox vbox = new VBox();

    Stage stage = new Stage();
    stage.setTitle("Fetch genomes");
    stage.setScene(new Scene(vbox));
    stage.initOwner(primaryStage);

    //frame.setSize(400, 600);

    try {
        Map<String, String> env = new HashMap<>();
        env.put("create", "true");
        //Path path = zipfile.toPath();
        String uristr = "jar:" + geneset.zippath.toUri();
        geneset.zipuri = URI.create(uristr /*.replace("file://", "file:")*/ );
        geneset.zipfilesystem = FileSystems.newFileSystem(geneset.zipuri, env);

        final SerifyApplet sa = new SerifyApplet(geneset.zipfilesystem);
        sa.init(frame, vbox, geneset.user);

        for (Path root : geneset.zipfilesystem.getRootDirectories()) {
            Files.list(root).filter(t -> {
                String fname = t.getFileName().toString();
                return /*fname.endsWith(".gbk") || */fname.endsWith(".fna") || fname.endsWith("fastg")
                        || fname.endsWith(".fsa") || fname.endsWith(".fa") || fname.endsWith(".fasta")
                        || fname.endsWith(".aa") || fname.endsWith(".nn") || fname.endsWith(".trna")
                        || fname.endsWith(".rrna") || fname.endsWith(".ssu") || fname.endsWith(".lsu")
                        || fname.endsWith(".tsu");
            }).forEach(t -> {
                try {
                    sa.addSequences(t.getFileName().toString(), t, null);
                } catch (URISyntaxException | IOException e) {
                    e.printStackTrace();
                }
            });
            ;
        }
    } catch (IOException e1) {
        try {
            geneset.zipfilesystem.close();
        } catch (IOException e2) {
            e2.printStackTrace();
        }
        e1.printStackTrace();
    }

    //BufferedWriter bw = Files.newBufferedWriter(nf, StandardOpenOption.CREATE);

    //InputStream is = new GZIPInputStream( new FileInputStream( fc.getSelectedFile() ) );
    //uni2symbol(new InputStreamReader(is), bw, unimap);

    //bw.close();
    //long bl = Files.copy( new ByteArrayInputStream( baos.toByteArray() ), nf, StandardCopyOption.REPLACE_EXISTING );

    /*frame.addWindowListener( new WindowListener() {
               
       @Override
       public void windowOpened(WindowEvent e) {}
               
       @Override
       public void windowIconified(WindowEvent e) {}
               
       @Override
       public void windowDeiconified(WindowEvent e) {}
               
       @Override
       public void windowDeactivated(WindowEvent e) {}
               
       @Override
       public void windowClosing(WindowEvent e) {}
               
       @Override
       public void windowClosed(WindowEvent e) {
    try {
       geneset.zipfilesystem.close();
            
       geneset.cleanUp();
       importStuff();
    } catch (IOException | UnavailableServiceException e1) {
       e1.printStackTrace();
    }
       }
               
       @Override
       public void windowActivated(WindowEvent e) {}
    });
            
    frame.setVisible( true );*/

    stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
        public void handle(WindowEvent event) {
            try {
                geneset.zipfilesystem.close();

                geneset.cleanUp();
                importStuff();
            } catch (IOException | UnavailableServiceException e1) {
                e1.printStackTrace();
            }
        }
    });
    stage.show();
}