Example usage for java.nio.file FileSystems getDefault

List of usage examples for java.nio.file FileSystems getDefault

Introduction

In this page you can find the example usage for java.nio.file FileSystems getDefault.

Prototype

public static FileSystem getDefault() 

Source Link

Document

Returns the default FileSystem .

Usage

From source file:org.openecomp.sdc.ci.tests.utilities.OnboardingUtils.java

private static File getTestZipFile(String filepath, String filename) throws IOException {
    Config config = Utils.getConfig();// w ww  .  j a  v  a2 s .c om
    String sourceDir = config.getImportResourceTestsConfigDir();
    java.nio.file.Path filePath = FileSystems.getDefault().getPath(filepath + File.separator + filename);
    return filePath.toFile();
}

From source file:net.solarnetwork.node.setup.s3.S3SetupManager.java

private List<Path> extractTarball(File tarball) throws IOException {
    List<String> cmd = new ArrayList<>(tarCommand.size());
    String tarballPath = tarball.getAbsolutePath();
    for (String param : tarCommand) {
        param = param.replace(SOURCE_FILE_PLACEHOLDER, tarballPath);
        param = param.replace(DESTINATION_DIRECTORY_PLACEHOLDER, destinationPath);
        cmd.add(param);//from   w w w . j  a v  a 2s  .  c o  m
    }
    if (log.isDebugEnabled()) {
        StringBuilder buf = new StringBuilder();
        for (String p : cmd) {
            if (buf.length() > 0) {
                buf.append(' ');
            }
            buf.append(p);
        }
        log.debug("Tar command: {}", buf.toString());
    }
    log.info("Extracting S3 tar archive {}", tarball);
    List<Path> extractedPaths = new ArrayList<>();
    ProcessBuilder pb = new ProcessBuilder(cmd);
    pb.redirectErrorStream(true); // OS X tar output list to STDERR; Linux GNU tar to STDOUT
    Process pr = pb.start();
    try (BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()))) {
        String line = null;
        while ((line = in.readLine()) != null) {
            Matcher m = TAR_LIST_PAT.matcher(line);
            if (m.matches()) {
                line = m.group(1);
            }
            Path path = FileSystems.getDefault().getPath(line).toAbsolutePath().normalize();
            extractedPaths.add(path);
            log.trace("Installed setup resource: {}", line);
        }
    }
    try {
        pr.waitFor();
    } catch (InterruptedException e) {
        log.warn("Interrupted waiting for tar command to complete");
    }
    if (pr.exitValue() != 0) {
        String output = extractedPaths.stream().map(p -> p.toString()).collect(Collectors.joining("\n")).trim();
        log.error("Tar command returned non-zero exit code {}: {}", pr.exitValue(), output);
        throw new IOException("Tar command returned non-zero exit code " + pr.exitValue() + ": " + output);
    }
    return extractedPaths;
}

From source file:de.cebitec.readXplorer.differentialExpression.plot.BaySeqGraphicsTopComponent.java

private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
    ReadXplorerFileChooser fc = new ReadXplorerFileChooser(new String[] { "svg" }, "svg") {
        private static final long serialVersionUID = 1L;

        @Override//from   w  ww  .j av a  2  s .  c o  m
        public void save(String fileLocation) {
            Path to = FileSystems.getDefault().getPath(fileLocation, "");
            BaySeqAnalysisHandler.Plot selectedPlot = (BaySeqAnalysisHandler.Plot) plotTypeComboBox
                    .getSelectedItem();
            if (selectedPlot == BaySeqAnalysisHandler.Plot.MACD) {
                saveToSVG(fileLocation);
            } else {
                Path from = currentlyDisplayed.toPath();
                try {
                    Path outputFile = Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING);
                    messages.setText("SVG image saved to " + outputFile.toString());
                } catch (IOException ex) {
                    Date currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
                    Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "{0}: " + ex.getMessage(),
                            currentTimestamp);
                    JOptionPane.showMessageDialog(null, ex.getMessage(), "Could not write to file.",
                            JOptionPane.WARNING_MESSAGE);
                }
            }
        }

        @Override
        public void open(String fileLocation) {
        }
    };
    fc.openFileChooser(ReadXplorerFileChooser.SAVE_DIALOG);
}

From source file:edu.vt.vbi.patric.cache.DataLandingGenerator.java

public boolean createCacheFilePathways(String filePath) {
    boolean isSuccess = false;
    JSONObject jsonData = new JSONObject();
    JSONObject data;//from   w  w w.j av  a 2 s . c  o m

    // from WP
    // data
    data = read(baseURL + "/tab/dlp-pathways-data/?req=passphrase");
    if (data != null) {
        jsonData.put("data", data);
    }
    // conservation
    data = getPathwayECDist();
    if (data != null) {
        jsonData.put("conservation", data);
    }
    // popular genomes
    data = getPopularGenomesForPathways();
    if (data != null) {
        jsonData.put("popularGenomes", data);
    }
    // tools
    data = read(baseURL + "/tab/dlp-pathways-tools/?req=passphrase");
    if (data != null) {
        jsonData.put("tools", data);
    }
    // process
    data = read(baseURL + "/tab/dlp-pathways-process/?req=passphrase");
    if (data != null) {
        jsonData.put("process", data);
    }
    // download
    data = read(baseURL + "/tab/dlp-pathways-download/?req=passphrase");
    if (data != null) {
        jsonData.put("download", data);
    }

    // save jsonData to file
    try (PrintWriter jsonOut = new PrintWriter(
            Files.newBufferedWriter(FileSystems.getDefault().getPath(filePath), Charset.defaultCharset()));) {
        jsonData.writeJSONString(jsonOut);
        isSuccess = true;
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    }
    return isSuccess;
}

From source file:com.facebook.buck.io.filesystem.impl.DefaultProjectFilesystemTest.java

@Test
public void testCreateReadOnlyFileSetsPermissions() throws IOException {
    Assume.assumeTrue(FileSystems.getDefault().supportedFileAttributeViews().contains("posix"));
    Path path = Paths.get("hello.txt");
    ImmutableSet<PosixFilePermission> permissions = ImmutableSet.of(PosixFilePermission.OWNER_READ,
            PosixFilePermission.GROUP_READ, PosixFilePermission.OTHERS_READ);

    filesystem.writeContentsToPath("hello world", path, PosixFilePermissions.asFileAttribute(permissions));
    // The umask may restrict the actual permissions on the filesystem:
    // https://fburl.com/26569549
    // So the best we can do is to check that the actual permissions are a
    // strict subset of the expected permissions.
    PosixFileAttributes attrs = filesystem.readAttributes(path, PosixFileAttributes.class);
    assertTrue(permissions.containsAll(attrs.permissions()));
}

From source file:org.loklak.harvester.TwitterAPI.java

public static void main(String[] args) {
    try {//from w  w w .  j ava2s . c  o  m
        Path data = FileSystems.getDefault().getPath("data");
        DAO.init(LoklakServer.readConfig(data), data);
        try {
            System.out.println(getRateLimitStatus(RATE_FOLLOWERS_IDS));
        } catch (TwitterException e) {
            e.printStackTrace();
        }
        try {
            System.out.println(getFollowersNames("loklak_app", 10000));
        } catch (IOException | TwitterException e) {
            e.printStackTrace();
        }
        try {
            System.out.println(getFollowingNames("loklak_app", 10000));
        } catch (IOException | TwitterException e) {
            e.printStackTrace();
        }
        DAO.close();
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    System.exit(0);
}

From source file:amulet.appbuilder.AppBuilder.java

private void cleanUp(String filename) {
    try {//from   w  w w .  j a  va 2 s . c  o  m
        FileSystem fs = FileSystems.getDefault();
        Path interRep = fs.getPath(filename + ".ir");
        Path resRep = fs.getPath(filename + ".res");
        Path staticRep = fs.getPath(filename + ".stat");
        Path translateRep = fs.getPath(filename + ".trans");
        Files.deleteIfExists(interRep);
        Files.deleteIfExists(resRep);
        Files.deleteIfExists(staticRep);
        Files.deleteIfExists(translateRep);
    } catch (Exception exp) {
        System.err.println("Unexpected exception:" + exp.getMessage());
        exp.printStackTrace();
    }
}

From source file:com.bekwam.mavenpomupdater.MainViewController.java

public void doUpdate() {

    for (POMObject p : tblPOMS.getItems()) {

        if (log.isDebugEnabled()) {
            log.debug("[DO UPDATE] p=" + p.getAbsPath());
        }/*from  ww  w .j  ava  2s . co  m*/

        if (p.getParseError()) {
            if (log.isDebugEnabled()) {
                log.debug("[DO UPDATE] skipping update of p=" + p.getAbsPath()
                        + " because of a parse error on scanning");
            }
            continue;
        }

        if (!p.getUpdate()) {
            if (log.isDebugEnabled()) {
                log.debug("[DO UPDATE] skipping update of p=" + p.getAbsPath()
                        + " because user excluded it from update");
            }
            continue;
        }

        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(false);
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.parse(p.getAbsPath());

            if (p.getParentVersion() != null && p.getParentVersion().length() > 0) {
                XPath xpath = XPathFactory.newInstance().newXPath();
                XPathExpression expression = xpath.compile("//project/parent/version/text()");
                Node node = (Node) expression.evaluate(doc, XPathConstants.NODE);

                if (StringUtils.isNotEmpty(tfNewVersion.getText())) {
                    node.setNodeValue(tfNewVersion.getText());
                } else { // editing individual table cells
                    node.setNodeValue(p.getParentVersion());
                }
            }

            if (p.getVersion() != null && p.getVersion().length() > 0) {
                XPath xpath = XPathFactory.newInstance().newXPath();
                XPathExpression expression = xpath.compile("//project/version/text()");
                Node node = (Node) expression.evaluate(doc, XPathConstants.NODE);

                if (StringUtils.isNotEmpty(tfNewVersion.getText())) {
                    node.setNodeValue(tfNewVersion.getText());
                } else { // editing individual table cells
                    node.setNodeValue(p.getVersion());
                }
            }

            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer();

            String workingFileName = p.getAbsPath() + ".mpu";
            FileWriter fw = new FileWriter(workingFileName);
            DOMSource source = new DOMSource(doc);
            StreamResult result = new StreamResult(fw);
            transformer.transform(source, result);
            fw.close();

            Path src = FileSystems.getDefault().getPath(workingFileName);
            Path target = FileSystems.getDefault().getPath(p.getAbsPath());

            Files.copy(src, target, StandardCopyOption.REPLACE_EXISTING);

            Files.delete(src);

        } catch (Exception exc) {
            log.error("error updating poms", exc);
        }
    }

    if (StringUtils.isNotEmpty(tfRootDir.getText())) {
        if (log.isDebugEnabled()) {
            log.debug("[DO UPDATE] issuing rescan command");
        }
        scan();
    } else {
        if (log.isDebugEnabled()) {
            log.debug("[DO UPDATE] did an update, but there is not value in root; clearing");
        }
        tblPOMS.getItems().clear();
    }
    tblPOMSDirty = false;
    tfNewVersion.setDisable(false);
}

From source file:org.apache.drill.test.framework.Utils.java

public static void deleteFile(String filename) {
    try {/*  w  w w.  j  a  v a 2  s.  c om*/
        Path path = FileSystems.getDefault().getPath(filename);
        Files.delete(path);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:de.jwi.jfm.Folder.java

private void chmod(File file, String value) throws IOException {
    Path p = file.toPath();// ww w  . j  a v a 2 s.co m

    FileSystem fileSystem = FileSystems.getDefault();
    Set<String> fileSystemViews = fileSystem.supportedFileAttributeViews();

    if (fileSystemViews.contains("posix")) {
        Set<PosixFilePermission> posixFilePermissions = PosixFilePermissions.fromString(value);

        if (posixFilePermissions == null) {
            throw new IllegalArgumentException(value);
        }

        Files.getFileAttributeView(p, PosixFileAttributeView.class).setPermissions(posixFilePermissions);
    } else if (fileSystemViews.contains("dos")) {
    }
}