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(URI uri) 

Source Link

Document

Converts the given URI to a Path object.

Usage

From source file:com.vaushell.superpipes.App.java

/**
 * Main method./*  w  ww .  ja v  a2  s .  c  o  m*/
 *
 * @param args Command line arguments
 * @throws Exception
 */
public static void main(final String... args) throws Exception {
    // My config
    final XMLConfiguration config = new XMLConfiguration();
    config.setDelimiterParsingDisabled(true);

    final long delay;
    final Path datas;
    switch (args.length) {
    case 1: {
        config.load(args[0]);
        datas = Paths.get("datas");
        delay = 10000L;

        break;
    }

    case 2: {
        config.load(args[0]);
        datas = Paths.get(args[1]);
        delay = 10000L;

        break;
    }

    case 3: {
        config.load(args[0]);
        datas = Paths.get(args[1]);
        delay = Long.parseLong(args[2]);

        break;
    }

    default: {
        config.load("conf/configuration.xml");
        datas = Paths.get("datas");
        delay = 10000L;

        break;
    }
    }

    final Dispatcher dispatcher = new Dispatcher();
    dispatcher.init(config, datas, new VC_SystemInputFactory());

    // Run
    dispatcher.start();

    // Wait
    try {
        Thread.sleep(delay);
    } catch (final InterruptedException ex) {
        // Ignore
    }

    // Stop
    dispatcher.stopAndWait();
}

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

/**
 * @param args/*www.  j a va2 s.c o  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);
    }
}

From source file:com.bekwam.resignator.commands.UnsignCommand.java

public static void main(String[] args) throws Exception {
    UnsignCommand cmd = new UnsignCommand();
    cmd.unsignJAR(//from   w  w  w  . j  a v  a  2 s. co  m
            Paths.get("C:\\Users\\carl_000\\git\\resignator-repos-1\\resignator\\mavenpomupdater-1.3.1.jar"),
            Paths.get("C:\\Users\\carl_000\\.resignator\\myoutputjar.jar"), s -> System.out.println(s));
}

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

/**
 * @param args/* w ww  .ja  v a2s .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.alnc.ALNCIngesterRunner.java

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

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

        for (String pstr : run.delegate.paths) {
            LOGGER.debug("Running on file: {}", pstr);
            Path p = Paths.get(pstr);
            new ExistingNonDirectoryFile(p);
            Path outWithExt = outpath.resolve(p.getFileName() + ".tar.gz");

            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 (ALNCIngester ing = new ALNCIngester(p);
                    OutputStream os = Files.newOutputStream(outWithExt);
                    GzipCompressorOutputStream gout = new GzipCompressorOutputStream(os);
                    TarArchiver arch = new TarArchiver(gout)) {
                Iterator<Communication> iter = ing.iterator();
                while (iter.hasNext()) {
                    Communication c = iter.next();
                    LOGGER.debug("Got comm: {}", c.getId());
                    arch.addEntry(new ArchivableCommunication(c));
                }
            } catch (IngestException e) {
                LOGGER.error("Caught exception processing path: " + pstr, e);
            }
        }
    } catch (NotFileException | IOException e) {
        LOGGER.error("Caught exception processing.", e);
    }
}

From source file:MetadataExample.java

public static void main(String[] args) throws ImageReadException, IOException {
    metadataExample(Paths
            .get("/e/Sridhar/Photos/camera phone photos/iPhone/2015-04-28/Madrid/2015-04-28 499.jpg").toFile());
}

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 w w  w.  ja v  a 2s. co 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:br.com.RatosDePC.Brpp.BrppCompilerMain.java

public static void main(String[] args) {
    // TODO Auto-generated method stub
    File f = new File(FileUtils.getBrinodirectory());
    f.mkdirs();// w ww . j a v  a2 s  .  c  o m
    File l = new File(FileUtils.getBrinodirectory() + "/bibliotecas");
    l.mkdirs();
    Path currentRelativePath = Paths.get("");
    String s = currentRelativePath.toAbsolutePath().toString();
    File destDir = new File(s + System.getProperty("file.separator") + "Arduino"
            + System.getProperty("file.separator") + "libraries");
    try {
        JSONUtils.config(s);
    } catch (IOException | ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        FileUtils.copyFolder(l, destDir);
        KeywordManagerUtils.processLibraries();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
    BrppIDEFrame frame = new BrppIDEFrame("Brino " + BrppCompiler.version);
    frame.setSize(500, 600);
    frame.setVisible(true);
    frame.setLocation(100, 30);

}

From source file:Pong.java

public static void main(String... args) throws Exception {
    System.setProperty("os.max.pid.bits", "16");

    Options options = new Options();
    options.addOption("i", true, "Input chronicle path");
    options.addOption("n", true, "Number of entries to write");
    options.addOption("w", true, "Number of writer threads");
    options.addOption("r", true, "Number of reader threads");
    options.addOption("x", false, "Delete the output chronicle at startup");

    CommandLine cmd = new DefaultParser().parse(options, args);
    final Path output = Paths.get(cmd.getOptionValue("o", "/tmp/__test/chr"));
    final long maxCount = Long.parseLong(cmd.getOptionValue("n", "10000000"));
    final int writerThreadCount = Integer.parseInt(cmd.getOptionValue("w", "4"));
    final int readerThreadCount = Integer.parseInt(cmd.getOptionValue("r", "4"));
    final boolean deleteOnStartup = cmd.hasOption("x");

    if (deleteOnStartup) {
        FileUtil.removeRecursive(output);
    }// w  w w .java  2s  .  c o  m

    final Chronicle chr = ChronicleQueueBuilder.vanilla(output.toFile()).build();

    final ExecutorService executor = Executors.newFixedThreadPool(4);
    final List<Future<?>> futures = new ArrayList<>();

    final long totalCount = writerThreadCount * maxCount;
    final long t0 = System.nanoTime();

    for (int i = 0; i != readerThreadCount; ++i) {
        final int tid = i;
        futures.add(executor.submit((Runnable) () -> {
            try {
                IntLongMap counts = HashIntLongMaps.newMutableMap();
                ExcerptTailer tailer = chr.createTailer();

                final StringBuilder sb1 = new StringBuilder();
                final StringBuilder sb2 = new StringBuilder();

                long count = 0;
                while (count != totalCount) {
                    if (!tailer.nextIndex())
                        continue;
                    final int id = tailer.readInt();
                    final long val = tailer.readStopBit();
                    final long longValue = tailer.readLong();
                    sb1.setLength(0);
                    sb2.setLength(0);
                    tailer.read8bitText(sb1);
                    tailer.read8bitText(sb2);
                    if (counts.addValue(id, 1) - 1 != val || longValue != 0x0badcafedeadbeefL
                            || !StringInterner.isEqual("FooBar", sb1)
                            || !StringInterner.isEqual("AnotherFooBar", sb2)) {
                        System.out.println("Unexpected value " + id + ", " + val + ", "
                                + Long.toHexString(longValue) + ", " + sb1.toString() + ", " + sb2.toString());
                        return;
                    }
                    ++count;
                    if (count % 1_000_000 == 0) {
                        long t1 = System.nanoTime();
                        System.out.println(tid + " " + (t1 - t0) / 1e6 + " ms");
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }));
    }
    for (Future f : futures) {
        f.get();
    }
    executor.shutdownNow();

    final long t1 = System.nanoTime();
    System.out.println("Done. Rough time=" + (t1 - t0) / 1e6 + " ms");
}

From source file:net.dv8tion.jda.player.Bot.java

public static void main(String[] args) {
    try {//  w ww  . j  a  v a  2  s  . co m
        JSONObject obj = new JSONObject(new String(Files.readAllBytes(Paths.get("Config.json"))));
        JDA api = new JDABuilder().setBotToken(obj.getString("botToken")).addListener(new Bot())
                .buildBlocking();

    } catch (IllegalArgumentException e) {
        System.out.println("The config was not populated. Please provide a token.");
    } catch (LoginException e) {
        System.out.println("The provided botToken was incorrect. Please provide valid details.");
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        System.err.println(
                "Encountered a JSON error. Most likely caused due to an outdated or ill-formated config.\n"
                        + "Please delete the config so that it can be regenerated. JSON Error:\n");
        e.printStackTrace();
    } catch (IOException e) {
        JSONObject obj = new JSONObject();
        obj.put("botToken", "");
        try {
            Files.write(Paths.get("Config.json"), obj.toString(4).getBytes());
            System.out.println("No config file was found. Config.json has been generated, please populate it!");
        } catch (IOException e1) {
            System.out.println("No config file was found and we failed to generate one.");
            e1.printStackTrace();
        }
    }
}