Example usage for java.io File toPath

List of usage examples for java.io File toPath

Introduction

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

Prototype

public Path toPath() 

Source Link

Document

Returns a Path java.nio.file.Path object constructed from this abstract path.

Usage

From source file:gdt.jgui.entity.folder.JFolderFacetOpenItem.java

private static boolean isTextFile(File file) {
    try {/* w ww . j a va  2s.  co m*/
        String mime$ = Files.probeContentType(file.toPath());
        //System.out.println("FileOpenItem: isTextFile:mime="+mime$);
        if (mime$.equals("text/plain"))
            return true;
        return false;
    } catch (Exception e) {
        Logger.getLogger(JFileOpenItem.class.getName()).info(e.toString());
        return false;
    }
}

From source file:net.dv8tion.jda.utils.SimpleLog.java

private static void logToFiles(String msg, Level level) {
    Set<File> files = collectFiles(level);
    for (File file : files) {
        try {//from w w  w.jav  a  2  s. c o  m
            Files.write(file.toPath(), (msg + '\n').getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE,
                    StandardOpenOption.APPEND);
        } catch (IOException e) {
            JDAImpl.LOG.fatal("Could not write log to logFile...");
            JDAImpl.LOG.log(e);
        }
    }
}

From source file:com.liferay.blade.cli.command.ConvertThemeCommand.java

private static boolean _compassSupport(String themePath) throws Exception {
    File themeDir = new File(themePath);

    File customCss = new File(themeDir, "docroot/_diffs/css/custom.css");

    if (!customCss.exists()) {
        customCss = new File(themeDir, "docroot/_diffs/css/_custom.scss");
    }//from www .j  a v  a2s. c o m

    if (!customCss.exists()) {
        return false;
    }

    String css = new String(Files.readAllBytes(customCss.toPath()));

    Matcher matcher = _compassImport.matcher(css);

    return matcher.find();
}

From source file:com.netsteadfast.greenstep.util.FSUtils.java

/**
 * get MIME-TYPE /*from ww  w.  java 2s  .  c  o m*/
 * Using javax.activation.MimetypesFileTypeMap
 * 
 * @param file
 * @return
 * @throws Exception
 */
public static String getMimeType(File file) throws Exception {
    String mimeType = "";
    if (file == null || !file.exists() || file.isDirectory()) {
        return mimeType;
    }
    /*
    mimeType=new MimetypesFileTypeMap().getContentType(file);
    return mimeType;
    */
    return Files.probeContentType(file.toPath());
}

From source file:com.opentable.db.postgres.embedded.BundledPostgresBinaryResolver.java

/**
 * Unpack archive compressed by tar with bzip2 compression. By default system tar is used
 * (faster). If not found, then the java implementation takes place.
 *
 * @param tbzPath//  w w w.ja v a 2  s  . c  om
 *        The archive path.
 * @param targetDir
 *        The directory to extract the content to.
 */
private static void extractTxz(String tbzPath, String targetDir) throws IOException {
    try (InputStream in = Files.newInputStream(Paths.get(tbzPath));
            XZInputStream xzIn = new XZInputStream(in);
            TarArchiveInputStream tarIn = new TarArchiveInputStream(xzIn)) {
        TarArchiveEntry entry;

        while ((entry = tarIn.getNextTarEntry()) != null) {
            final String individualFile = entry.getName();
            final File fsObject = new File(targetDir + "/" + individualFile);

            if (entry.isSymbolicLink() || entry.isLink()) {
                Path target = FileSystems.getDefault().getPath(entry.getLinkName());
                Files.createSymbolicLink(fsObject.toPath(), target);
            } else if (entry.isFile()) {
                byte[] content = new byte[(int) entry.getSize()];
                int read = tarIn.read(content, 0, content.length);
                Verify.verify(read != -1, "could not read %s", individualFile);
                mkdirs(fsObject.getParentFile());
                try (OutputStream outputFile = new FileOutputStream(fsObject)) {
                    IOUtils.write(content, outputFile);
                }
            } else if (entry.isDirectory()) {
                mkdirs(fsObject);
            } else {
                throw new UnsupportedOperationException(
                        String.format("Unsupported entry found: %s", individualFile));
            }

            if (individualFile.startsWith("bin/") || individualFile.startsWith("./bin/")) {
                fsObject.setExecutable(true);
            }
        }
    }
}

From source file:net.dv8tion.jda.core.utils.SimpleLog.java

private static void logToFiles(String msg, Level level) {
    Set<File> files = collectFiles(level);
    for (File file : files) {
        try {/*from   w  ww  .j  av a  2  s . c om*/
            Files.write(file.toPath(), (msg + '\n').getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE,
                    StandardOpenOption.APPEND);
        } catch (IOException e) {
            e.printStackTrace();
            //                JDAImpl.LOG.fatal("Could not write log to logFile...");
            //                JDAImpl.LOG.log(e);
        }
    }
}

From source file:net.sf.jabref.gui.desktop.JabRefDesktop.java

/**
 * Opens a new console starting on the given file location
 *
 * If no command is specified in {@link Globals},
 * the default system console will be executed.
 *
 * @param file Location the console should be opened at.
 *///from   w  w w . ja  v a2s  .com
public static void openConsole(File file) throws IOException {
    if (file == null) {
        return;
    }

    String absolutePath = file.toPath().toAbsolutePath().getParent().toString();
    boolean usingDefault = Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_CONSOLE_APPLICATION);

    if (usingDefault) {
        NATIVE_DESKTOP.openConsole(absolutePath);
    } else {
        String command = Globals.prefs.get(JabRefPreferences.CONSOLE_COMMAND);
        command = command.trim();

        if (!command.isEmpty()) {
            command = command.replaceAll("\\s+", " "); // normalize white spaces
            String[] subcommands = command.split(" ");
            StringBuilder commandLoggingText = new StringBuilder();

            for (int i = 0; i < subcommands.length; i++) {
                subcommands[i] = subcommands[i].replace("%DIR", absolutePath); // replace the placeholder if used
                commandLoggingText.append(subcommands[i]);
                if (i < (subcommands.length - 1)) {
                    commandLoggingText.append(" ");
                }
            }

            JabRefGUI.getMainFrame()
                    .output(Localization.lang("Executing command \"%0\"...", commandLoggingText.toString()));
            LOGGER.info("Executing command \"" + commandLoggingText.toString() + "\"...");

            try {
                new ProcessBuilder(subcommands).start();
            } catch (IOException exception) {
                LOGGER.error("Open console", exception);

                JOptionPane.showMessageDialog(JabRefGUI.getMainFrame(),
                        Localization.lang("Error_occured_while_executing_the_command_\"%0\".",
                                commandLoggingText.toString()),
                        Localization.lang("Open console") + " - " + Localization.lang("Error"),
                        JOptionPane.ERROR_MESSAGE);
                JabRefGUI.getMainFrame().output(null);
            }
        }
    }
}

From source file:com.twitter.heron.apiserver.utils.FileHelper.java

private static void addFileToArchive(TarArchiveOutputStream archiveOutputStream, File file, String base)
        throws IOException {
    final File absoluteFile = file.getAbsoluteFile();
    final String entryName = base + file.getName();
    final TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(file, entryName);
    archiveOutputStream.putArchiveEntry(tarArchiveEntry);

    if (absoluteFile.isFile()) {
        Files.copy(file.toPath(), archiveOutputStream);
        archiveOutputStream.closeArchiveEntry();
    } else {/*from   w  w w .  ja  va2 s.c  om*/
        archiveOutputStream.closeArchiveEntry();
        if (absoluteFile.listFiles() != null) {
            for (File f : absoluteFile.listFiles()) {
                addFileToArchive(archiveOutputStream, f, entryName + "/");
            }
        }
    }
}

From source file:com.github.thorqin.toolkit.web.utility.UploadManager.java

private static long getCreationTime(File f) throws IOException {
    BasicFileAttributes attributes = Files.readAttributes(f.toPath(), BasicFileAttributes.class);
    return attributes.creationTime().toMillis();
}

From source file:com.bc.fiduceo.TestUtil.java

public static File copyFileDir(File sourceFile, File targetDirectory) throws IOException {
    assertTrue(sourceFile.isFile());// w ww  .j  av  a  2  s .c  o m

    final String name = sourceFile.getName();
    final File targetFile = new File(targetDirectory, name);
    targetFile.createNewFile();

    Files.copy(sourceFile.toPath(), targetFile.toPath(), REPLACE_EXISTING);

    assertTrue(targetFile.isFile());

    return targetFile;
}