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:com.willkara.zeteo.filetypes.impl.BaseFileType.java

/**
 * Creates the BaseFileType object from the Java {@link java.io.File} class
 * as an argument./*  www  . j  a  v a  2s. c  o  m*/
 *
 * @param f The file object
 */
public BaseFileType(File f) {

    if (f.isFile()) {
        BasicFileAttributes attr;
        try {
            attr = Files.readAttributes(f.toPath(), BasicFileAttributes.class);

            fileName = f.getName();
            filePath = f.getCanonicalPath();
            fileSize = f.length();

            lastModifiedDate = new Date(attr.lastModifiedTime().toMillis());
            createdDate = new Date(attr.creationTime().toMillis());
            lastAccessDate = new Date(attr.lastAccessTime().toMillis());
        } catch (IOException ex) {
            Logger.getLogger(BaseFileType.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:com.qantium.data.Data.java

public File toCSV(File file, String delimiter) throws IOException {
    Files.write(file.toPath(), toCSV(delimiter).getBytes());
    return file;/*from ww  w .ja  v a2 s .c  o m*/
}

From source file:cpcc.ros.sim.osm.TileCacheTest.java

@BeforeMethod
public void setUp() throws Exception {
    File path = new File("target/");
    tempDirectory = Files.createTempDirectory(path.toPath(), "tmp-test").toFile();
    assertThat(tempDirectory).exists();//from  ww w.  ja v  a2  s.  c o m

    config = PowerMockito.mock(Configuration.class);
    PowerMockito.doReturn(tempDirectory.getAbsolutePath()).when(config).getTileCacheBaseDir();
    PowerMockito.doReturn("http://my.tile.server/%1$d/%2$d/%3$d.png").when(config).getTileServerUrl();

    sut = new TileCache(config);

    entity = Mockito.mock(HttpEntity.class);
    when(entity.getContent()).thenReturn(new ByteArrayInputStream(responseData.getBytes("UTF-8")));

    response = PowerMockito.mock(CloseableHttpResponse.class);
    PowerMockito.when(response.getStatusLine()).thenReturn(statusLine200ok);
    PowerMockito.when(response.getEntity()).thenReturn(entity);

    client = PowerMockito.mock(CloseableHttpClient.class);
    PowerMockito.doReturn(response).when(client).execute(any(HttpUriRequest.class));

    httpClientBuilderMock = PowerMock.createMock(HttpClientBuilder.class);

    PowerMock.mockStatic(HttpClientBuilder.class);
    EasyMock.expect(HttpClientBuilder.create()).andReturn(httpClientBuilderMock).anyTimes();
    PowerMock.replay(HttpClientBuilder.class);
    EasyMock.expect(httpClientBuilderMock.setUserAgent(USER_AGENT)).andReturn(httpClientBuilderMock).anyTimes();
    PowerMock.replay(HttpClientBuilder.class);
    EasyMock.expect(httpClientBuilderMock.build()).andReturn(client).anyTimes();
    PowerMock.replay(HttpClientBuilder.class, httpClientBuilderMock);
}

From source file:com.arpnetworking.configuration.jackson.JsonNodeDirectorySourceTest.java

@Test
public void testDirectoryOnlyMatchingNames() throws IOException {
    final File directory = new File(
            "./target/tmp/filter/JsonNodeDirectorySourceTest/testDirectoryOnlyMatchingNames");
    deleteDirectory(directory);//from  w  w w  . jav a  2s.c om
    Files.createDirectory(directory.toPath());
    Files.write(directory.toPath().resolve("foo.json"), "[\"one\"]".getBytes(Charsets.UTF_8));
    Files.write(directory.toPath().resolve("bar.txt"), "[\"two\"]".getBytes(Charsets.UTF_8));
    final JsonNodeDirectorySource source = new JsonNodeDirectorySource.Builder().setDirectory(directory)
            .addFileName("foo.json").build();
    Assert.assertTrue(source.getJsonNode().isPresent());
    Assert.assertTrue(source.getJsonNode().get().isArray());
    final ArrayNode arrayNode = (ArrayNode) source.getJsonNode().get();
    Assert.assertEquals(1, arrayNode.size());
    Assert.assertTrue(arrayNodeContains(arrayNode, "one"));
}

From source file:com.netflix.genie.agent.execution.statemachine.actions.ShutdownAction.java

/**
 * {@inheritDoc}//w w  w. j  a v  a2  s  .c  o  m
 */
@Override
protected Events executeStateAction(final ExecutionContext executionContext) {
    log.info("Shutting down...");

    if (executionContext.getJobSpecification().isPresent()) {
        final JobSpecification jobSpecification = executionContext.getJobSpecification().get();
        if (jobSpecification.getArchiveLocation().isPresent()) {
            final String archiveLocation = jobSpecification.getArchiveLocation().get();
            if (StringUtils.isNotBlank(archiveLocation) && executionContext.getJobDirectory().isPresent()) {
                final File jobDirectory = executionContext.getJobDirectory().get();
                try {
                    log.info("Attempting to archive job folder to: " + archiveLocation);
                    this.jobArchiveService.archiveDirectory(jobDirectory.toPath(), new URI(archiveLocation));
                    log.info("Job folder archived to: " + archiveLocation);
                } catch (JobArchiveException | URISyntaxException e) {
                    log.error("Error archiving job folder", e);
                }
            }
        }
    }

    return Events.SHUTDOWN_COMPLETE;
}

From source file:algorithm.F5Steganography.java

private String getOutputString(File carrier) {
    File outputFile = getOutputFile(carrier);
    outputFile.delete(); // F5 won't override existing files!
    return "" + outputFile.toPath();
}

From source file:at.nonblocking.cliwix.cli.Options.java

void copyDefaultPropertiesTo(File file) throws CliwixCliClientArgumentException {
    try {//from ww w  .  j  av  a 2 s  .  c  o m
        Files.copy(getDefaultProperties(), file.toPath());
    } catch (IOException e) {
        throw new CliwixCliClientArgumentException("Unable to store config: " + file.getAbsolutePath());
    }
}

From source file:com.github.rwhogg.git_vcr.review.ReviewResults.java

/**
 * review runs the code review on each file
 * @throws ClassNotFoundException If we cannot find a review tool class
 * @throws ReviewFailedException If code review failed for some reason
 * @throws IllegalAccessException If we cannot access a review tool class
 * @throws InstantiationException if we cannot instantiate a review tool class
 *//*w  w  w.  j a va2  s. c  o  m*/
@SuppressWarnings("rawtypes")
public void review()
        throws InstantiationException, IllegalAccessException, ClassNotFoundException, ReviewFailedException {
    Map<String, List<ReviewTool>> tests = getTests();
    results = new HashMap<>();
    for (ImmutablePair<String, String> changePair : Util.getFilesChanged(patch)) {
        String oldFileName = changePair.left;
        String newFileName = changePair.right;

        // FIXME: what to do if one or more is null?

        // FIXME: not sure what to do about this case. For now, just assert.
        assert FilenameUtils.getExtension(oldFileName).equals(FilenameUtils.getExtension(newFileName));

        File file = new File(isNew ? newFileName : oldFileName);

        String mimeType = null;
        try {
            mimeType = Files.probeContentType(file.toPath());
        } catch (IOException e) {
            // FIXME Auto-generated catch block
            e.printStackTrace();
        }

        // run the tests
        List<ReviewTool> tools = tests.get(mimeType);
        Map<Class, List<String>> resultsForThisFile = new HashMap<>();
        if (tools != null) {
            for (ReviewTool tool : tools) {
                List<String> resultsFromTool;
                resultsFromTool = tool.getResults(file);
                resultsForThisFile.put(tool.getClass(), resultsFromTool);
            }
        }
        results.put(oldFileName, resultsForThisFile);
    }
}

From source file:net.sf.jasperreports.repo.FileRepositoryService.java

@Override
public ResourceInfo getResourceInfo(RepositoryContext context, String location) {
    File file = getFile(context, location);
    if (file != null) {
        try {//from  www. ja v  a 2s  .c  o m
            Path filePath = file.toPath().toRealPath();
            if (rootRealPath != null && filePath.startsWith(rootRealPath)) {
                Path relativePath = rootRealPath.relativize(filePath);
                return StandardResourceInfo.from(relativePath);
            } else if (resolveAbsolutePath) {
                return StandardResourceInfo.from(filePath);
            }
        } catch (IOException e) {
            log.warn("Failed to resolve real path for file " + file, e);
        }
    }
    return null;
}

From source file:com.linkedin.pinot.core.segment.index.converter.SegmentV1V2ToV3FormatConverter.java

private void copyCreationMetadata(File currentDir, File v3Dir) throws IOException {
    File v2CreationFile = new File(currentDir, V1Constants.SEGMENT_CREATION_META);
    File v3CreationFile = new File(v3Dir, V1Constants.SEGMENT_CREATION_META);
    Files.copy(v2CreationFile.toPath(), v3CreationFile.toPath());
}