Example usage for java.nio.file Path toString

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

Introduction

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

Prototype

String toString();

Source Link

Document

Returns the string representation of this path.

Usage

From source file:edu.jhu.hlt.concrete.ingesters.annotatednyt.AnnotatedNYTIngesterRunner.java

/**
 * @param args/*from ww  w  .  j  ava2s .  c  om*/
 */
public static void main(String... args) {
    Thread.setDefaultUncaughtExceptionHandler(new LoggedUncaughtExceptionHandler());
    AnnotatedNYTIngesterRunner run = new AnnotatedNYTIngesterRunner();
    JCommander jc = new JCommander(run, args);
    jc.setProgramName(AnnotatedNYTIngesterRunner.class.getSimpleName());
    if (run.delegate.help) {
        jc.usage();
    }

    try {
        Path outpath = Paths.get(run.delegate.outputPath);
        IngesterParameterDelegate.prepare(outpath);

        NYTCorpusDocumentParser parser = new NYTCorpusDocumentParser();
        for (String pstr : run.delegate.paths) {
            LOGGER.debug("Running on file: {}", pstr);
            Path p = Paths.get(pstr);
            new ExistingNonDirectoryFile(p);
            int nPaths = p.getNameCount();
            Path year = p.getName(nPaths - 2);
            Path outWithExt = outpath.resolve(year.toString() + p.getFileName());

            if (Files.exists(outWithExt)) {
                if (!run.delegate.overwrite) {
                    LOGGER.info("File: {} exists and overwrite disabled. Not running.", outWithExt.toString());
                    continue;
                } else {
                    Files.delete(outWithExt);
                }
            }

            try (InputStream is = Files.newInputStream(p);
                    BufferedInputStream bin = new BufferedInputStream(is);
                    TarGzArchiveEntryByteIterator iter = new TarGzArchiveEntryByteIterator(bin);

                    OutputStream os = Files.newOutputStream(outWithExt);
                    GzipCompressorOutputStream gout = new GzipCompressorOutputStream(os);
                    TarArchiver arch = new TarArchiver(gout)) {
                Iterable<byte[]> able = () -> iter;
                StreamSupport.stream(able.spliterator(), false).map(ba -> parser.fromByteArray(ba, false))
                        .map(doc -> new AnnotatedNYTDocument(doc))
                        .map(and -> new CommunicationizableAnnotatedNYTDocument(and).toCommunication())
                        .forEach(comm -> {
                            try {
                                arch.addEntry(new ArchivableCommunication(comm));
                            } catch (IOException e) {
                                LOGGER.error("Caught exception processing file: " + pstr, e);
                            }
                        });
            }
        }
    } catch (NotFileException | IOException e) {
        LOGGER.error("Caught exception processing.", e);
    }
}

From source file:ratpack.spark.jobserver.Main.java

public static void main(String... args) throws Exception {
    RatpackServer ratpackServer = RatpackServer.start(spec -> spec.serverConfig(builder -> {
        Path basePath = BaseDir.find("application.properties");
        LOGGER.debug("BASE DIR: {}", basePath.toString());
        builder.baseDir(BaseDir.find("application.properties")).env().sysProps();

        Path localAppProps = Paths.get("../../config/application.properties");
        if (Files.exists(localAppProps)) {
            LOGGER.debug("LOCALLY OVERLOADED application.properties: {}", localAppProps.toUri().toString());
            builder.props(localAppProps);
        } else {//from  w  w w  . ja v  a  2s .c om
            URL cpAppProps = Main.class.getClassLoader().getResource("config/application.properties");
            LOGGER.debug("CLASSPATH OVERLOADED application.properties: {}",
                    cpAppProps != null ? cpAppProps.toString() : "DEFAULT LOCATION");
            builder.props(cpAppProps != null ? cpAppProps
                    : Main.class.getClassLoader().getResource("application.properties"));
        }

        Path localSparkJobsProps = Paths.get("../../config/sparkjobs.properties");
        if (Files.exists(localSparkJobsProps)) {
            LOGGER.debug("LOCALLY OVERLOADED sparkjobs.properties: {}", localSparkJobsProps.toUri().toString());
            builder.props(localSparkJobsProps);
        } else {
            URL cpSparkJobsProps = Main.class.getClassLoader().getResource("config/sparkjobs.properties");
            LOGGER.debug("CLASSPATH OVERLOADED SPARKJOBS.PROPS: {}",
                    cpSparkJobsProps != null ? cpSparkJobsProps.toString() : "DEFAULT LOCATION");
            builder.props(cpSparkJobsProps != null ? cpSparkJobsProps
                    : Main.class.getClassLoader().getResource("sparkjobs.properties"));
        }

        builder.require("/spark", SparkConfig.class).require("/job", SparkJobsConfig.class);
    }).registry(Guice.registry(bindingsSpec -> bindingsSpec.bindInstance(ResponseTimer.decorator())
            .module(ContainersModule.class).module(SparkModule.class)
            .bindInstance(new ObjectMapper().writerWithDefaultPrettyPrinter())))
            .handlers(chain -> chain.all(ctx -> {
                LOGGER.debug("ALL");
                MDC.put("clientIP", ctx.getRequest().getRemoteAddress().getHostText());
                RequestId.Generator generator = ctx.maybeGet(RequestId.Generator.class)
                        .orElse(UuidBasedRequestIdGenerator.INSTANCE);
                RequestId requestId = generator.generate(ctx.getRequest());
                ctx.getRequest().add(RequestId.class, requestId);
                MDC.put("requestId", requestId.toString());
                ctx.next();
            }).prefix("v1", chain1 -> chain1.all(RequestLogger.ncsa()).get("api-def", ctx -> {
                LOGGER.debug("GET API_DEF.JSON");
                SparkJobsConfig config = ctx.get(SparkJobsConfig.class);
                LOGGER.debug("SPARK JOBS CONFIG: " + config.toString());
                ctx.render(ctx.file("public/apidef/apidef.json"));
            }).prefix("spark", JobsEndpoints.class))));
    LOGGER.debug("STARTED: {}://{}:{}", ratpackServer.getScheme(), ratpackServer.getBindHost(),
            ratpackServer.getBindPort());
}

From source file:ru.histone.staticrender.StaticRender.java

public static void main(String... args) throws IOException {
    Path workDir = Paths.get(".").toRealPath();
    log.info("Working dir={}", workDir.toString());

    Path srcDir = workDir.resolve("src/site");
    Path dstDir = workDir.resolve("build/site");

    StaticRender app = new StaticRender();
    app.renderSite(srcDir, dstDir);//from  w  ww .j  a va2 s.  co  m
}

From source file:de.qaware.chronix.spark.api.java.ExternalizeTestData.java

/**
 * @param args optional first argument: file to serialize to. A default file name is provided.
 * @throws SolrServerException/*from  w w w.j a v a2s  . c om*/
 * @throws FileNotFoundException
 */
public static void main(String[] args) throws SolrServerException, IOException {

    ChronixSparkLoader chronixSparkLoader = new ChronixSparkLoader();
    ChronixYAMLConfiguration config = chronixSparkLoader.getConfig();

    String file = (args.length >= 1) ? args[0] : config.getTestdataFile();

    Path filePath = Paths.get(file);
    Files.deleteIfExists(filePath);
    Output output = new Output(new DeflaterOutputStream(new FileOutputStream(filePath.toString())));
    System.out.println("Opening test data file: " + filePath.toString());

    ChronixSparkContext cSparkContext = null;

    //Create target file
    try {
        //Create Chronix Spark context
        cSparkContext = chronixSparkLoader.createChronixSparkContext();

        //Read data into ChronixRDD
        SolrQuery query = new SolrQuery(config.getSolrReferenceQuery());
        ChronixRDD rdd = cSparkContext.queryChronixChunks(query, config.getZookeeperHost(),
                config.getChronixCollection(), config.getStorage());

        System.out.println("Writing " + rdd.count() + " time series into test data file.");

        //Loop through result and serialize it to disk
        Kryo kryo = new Kryo();
        List<MetricTimeSeries> mtsList = IteratorUtils.toList(rdd.iterator());
        System.out.println("Writing objects...");
        kryo.writeObject(output, mtsList);
        output.flush();
        System.out.println("Objects written.");
    } finally {
        output.close();
        if (cSparkContext != null) {
            cSparkContext.getSparkContext().close();
        }
        System.out.println("Test data file written successfully!");
    }
}

From source file:edu.jhu.hlt.concrete.ingesters.gigaword.GigawordGzProcessor.java

public static void main(String... args) {
    Thread.setDefaultUncaughtExceptionHandler(new LoggedUncaughtExceptionHandler());
    if (args.length != 2) {
        LOGGER.info("This program takes 2 arguments.");
        LOGGER.info("First: the path to a .gz file that is part of the English Gigaword v5 corpus.");
        LOGGER.info("Second: the path to the output file (a .tar.gz with communication files).");
        LOGGER.info("Example usage:");
        LOGGER.info("{} {} {}", GigawordGzProcessor.class.getName(), "/path/to/LDC/sgml/.gz",
                "/path/to/out.tar.gz");
        System.exit(1);/*from  www .ja v a  2s.  c o  m*/
    }

    String inPathStr = args[0];
    String outPathStr = args[1];

    Path inPath = Paths.get(inPathStr);
    if (!Files.exists(inPath))
        LOGGER.error("Input path {} does not exist. Try again with the right path.", inPath.toString());

    Path outPath = Paths.get(outPathStr);
    Optional<Path> parent = Optional.ofNullable(outPath.getParent());
    // lambda does not allow caught exceptions.
    if (parent.isPresent()) {
        if (!Files.exists(outPath.getParent())) {
            LOGGER.info("Attempting to create output directory: {}", outPath.toString());
            try {
                Files.createDirectories(outPath);
            } catch (IOException e) {
                LOGGER.error("Caught exception creating output directory.", e);
            }
        }
    }

    GigawordDocumentConverter conv = new GigawordDocumentConverter();
    Iterator<Communication> iter = conv.gzToStringIterator(inPath);
    try (OutputStream os = Files.newOutputStream(outPath);
            BufferedOutputStream bos = new BufferedOutputStream(os, 1024 * 8 * 16);
            GzipCompressorOutputStream gout = new GzipCompressorOutputStream(bos);
            TarArchiver archiver = new TarArchiver(gout);) {
        while (iter.hasNext()) {
            Communication c = iter.next();
            LOGGER.info("Adding Communication {} [UUID: {}] to archive.", c.getId(),
                    c.getUuid().getUuidString());
            archiver.addEntry(new ArchivableCommunication(c));
        }
    } catch (IOException e) {
        LOGGER.error("Caught IOException during output.", e);
    }
}

From source file:de.kaixo.mubi.lists.store.MubiListsToElasticSearchLoader.java

public static void main(String arg[]) {
    if (arg.length < 1) {
        logger.error("Usage: MubiListsToElasticSearchLoader <directory>");
        System.exit(1);// ww w  . j a  v  a 2  s. c  o  m
    }

    Path path = Paths.get(arg[0]);

    if (!Files.isDirectory(path)) {
        logger.error("Does not exist or is not a directory: " + path.toString());
        System.exit(1);
    }

    MubiListsToElasticSearchLoader loader = new MubiListsToElasticSearchLoader();
    if (loader.prepareIndex(true))
        loader.loadAllFromDir(path);
    loader.close();
}

From source file:io.github.dsheirer.record.wave.MonoWaveReader.java

public static void main(String[] args) {
    Path path = Paths.get("/home/denny/Music/PCM.wav");
    mLog.debug("Opening: " + path.toString());

    try {//from ww w  .ja  va2s.c  om
        MonoWaveReader reader = new MonoWaveReader(path, true);
        reader.setListener(new Listener<RealBuffer>() {
            @Override
            public void receive(RealBuffer realBuffer) {
                mLog.debug("Received buffer");
            }
        });
        reader.read();
    } catch (IOException e) {
        mLog.error("Error", e);
    }

    mLog.debug("Finished");
}

From source file:edu.jhu.hlt.concrete.ingesters.gigaword.GigawordDocumentConverter.java

public static void main(String... args) {
    if (args.length != 2) {
        LOGGER.info("This program takes 2 arguments:");
        LOGGER.info("The first is a path to an LDC SGML file. These include Gigaword documents.");
        LOGGER.info("The second is a path to the output, where the Concrete Communication will be written.");
        LOGGER.info("Usage: {} {} {}", GigawordDocumentConverter.class.getName(), "/path/to/input/sgml/file",
                "/path/to/output/file");
        System.exit(1);//from ww w  .j a va  2s  .c  om
    }

    String pathStr = args[0];
    String outStr = args[1];

    Path path = Paths.get(pathStr);
    if (!Files.exists(path)) {
        LOGGER.error("Path {} does not exist.", path.toString());
        System.exit(1);
    }

    try {
        Communication c = new GigawordDocumentConverter().fromPath(path);
        new WritableCommunication(c).writeToFile(Paths.get(outStr), true);
    } catch (ConcreteException | IOException e) {
        LOGGER.error("Caught Exception during conversion.", e);
    }
}

From source file:edu.jhu.hlt.concrete.ingesters.bolt.BoltIngesterRunner.java

/**
 * @param args//ww  w . j a  v  a 2s  .  c om
 */
public static void main(String... args) {
    Thread.setDefaultUncaughtExceptionHandler(new LoggedUncaughtExceptionHandler());
    BoltIngesterRunner run = new BoltIngesterRunner();
    JCommander jc = new JCommander(run, args);
    jc.setProgramName(BoltIngesterRunner.class.getSimpleName());
    if (run.delegate.help) {
        jc.usage();
    }

    try {
        Path outpath = Paths.get(run.delegate.outputPath);
        IngesterParameterDelegate.prepare(outpath);
        BoltForumPostIngester ing = new BoltForumPostIngester();
        Path outWithExt = outpath.resolve("bolt.tar.gz");

        if (Files.exists(outWithExt)) {
            if (!run.delegate.overwrite) {
                LOGGER.info("File: {} exists and overwrite disabled. Not running.", outWithExt.toString());
                return;
            } else {
                Files.delete(outWithExt);
            }
        }

        try (OutputStream os = Files.newOutputStream(outWithExt);
                GzipCompressorOutputStream gout = new GzipCompressorOutputStream(os);
                TarArchiver arch = new TarArchiver(gout)) {
            for (Path p : run.delegate.findFilesInPaths()) {
                LOGGER.debug("Running on file: {}", p);
                new ExistingNonDirectoryFile(p);
                try {
                    Communication next = ing.fromCharacterBasedFile(p);
                    arch.addEntry(new ArchivableCommunication(next));
                } catch (IngestException e) {
                    LOGGER.error("Error processing file: " + p, e);
                }
            }
        }
    } catch (NotFileException | IOException e) {
        LOGGER.error("Caught exception processing.", e);
    }
}

From source file:edu.jhu.hlt.concrete.ingesters.webposts.WebPostIngesterRunner.java

/**
 * @param args/*from w  w w. j  a  v  a 2 s  .co  m*/
 */
public static void main(String... args) {
    Thread.setDefaultUncaughtExceptionHandler(new LoggedUncaughtExceptionHandler());
    WebPostIngesterRunner run = new WebPostIngesterRunner();
    JCommander jc = new JCommander(run, args);
    jc.setProgramName(WebPostIngesterRunner.class.getSimpleName());
    if (run.delegate.help) {
        jc.usage();
    }

    try {
        Path outpath = Paths.get(run.delegate.outputPath);
        IngesterParameterDelegate.prepare(outpath);
        WebPostIngester ing = new WebPostIngester();
        Path outWithExt = outpath.resolve("webposts.tar.gz");

        if (Files.exists(outWithExt)) {
            if (!run.delegate.overwrite) {
                LOGGER.info("File: {} exists and overwrite disabled. Not running.", outWithExt.toString());
                return;
            } else {
                Files.delete(outWithExt);
            }
        }

        try (OutputStream os = Files.newOutputStream(outWithExt);
                GzipCompressorOutputStream gout = new GzipCompressorOutputStream(os);
                TarArchiver arch = new TarArchiver(gout)) {
            for (String pstr : run.delegate.paths) {
                LOGGER.debug("Running on file: {}", pstr);
                Path p = Paths.get(pstr);
                new ExistingNonDirectoryFile(p);
                try {
                    Communication next = ing.fromCharacterBasedFile(p);
                    arch.addEntry(new ArchivableCommunication(next));
                } catch (IngestException e) {
                    LOGGER.error("Error processing file: " + pstr, e);
                }
            }
        }
    } catch (NotFileException | IOException e) {
        LOGGER.error("Caught exception processing.", e);
    }
}