Example usage for java.nio.file Path getFileName

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

Introduction

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

Prototype

Path getFileName();

Source Link

Document

Returns the name of the file or directory denoted by this path as a Path object.

Usage

From source file:com.seleniumtests.util.helper.AppTestDocumentation.java

private static void parseWebPage(Path path) throws FileNotFoundException {
    javadoc.append(String.format("\nh2. Page: %s\n", path.getFileName().toString()));

    FileInputStream in = new FileInputStream(path.toAbsolutePath().toString());

    // parse the file
    CompilationUnit cu = JavaParser.parse(in);

    // prints the resulting compilation unit to default system output
    cu.accept(new ClassVisitor(), "Pages");
    cu.accept(new WebPageMethodVisitor(), null);
}

From source file:com.seleniumtests.util.helper.AppTestDocumentation.java

private static void parseTest(Path path) throws FileNotFoundException {
    javadoc.append(String.format("\nh2. Tests: %s\n", path.getFileName().toString()));

    FileInputStream in = new FileInputStream(path.toAbsolutePath().toString());

    // parse the file
    CompilationUnit cu = JavaParser.parse(in);

    // prints the resulting compilation unit to default system output
    cu.accept(new ClassVisitor(), "Tests");
    cu.accept(new TestMethodVisitor(), null);
}

From source file:com.fizzed.stork.deploy.Archive.java

static public String format(Path file) {
    String name = file.getFileName().toString();
    if (name.endsWith(".tar.gz")) {
        return "tar.gz";
    } else if (name.endsWith(".zip")) {
        return "zip";
    } else {/*from   w ww .j  a v a2s . co  m*/
        return null;
    }
}

From source file:com.fizzed.stork.deploy.Archive.java

static private ArchiveInputStream newArchiveInputStream(Path file) throws IOException {
    String name = file.getFileName().toString();

    if (name.endsWith(".tar.gz")) {
        return new TarArchiveInputStream(new GzipCompressorInputStream(Files.newInputStream(file), true));
    } else if (name.endsWith(".zip")) {
        return new ZipArchiveInputStream(Files.newInputStream(file));
    } else {//from w w  w  .  j  av a 2 s.  c o  m
        throw new IOException("Unsupported archive file type (we support .tar.gz and .zip)");
    }
}

From source file:com.bc.fiduceo.ingest.IngestionTool.java

static Matcher getMatcher(Path filePath, Pattern pattern) {
    final String fileName = filePath.getFileName().toString();
    return pattern.matcher(fileName);
}

From source file:hrytsenko.csv.IO.java

/**
 * Gets records from file.//w  ww  . j  a  va2s.co m
 * 
 * <p>
 * If closure is given, then it will be applied to each record.
 * 
 * @param args
 *            the named arguments {@link IO}.
 * @param closure
 *            the closure to be applied to each record.
 * 
 * @return the loaded records.
 * 
 * @throws IOException
 *             if file could not be read.
 */
public static List<Record> load(Map<String, ?> args, Closure<?> closure) throws IOException {
    Path path = getPath(args);
    LOGGER.info("Load: {}.", path.getFileName());

    try (InputStream dataStream = newInputStream(path, StandardOpenOption.READ);
            InputStream bomStream = new BOMInputStream(dataStream);
            Reader dataReader = new InputStreamReader(bomStream, getCharset(args))) {
        CsvSchema csvSchema = getSchema(args).setUseHeader(true).build();
        CsvMapper csvMapper = new CsvMapper();
        ObjectReader csvReader = csvMapper.reader(Map.class).with(csvSchema);

        Iterator<Map<String, String>> rows = csvReader.readValues(dataReader);
        List<Record> records = new ArrayList<>();
        while (rows.hasNext()) {
            Map<String, String> row = rows.next();
            Record record = new Record();
            record.putAll(row);
            records.add(record);

            if (closure != null) {
                closure.call(record);
            }
        }
        return records;
    }
}

From source file:notaql.performance.PerformanceTest.java

public static void runTests() throws URISyntaxException, IOException {
    URI basePath = NotaQL.class.getResource(BASE_PATH).toURI();

    Map<String, String> env = new HashMap<>();
    env.put("create", "true");
    FileSystem zipfs = FileSystems.newFileSystem(basePath, env);

    final List<Path> tests = Files.list(Paths.get(basePath)).filter(p -> p.toString().endsWith(".json"))
            .sorted((a, b) -> a.toString().compareTo(b.toString())).collect(Collectors.toList());

    List<String> csv = new LinkedList<>();

    for (Path test : tests) {
        if (testCase != null && !test.getFileName().toString().equals(testCase))
            continue;

        final List<JSONObject> transformations = readArray(test);

        csv.add(test.getFileName().toString());

        int i = 1;

        for (JSONObject transformation : transformations) {
            final String name = transformation.getString("name");
            final String notaqlTransformation = composeTransformation(transformation);

            if (!(inEngine == null && outEngine == null
                    || inEngine != null/*w ww.j a v  a  2 s  .  c om*/
                            && transformation.getJSONObject("IN-ENGINE").getString("engine").equals(inEngine)
                    || outEngine != null && transformation.getJSONObject("OUT-ENGINE").getString("engine")
                            .equals(outEngine)))
                continue;

            System.out.println("Evaluation test (" + i++ + "/" + transformations.size() + "): "
                    + test.getFileName() + ": " + name);

            List<Duration> durations = new LinkedList<>();

            for (int j = 0; j < RUNS; j++) {
                clean(transformation);

                final Instant startTime = Instant.now();

                NotaQL.evaluate(notaqlTransformation);

                final Instant endTime = Instant.now();

                final Duration duration = Duration.between(startTime, endTime);

                durations.add(duration);

                System.out.println("Testrun(" + j + ") " + name + " took: " + duration);
            }

            System.out.println("!!=================================================================!!");

            System.out.println("Test " + name + " took: "
                    + durations.stream().map(Duration::toString).collect(Collectors.joining(", ")));

            System.out.println("Test " + name + " took millis: " + durations.stream()
                    .map(d -> Long.toString(d.toMillis())).collect(Collectors.joining(", ")));

            System.out.println("Test " + name + " took on average (millis): "
                    + durations.stream().mapToLong(Duration::toMillis).average());

            System.out.println("Test " + name + " took on average (ignoring first - millis): "
                    + durations.stream().skip(1).mapToLong(Duration::toMillis).average());

            System.out.println("!!=================================================================!!");

            csv.add(name);
            csv.add(durations.stream().map(d -> Long.toString(d.toMillis())).collect(Collectors.joining(",")));
        }

    }

    System.out.println(csv.stream().collect(Collectors.joining("\n")));
}

From source file:hrytsenko.csv.IO.java

/**
 * Saves records into CSV file./*from ww w.  j  a va 2 s.co m*/
 * 
 * <p>
 * If file already exists, then it will be overridden.
 * 
 * @param args
 *            the named arguments {@link IO}.
 * 
 * @throws IOException
 *             if file could not be written.
 */
public static void save(Map<String, ?> args) throws IOException {
    Path path = getPath(args);
    LOGGER.info("Save: {}.", path.getFileName());

    @SuppressWarnings("unchecked")
    Collection<Record> records = (Collection<Record>) args.get("records");
    if (records.isEmpty()) {
        LOGGER.info("No records to save.");
        return;
    }

    try (Writer dataWriter = newBufferedWriter(path, getCharset(args), StandardOpenOption.CREATE,
            StandardOpenOption.TRUNCATE_EXISTING)) {
        Set<String> columns = new LinkedHashSet<>();
        List<Map<String, String>> rows = new ArrayList<>();
        for (Record record : records) {
            Map<String, String> values = record.values();
            columns.addAll(values.keySet());
            rows.add(values);
        }

        CsvSchema.Builder csvSchema = getSchema(args).setUseHeader(true);
        for (String column : columns) {
            csvSchema.addColumn(column);
        }
        CsvMapper csvMapper = new CsvMapper();
        ObjectWriter csvWriter = csvMapper.writer().withSchema(csvSchema.build());
        csvWriter.writeValue(dataWriter, rows);
    }
}

From source file:com.fizzed.stork.deploy.Archive.java

static public Archive pack(Path unpackedDir, String format) throws IOException {
    String name = unpackedDir.getFileName().toString();
    Path archiveFile = unpackedDir.resolveSibling(name + "." + format);
    return pack(unpackedDir, archiveFile, format);
}

From source file:org.transitime.gtfs.GtfsUpdatedModule.java

/**
 * Copies the specified file to a directory at the same directory level but
 * with the directory name that is the last modified date of the file (e.g.
 * 03-28-2015).//from  w  w  w.j  ava  2 s.c om
 * 
 * @param fullFileName
 *            The full name of the file to be copied
 */
private static void archive(String fullFileName) {
    // Determine name of directory to archive file into. Use date of
    // lastModified time of file e.g. MM-dd-yyyy.
    File file = new File(fullFileName);
    Date lastModified = new Date(file.lastModified());
    String dirName = Time.dateStr(lastModified);

    // Copy the file to the sibling directory with the name that is the
    // last modified date (e.g. 03-28-2015)
    Path source = Paths.get(fullFileName);
    Path target = source.getParent().getParent().resolve(dirName).resolve(source.getFileName());

    logger.info("Archiving file {} to {}", source.toString(), target.toString());

    try {
        // Create the directory where file is to go
        String fullDirName = target.getParent().toString();
        new File(fullDirName).mkdir();

        // Copy the file to the directory
        Files.copy(source, target, StandardCopyOption.COPY_ATTRIBUTES);
    } catch (IOException e) {
        logger.error("Was not able to archive GTFS file {} to {}", source.toString(), target);
    }
}