Example usage for java.nio.file Paths get

List of usage examples for java.nio.file Paths get

Introduction

In this page you can find the example usage for java.nio.file Paths get.

Prototype

public static Path get(String first, String... more) 

Source Link

Document

Converts a path string, or a sequence of strings that when joined form a path string, to a Path .

Usage

From source file:com.justgiving.raven.kissmetrics.utils.KissmetricsLocalSchemaExtractor.java

/****
 * This function parses all the json record files in a folder and returns a counts of the total occurrences of keys
 * in all files// w  w  w.j  ava  2  s. co m
 * 
 * @param inputFolder
 * @param outputFolder
 * @throws IOException
 */
private static void countKeysInJsonRecordsFolder(String inputFolder, String outputFile) throws IOException {
    File folder = new File(inputFolder);
    File[] listOfFiles = folder.listFiles();
    KeyValueCounter totalKeyValueCounter = new KeyValueCounter();
    KeyValueCounter currentKeyValueCounter = new KeyValueCounter();
    for (File currentFile : listOfFiles) {
        if (currentFile.isFile()) {
            logger.info("Processing file: " + currentFile.getName());
            currentKeyValueCounter = countKeysInJsonRecordsFile(
                    Paths.get(inputFolder, currentFile.getName()).toString());
            totalKeyValueCounter = deepMergeKeyValueCounter(totalKeyValueCounter, currentKeyValueCounter);
        } else if (currentFile.isDirectory()) {
            logger.warn("Sub-directory folders are currently ignored");
        }
    }
    //System.out.println(totalKeyCounter.toString());
    logger.info("---------------");
    logger.info(sortOutputByKey(totalKeyValueCounter));
    logger.info("saving output to file: ");
    File outpuFile = new File(outputFile);
    outpuFile.getParentFile().mkdirs();
    PrintWriter out = new PrintWriter(outputFile);
    out.print(sortOutputByKey(totalKeyValueCounter));
    out.close();
}

From source file:com.reprezen.swagedit.validation.ErrorProcessorTest.java

@Test
public void testProcessNode_WithSingleError() throws Exception {
    JsonNode fixture = mapper.readTree(Paths.get("resources", "error-1.json").toFile());
    Set<SwaggerError> errors = processor.processMessageNode(fixture);

    assertEquals(1, errors.size());/*from ww w .ja v a2  s. c om*/
    assertTrue(getOnlyElement(errors) instanceof SwaggerError);
}

From source file:audiomanagershell.commands.FavCommand.java

@Override
public void execute() throws CommandException {
    Path file = Paths.get(this.pathRef.toString(), this.arg);

    if (!Files.exists(file))
        throw new FileNotFoundException(file.getFileName().toString());
    if (!Files.isRegularFile(file))
        throw new NotAFileException(file.getFileName().toString());

    List<String> validExtensions = Arrays.asList("wav", "mp3", "flac", "mp4");
    if (!validExtensions.contains(FilenameUtils.getExtension(file.toString())))
        throw new NotAudioFileException(file.toString());

    try (PrintWriter output = new PrintWriter(new FileWriter(favFile.toFile(), true));
            Scanner input = new Scanner(new FileReader(favFile.toString()))) {

        while (input.hasNextLine()) {
            if (input.nextLine().equals(file.toString())) {
                System.out.printf("File \"%s\" is already added to favorite List!%n", file);
                return;
            }/*  ww w . j ava 2 s . c  o m*/
        }
        System.out.printf("Added: \"%s\"%n", file);
        output.println(file);
    } catch (IOException ex) {
        throw new CommandException("Error related from I/O to file:" + favFile.toString());
    }
}

From source file:com.thoughtworks.go.buildsession.DownloadDirCommandExecutorTest.java

@Test
void downloadDirWithChecksum() throws Exception {
    File folder = temporaryFolder.newFolder("log");
    Files.write(Paths.get(folder.getPath(), "a"), "content for a".getBytes());
    Files.write(Paths.get(folder.getPath(), "b"), "content for b".getBytes());

    File zip = new ZipUtil().zip(folder, temporaryFolder.newFile("log.zip"), Deflater.NO_COMPRESSION);

    httpService.setupDownload("http://far.far.away/log.zip", zip);
    httpService.setupDownload("http://far.far.away/log.zip.md5",
            "s/log/a=524ebd45bd7de3616317127f6e639bd6\ns/log/b=83c0aa3048df233340203c74e8a93d7d");

    runBuild(downloadDir(map("url", "http://far.far.away/log.zip", "dest", "dest", "src", "s/log",
            "checksumUrl", "http://far.far.away/log.zip.md5")), Passed);
    File dest = new File(sandbox, "dest");

    assertThat(console.output()).contains(String
            .format("Saved artifact to [%s] after verifying the integrity of its contents", dest.getPath()));
    assertThat(FileUtils.readFileToString(new File(dest, "log/a"), UTF_8)).isEqualTo("content for a");
    assertThat(FileUtils.readFileToString(new File(dest, "log/b"), UTF_8)).isEqualTo("content for b");
}

From source file:com.github.ffremont.microservices.springboot.node.tasks.InstallPropertiesTask.java

@Override
public void run(MicroServiceTask task) throws InvalidInstallationException {
    Path msVersionFolder = helper.targetDirOf(task.getMs());

    byte[] content = msService.getContentOfProperties(task.getMs().getName());
    Path applicationProp = Paths.get(msVersionFolder.toString(), "application.properties");
    try {//w ww .j  ava  2 s. com
        Files.write(applicationProp, content);
        LOG.info("Cration du fichier de proprits {}", applicationProp.toAbsolutePath());
    } catch (IOException ex) {
        throw new InvalidInstallationException("Impossible d'installer le fichier de properties", ex);
    }
}

From source file:com.netflix.spinnaker.halyard.config.config.v1.HalconfigDirectoryStructure.java

public Path getInstallScriptPath(String deploymentName) {
    Path halconfigPath = Paths.get(halconfigDirectory, deploymentName);
    ensureDirectory(halconfigPath);//from w  w  w .  j  a  v  a 2  s.c o m
    return new File(halconfigPath.toFile(), "install.sh").toPath();
}

From source file:com.github.exper0.efilecopier.ftp.FtpInboundChannelAdapterSample.java

@Test
public void runDemo() throws Exception {
    Files.copy(this.getClass().getResourceAsStream("/test-files/a.txt"),
            Paths.get(TestSuite.FTP_ROOT_DIR, "a.txt"));
    Files.copy(this.getClass().getResourceAsStream("/test-files/b.txt"),
            Paths.get(TestSuite.FTP_ROOT_DIR, "b.txt"));
    FtpReportSettings settings = new FtpReportSettings();
    settings.setPort(4444);//from   ww w . j  av a  2s  .  c o m
    settings.setHost("localhost");
    settings.setLocalDir(LOCAL_FTP_TEMP_DIR + "/ftpInbound");
    settings.setRemoteDir("/");
    settings.setUser("demo");
    settings.setPassword("demo");
    FtpAdapterFactory factory = new FtpAdapterFactory();
    try (FileAdapter adapter = factory.createAdapter(settings)) {
        adapter.activate();
        PollableChannel ftpChannel = adapter.channel();
        Message<?> message1 = ftpChannel.receive(2000);
        Message<?> message2 = ftpChannel.receive(2000);
        Message<?> message3 = ftpChannel.receive(1000);

        LOGGER.info(String.format("Received first file message: %s.", message1));
        LOGGER.info(String.format("Received second file message: %s.", message2));
        LOGGER.info(String.format("Received nothing else: %s.", message3));

        assertNotNull(message1);
        assertNotNull(message2);
        assertNull("Was NOT expecting a third message.", message3);
    }
}

From source file:ch.bender.evacuate.Testconstants.java

/**
 * createNewFolder/*from  www.  j a va 2 s.c o m*/
 * <p>
 * @param aParent
 * @param aNewFolderStr
 * @return
 * @throws IOException
 */
public static Path createNewFolder(Path aParent, String aNewFolderStr) throws IOException {
    Path orig = Paths.get(aParent.toString(), aNewFolderStr);
    Files.createDirectory(orig);
    return orig;
}