Example usage for java.nio.file Path toFile

List of usage examples for java.nio.file Path toFile

Introduction

In this page you can find the example usage for java.nio.file Path toFile.

Prototype

default File toFile() 

Source Link

Document

Returns a File object representing this path.

Usage

From source file:com.samsung.sjs.Compiler.java

public static Process exec(boolean should_inherit_io, String... args) throws IOException {
    System.err.println("Executing: " + Arrays.toString(args));
    Path tmp = Files.createTempDirectory("testing");
    tmp.toFile().deleteOnExit();
    ProcessBuilder pb = new ProcessBuilder(args);
    pb.directory(tmp.toFile());/*from   ww  w. jav a  2  s. c  o  m*/
    if (should_inherit_io) {
        pb.inheritIO();
    }
    return pb.start();
}

From source file:com.sonar.it.scanner.msbuild.TestUtils.java

public static void runMSBuild(Orchestrator orch, Path projectDir, String... arguments) {
    String msBuildPathStr = orch.getConfiguration().getString(MSBUILD_PATH,
            "C:\\Program Files (x86)\\MSBuild\\14.0\\bin\\MSBuild.exe");
    Path msBuildPath = Paths.get(msBuildPathStr).toAbsolutePath();
    if (!Files.exists(msBuildPath)) {
        throw new IllegalStateException("Unable to find MSBuild at " + msBuildPath.toString()
                + ". Please configure property '" + MSBUILD_PATH + "'");
    }/*from  w  w  w .j  a  v a 2s.c o m*/

    int r = CommandExecutor.create().execute(
            Command.create(msBuildPath.toString()).addArguments(arguments).setDirectory(projectDir.toFile()),
            60 * 1000);
    assertThat(r).isEqualTo(0);
}

From source file:org.elasticsearch.xpack.security.authc.saml.SamlRealm.java

@SuppressForbidden(reason = "uses toFile")
private static Tuple<AbstractReloadingMetadataResolver, Supplier<EntityDescriptor>> parseFileSystemMetadata(
        Logger logger, String metadataPath, RealmConfig config, ResourceWatcherService watcherService)
        throws ResolverException, ComponentInitializationException, IOException, PrivilegedActionException {

    final String entityId = require(config, IDP_ENTITY_ID);
    final Path path = config.env().configFile().resolve(metadataPath);
    final FilesystemMetadataResolver resolver = new FilesystemMetadataResolver(path.toFile());

    if (IDP_METADATA_HTTP_REFRESH.exists(config.settings())) {
        logger.info("Ignoring setting [{}] because the IdP metadata is being loaded from a file",
                RealmSettings.getFullSettingKey(config, IDP_METADATA_HTTP_REFRESH));
    }/*  www  .j  a  v  a  2  s  .  c om*/

    // We don't want to rely on the internal OpenSAML refresh timer, but we can't turn it off, so just set it to run once a day.
    // @TODO : Submit a patch to OpenSAML to optionally disable the timer
    final long oneDayMs = TimeValue.timeValueHours(24).millis();
    resolver.setMinRefreshDelay(oneDayMs);
    resolver.setMaxRefreshDelay(oneDayMs);
    initialiseResolver(resolver, config);

    FileWatcher watcher = new FileWatcher(path);
    watcher.addListener(new FileListener(logger, resolver::refresh));
    watcherService.add(watcher, ResourceWatcherService.Frequency.MEDIUM);
    return new Tuple<>(resolver, () -> resolveEntityDescriptor(resolver, entityId, path.toString()));
}

From source file:it.baeyens.arduino.managers.Manager.java

private static void loadLibraryIndex(boolean download) {
    try {/* w  w  w  .j a  v  a2 s . c o  m*/
        URL librariesUrl = new URL(Defaults.LIBRARIES_URL);
        String localFileName = Paths.get(librariesUrl.getPath()).getFileName().toString();
        Path librariesPath = Paths
                .get(ConfigurationPreferences.getInstallationPath().append(localFileName).toString());
        File librariesFile = librariesPath.toFile();
        if (!librariesFile.exists() || download) {
            librariesPath.getParent().toFile().mkdirs();
            Files.copy(librariesUrl.openStream(), librariesPath, StandardCopyOption.REPLACE_EXISTING);
        }
        if (librariesFile.exists()) {
            try (InputStreamReader reader = new InputStreamReader(new FileInputStream(librariesFile),
                    Charset.forName("UTF8"))) { //$NON-NLS-1$
                libraryIndex = new Gson().fromJson(reader, LibraryIndex.class);
                libraryIndex.resolve();
            }
        }
    } catch (IOException e) {
        Common.log(new Status(IStatus.WARNING, Activator.getId(), "Failed to load library index", e)); //$NON-NLS-1$
    }

}

From source file:it.baeyens.arduino.managers.Manager.java

/**
 * Given a platform description in a json file download and install all
 * needed stuff. All stuff is including all tools and core files and
 * hardware specific libraries. That is (on windows) inclusive the make.exe
 * /*from   w ww .j a  v a2s.c o  m*/
 * @param platform
 * @param monitor
 * @param object
 * @return
 */
static public IStatus downloadAndInstall(ArduinoPlatform platform, boolean forceDownload,
        IProgressMonitor monitor) {

    IStatus status = downloadAndInstall(platform.getUrl(), platform.getArchiveFileName(),
            platform.getInstallPath(), forceDownload, monitor);
    if (!status.isOK()) {
        return status;
    }
    MultiStatus mstatus = new MultiStatus(status.getPlugin(), status.getCode(), status.getMessage(),
            status.getException());

    for (ToolDependency tool : platform.getToolsDependencies()) {
        monitor.setTaskName(InstallProgress.getRandomMessage());
        mstatus.add(tool.install(monitor));
    }
    // On Windows install make from equations.org
    if (Platform.getOS().equals(Platform.OS_WIN32)) {
        try {
            Path makePath = Paths
                    .get(ConfigurationPreferences.getPathExtensionPath().append("make.exe").toString()); //$NON-NLS-1$
            if (!makePath.toFile().exists()) {
                Files.createDirectories(makePath.getParent());
                URL makeUrl = new URL("ftp://ftp.equation.com/make/32/make.exe"); //$NON-NLS-1$
                Files.copy(makeUrl.openStream(), makePath);
                makePath.toFile().setExecutable(true, false);
            }

        } catch (IOException e) {
            mstatus.add(new Status(IStatus.ERROR, Activator.getId(), Messages.Manager_Downloading_make_exe, e));
        }
    }

    return mstatus.getChildren().length == 0 ? Status.OK_STATUS : mstatus;

}

From source file:com.themodernway.server.core.file.vfs.simple.SimpleFileItemStorage.java

protected static final IFileItem make(final Path path, final IFileItemStorage stor) {
    return make(path.toFile(), stor);
}

From source file:net.mozq.picto.core.ProcessCore.java

private static ImageMetadata getImageMetadata(Path imagePath) throws IOException {
    File imageFile = imagePath.toFile();

    ImageMetadata imageMetadata;/*from ww w.j  av a2s  . c o  m*/
    try {
        imageMetadata = Imaging.getMetadata(imageFile);
    } catch (ImageReadException e) {
        imageMetadata = null;
    }

    return imageMetadata;
}

From source file:net.mozq.picto.core.ProcessCore.java

private static Date getPhotoTakenDate(Path imagePath, ImageMetadata imageImageMetadata) {
    File imageFile = imagePath.toFile();

    Date photoTakenDate;/*from   w  ww .j  a v  a2s  . co m*/
    try {
        photoTakenDate = getExifDate(imageImageMetadata);
    } catch (IOException e) {
        photoTakenDate = null;
    }

    if (photoTakenDate == null) {
        photoTakenDate = new Date(imageFile.lastModified());
    }

    return photoTakenDate;
}

From source file:io.sloeber.core.managers.Manager.java

/**
 * convert a web url to a local file name. The local file name is the cache
 * of the web//  w w  w  .j a  v  a2 s  .c  o  m
 *
 * @param url
 *            url of the file we want a local cache
 * @return the file that represents the file that is the local cache. the
 *         file itself may not exists. If the url is malformed return null;
 * @throws MalformedURLException
 */
public static File getLocalFileName(String url) {
    URL packageUrl;
    try {
        packageUrl = new URL(url.trim());
    } catch (MalformedURLException e) {
        Common.log(new Status(IStatus.ERROR, Activator.getId(), "Malformed url " + url, e)); //$NON-NLS-1$
        return null;
    }
    String localFileName = Paths.get(packageUrl.getPath()).getFileName().toString();
    Path packagePath = Paths
            .get(ConfigurationPreferences.getInstallationPath().append(localFileName).toString());
    return packagePath.toFile();
}

From source file:listduplicatingfiles.ListDuplicatingFiles.java

public void listDuplicatingFiles(Path dir) {
    File myFile = dir.toFile();
    List<File> nonDuplicated = new LinkedList<File>();

    for (File fileEntry : myFile.listFiles()) {
        if (fileEntry.isDirectory()) {

            System.out.println(fileEntry.getName());
            listDuplicatingFiles(fileEntry.toPath());

        } else {/*w ww .  j  a  va  2 s .c  o  m*/
            if (!isDuplicated(nonDuplicated, fileEntry)) {
                nonDuplicated.add(fileEntry);
            }
            //System.out.println(fileEntry.getName());
        }
    }

    for (File file : nonDuplicated) {
        System.out.println(file);
    }

}