Example usage for java.io File listRoots

List of usage examples for java.io File listRoots

Introduction

In this page you can find the example usage for java.io File listRoots.

Prototype

public static File[] listRoots() 

Source Link

Document

List the available filesystem roots.

Usage

From source file:com.symbian.driver.plugins.romflash.Activator.java

public boolean FlashRom(String romLocation) {

    try {/*w ww.j ava2  s . c  om*/
        File rom = new File(romLocation);
        if (method.compareToIgnoreCase("serial") == 0) {
            if (!(switchOff() && switchOn())) {
                LOGGER.log(Level.SEVERE, "Could not reboot device, so No rom flashing.");
                return false;
            }
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                LOGGER.log(Level.SEVERE, "Failed to wait for sync.exe to finish.");
            }
            File trgtTestFile = JarUtils.extractResource(Activator.class, "/resource/trgtest.exe");
            if (trgtTestFile.isFile()) {
                ProcessBuilder ld = new ProcessBuilder(trgtTestFile.getAbsolutePath(), portNumber,
                        rom.getCanonicalPath());
                ld.directory(trgtTestFile.getParentFile());
                Process pp = ld.start();
                LOGGER.log(Level.INFO, "started trgtest process");
                BufferedReader br = new BufferedReader(new InputStreamReader(pp.getInputStream()));
                StringBuffer sb = new StringBuffer();
                String line;
                while ((line = br.readLine()) != null) {
                    sb.append(line).append("\n");
                    LOGGER.log(Level.INFO, line);
                }
                //String answer = sb.toString();

                try {
                    LOGGER.log(Level.INFO, "going to wait now for trgtest to finish");
                    pp.waitFor();
                } catch (InterruptedException e) {
                    LOGGER.log(Level.SEVERE, "Failed to wait for trgtest.exe to finish.");
                }
                LOGGER.log(Level.INFO, "trgtest returned: " + pp.exitValue());
                pp.destroy();

            } else {
                LOGGER.log(Level.SEVERE, "Could not find trgtest.exe file.");
            }
        } else // usb rom loading
        {
            // switch the device off...
            switchOff();
            List<File> lis1 = Arrays.asList(File.listRoots());
            // get reboot plugin, and reboot the device
            switchOn(); // or just switch on as things may be
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                LOGGER.log(Level.SEVERE, "Failed to wait for sync.exe to finish.");
            }
            File[] listRoots2 = File.listRoots();
            // find the drive that made the difference!!
            File diff = null;
            for (File root : listRoots2) {
                if (!lis1.contains(root)) // found new drive
                {
                    diff = root;
                    break;
                }
            }
            File romfl = new File(diff, rom.getName());
            romfl.delete();
            File aCopyFrom = new File(rom.getCanonicalPath());
            FileChannel lSrcChannel = new FileInputStream(aCopyFrom).getChannel();
            FileChannel lDstChannel = new FileOutputStream(romfl).getChannel();
            lDstChannel.transferFrom(lSrcChannel, 0, lSrcChannel.size());
            lSrcChannel.close();
            lDstChannel.close();

            File syncFile = JarUtils.extractResource(Activator.class, "/resource/sync.exe");
            if (syncFile.isFile()) {

                ProcessBuilder ld = new ProcessBuilder(syncFile.getAbsolutePath(), "-r", "-e", diff.toString());

                ld.directory(syncFile.getParentFile());
                ld.start();
                // wait 10 seconds for the rom to load ...
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    LOGGER.log(Level.SEVERE, "Failed to wait for sync.exe to finish.");
                }
            } else {
                LOGGER.log(Level.SEVERE, "Could not find sync.exe file.");
            }
        }
    } catch (IOException lIOException) {
        LOGGER.log(Level.SEVERE, "Could not flash ROM " + lIOException.getMessage());
        return false;
    }
    try {
        Thread.sleep(10000);
    } catch (InterruptedException e) {
        LOGGER.log(Level.SEVERE, "Failed to wait for sync.exe to finish.");
    }
    return true;
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.QcliveAbstractBaseIntegrationTest.java

/**
 * Retrieves the absolute root directory path of the tcgafiles directory.
 * /*from ww  w.j a v  a 2s .c o  m*/
 * @return the absolute root directory path of the tcgafiles directory
 */
private static String getTcgaFilesRootDirPath() {
    File tcgaFilesRoot = null;
    for (final File root : File.listRoots()) {
        tcgaFilesRoot = new File(root + tcgaFilesRootDirName);
        if (tcgaFilesRoot.canRead())
            return tcgaFilesRoot.getAbsolutePath();
    }
    return null;
}

From source file:tajo.worker.Worker.java

@Override
public ServerStatusProto getServerStatus(NullProto request) {
    // serverStatus builder
    ServerStatusProto.Builder serverStatus = ServerStatusProto.newBuilder();
    // TODO: compute the available number of task slots
    serverStatus.setAvailableTaskSlotNum(MAX_TASK_NUM - tasks.size());

    // system(CPU, memory) status builder
    ServerStatusProto.System.Builder systemStatus = ServerStatusProto.System.newBuilder();

    systemStatus.setAvailableProcessors(Runtime.getRuntime().availableProcessors());
    systemStatus.setFreeMemory(Runtime.getRuntime().freeMemory());
    systemStatus.setMaxMemory(Runtime.getRuntime().maxMemory());
    systemStatus.setTotalMemory(Runtime.getRuntime().totalMemory());

    serverStatus.setSystem(systemStatus);

    // disk status builder
    File[] roots = File.listRoots();
    for (File root : roots) {
        ServerStatusProto.Disk.Builder diskStatus = ServerStatusProto.Disk.newBuilder();

        diskStatus.setAbsolutePath(root.getAbsolutePath());
        diskStatus.setTotalSpace(root.getTotalSpace());
        diskStatus.setFreeSpace(root.getFreeSpace());
        diskStatus.setUsableSpace(root.getUsableSpace());

        serverStatus.addDisk(diskStatus);
    }//from w w w . ja  v  a2s .c o  m
    return serverStatus.build();
}

From source file:com.scooter1556.sms.server.controller.MediaController.java

@RequestMapping(value = "/files", method = RequestMethod.GET)
public ResponseEntity<List<Directory>> getDirectoryList(
        @RequestParam(value = "path", required = false) String path) {
    List<Directory> directories = new ArrayList<>();
    File[] files = null;//from  www  .  j  ava 2  s.c  o m

    // If no path is specified return roots
    if (path == null) {
        if (SystemUtils.IS_OS_WINDOWS) {
            files = File.listRoots();
        } else if (SystemUtils.IS_OS_LINUX) {
            files = new File("/").listFiles(new FileFilter() {
                @Override
                public boolean accept(File file) {
                    return file.isDirectory();
                }
            });
        }
    } else {
        // Return directory list for given path
        File file = new File(path);

        if (!file.isDirectory()) {
            return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
        }

        files = file.listFiles(new FileFilter() {
            @Override
            public boolean accept(File file) {
                return file.isDirectory();
            }
        });
    }

    // Check if there is anything to return
    if (files == null || files.length == 0) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

    // Convert files to directory list
    for (File file : files) {
        directories.add(new Directory(file.getName(), file.getAbsolutePath()));
    }

    return new ResponseEntity<>(directories, HttpStatus.OK);
}

From source file:com.wavemaker.commons.util.IOUtils.java

private static void makeDirectoriesRecurse(File dir, File topLevel) throws FileAccessException {

    // if we're at the topLevel end recursion
    if (dir.equals(topLevel)) {
        return;/*from w w  w.ja v a  2 s.c o m*/
    }

    // if we're at the filesystem root, error
    for (File root : File.listRoots()) {
        if (dir.equals(root)) {
            throw new FileAccessException(MessageResource.UTIL_FILEUTILS_REACHEDROOT, root, topLevel);
        }
    }

    // make & check parent directories
    makeDirectoriesRecurse(dir.getParentFile(), topLevel);

    // make this directory
    if (!dir.exists()) {
        dir.mkdir();
    }
}

From source file:org.wso2.carbon.core.bootup.validator.SystemValidator.java

/**
 * @return maximum free disk space in the filesystem
 *///from w  ww  .j av  a2 s .  c  om
private long getMaxFreeDiskSpace() {
    // list of all filesystem roots of this system
    long maxFreeSpace = 0;
    File[] roots = File.listRoots();
    for (File disk : roots) {
        long diskFreeSpace = disk.getFreeSpace() / MB_BASE;
        if (disk.isDirectory() && (diskFreeSpace > maxFreeSpace)) {
            maxFreeSpace = diskFreeSpace;
        }
    }
    return maxFreeSpace;
}

From source file:mendeley2kindle.MainUIFrame.java

private File guessKindleRoot() {
    String os = System.getProperty("os.name");
    if (os.indexOf("Windows") >= 0) {
        FileSystemView fs = FileSystemView.getFileSystemView();
        Pattern pat = Pattern.compile("^Kindle \\(\\w:\\)$");
        for (File f : File.listRoots()) {
            String name = fs.getSystemDisplayName(f);
            if (pat.matcher(name).matches()) {
                return f;
            }//ww w. j a v  a  2s . c o m
        }
    } else if (os.indexOf("Linux") >= 0) {
        File f = new File("/media/");
        return f.isDirectory() ? f : null;
    } else if (os.indexOf("Mac") >= 0) {
        File f = new File("/Volumes/Kindle/");
        return f.isDirectory() ? f : new File("/Volumes/");
    }
    return null;
}

From source file:edu.harvard.i2b2.patientMapping.ui.PatientIDConversionJFrame.java

@SuppressWarnings("unused")
private String getNoteKeyDrive() {
    File[] drives = File.listRoots();
    String filename = "i2b2patientidkey.txt";
    for (int i = drives.length - 1; i >= 0; i--) {
        if (drives[i].getPath().startsWith("A") || drives[i].getPath().startsWith("B")) {
            continue;
        }//from  www.j a v a2s.  c om

        File tmp = new File(drives[i]/* +File.separator */ + filename);
        if (tmp.exists()) {
            return drives[i]/* +File.separator */ + filename;
        }
        // else {
        // return null;
        // }
    }

    File testFile = new File("i2b2patientidkey.txt");
    System.out.println("file dir: " + testFile.getAbsolutePath());
    if (testFile.exists()) {
        return testFile.getAbsolutePath();
    }

    return null;
}

From source file:org.sonatype.nexus.proxy.storage.local.fs.DefaultFSLocalRepositoryStorage.java

private static boolean validFile(File file) {
    if (roots == null) {
        roots = new HashSet<>();

        File[] listedRoots = File.listRoots();

        for (int i = 0; i < listedRoots.length; i++) {
            roots.add(listedRoots[i]);//from   ww  w  .j ava 2s  . c  o m
        }

        // Allow UNC based paths on windows
        // i.e. \\someserver\repository\central\blah
        if (isWindows()) {
            roots.add(new File("\\\\"));
        }
    }

    File root = file;

    while (root.getParentFile() != null) {
        root = root.getParentFile();
    }

    return roots.contains(root);
}

From source file:ddf.test.itests.catalog.TestFederation.java

@Test
public void testFederatedRetrieveNoProductCsw() throws Exception {
    File[] rootDirectories = File.listRoots();
    String rootDir = rootDirectories[0].getCanonicalPath();
    urlResourceReaderConfigurator.setUrlResourceReaderRootDirs(rootDir);
    String restUrl = REST_PATH.getUrl() + "sources/" + CSW_SOURCE_ID + "/" + metacardIds[GEOJSON_RECORD_INDEX]
            + "?transform=resource";

    // @formatter:off
    when().get(restUrl).then().log().all().assertThat().statusCode(equalTo(500));
    // @formatter:on
}