Example usage for java.io File exists

List of usage examples for java.io File exists

Introduction

In this page you can find the example usage for java.io File exists.

Prototype

public boolean exists() 

Source Link

Document

Tests whether the file or directory denoted by this abstract pathname exists.

Usage

From source file:org.solrsystem.Main.java

public static void main(String[] args) throws IOException, HttpException {

    if (GraphicsEnvironment.isHeadless()) {
        UI = new TextInstall();
    } else {/*from  w  ww.  j av  a2s  .  c o  m*/
        UI = new GraphicalInstall();
    }

    if (UI.confirm("Do you want to create ./SolrSystem in this directory and install SolrSystem?")) {
        File solrSystemDir = new File("SolrSystem");
        //noinspection ResultOfMethodCallIgnored
        solrSystemDir.mkdir();
        UI.downLoad(GRADLE);

        File file = new File(solrSystemDir, "gradle-1.11-bin.zip");
        if (!file.exists()) {
            doGetToFile(GRADLE, file.getCanonicalPath(), UI);
        }
    }

}

From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step2FillWithRetrievedResults.java

public static void main(String[] args) throws IOException {
    // input dir - list of xml query containers
    File inputDir = new File(args[0]);

    // retrieved results from Technion
    // ltr-50queries-100docs.txt
    File ltr = new File(args[1]);

    // output dir
    File outputDir = new File(args[2]);
    if (!outputDir.exists()) {
        outputDir.mkdirs();/*from   ww  w. j  a v  a  2 s  .c  om*/
    }

    // load the query containers first (into map: id + container)
    Map<String, QueryResultContainer> queryResults = new HashMap<>();
    for (File f : FileUtils.listFiles(inputDir, new String[] { "xml" }, false)) {
        System.out.println(f);
        QueryResultContainer queryResultContainer = QueryResultContainer
                .fromXML(FileUtils.readFileToString(f, "utf-8"));
        queryResults.put(queryResultContainer.qID, queryResultContainer);
    }

    // iterate over IR results
    for (String line : FileUtils.readLines(ltr)) {
        String[] split = line.split("\\s+");
        Integer origQueryId = Integer.valueOf(split[0]);
        String clueWebID = split[2];
        Integer rank = Integer.valueOf(split[3]);
        double score = Double.valueOf(split[4]);
        String additionalInfo = split[5];

        // get the container for this result
        QueryResultContainer container = queryResults.get(origQueryId.toString());

        if (container != null) {
            // add new result
            QueryResultContainer.SingleRankedResult result = new QueryResultContainer.SingleRankedResult();
            result.clueWebID = clueWebID;
            result.rank = rank;
            result.score = score;
            result.additionalInfo = additionalInfo;

            if (container.rankedResults == null) {
                container.rankedResults = new ArrayList<>();
            }
            container.rankedResults.add(result);
        }
    }

    // save all containers to the output dir
    for (QueryResultContainer queryResultContainer : queryResults.values()) {
        File outputFile = new File(outputDir, queryResultContainer.qID + ".xml");
        FileUtils.writeStringToFile(outputFile, queryResultContainer.toXML(), "utf-8");
        System.out.println("Finished " + outputFile);
    }
}

From source file:ie.pars.bnc.preprocess.MainBNCProcess.java

/**
 * Main method use for processing BNC text. Claws PoSs are replaced by
 * Stanford CoreNLP results for consistency with the rest of data! Currently
 * the structure of BNC is mainly discarded, only paragraphs and sentences
 *
 * @param sugare//from   w w w. j  av a  2s.  c  om
 * @throws IOException
 * @throws ArchiveException
 * @throws Exception
 */
public static void main(String[] sugare) throws IOException, ArchiveException, Exception {
    pathInput = sugare[0];
    pathOutput = sugare[1];
    letter = sugare[2];
    filesProcesed = new TreeSet();

    File folder = new File(pathOutput);
    if (folder.exists()) {
        for (File f : folder.listFiles()) {
            if (f.isFile()) {
                String pfile = f.getName().split("\\.")[0];
                filesProcesed.add(pfile);
            }
        }
    } else {
        folder.mkdirs();
    }
    getZippedFile();
}

From source file:cc.twittertools.index.ExtractTweetidsFromIndex.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(//from  ww w. j a  v a  2 s  .c o m
            OptionBuilder.withArgName("dir").hasArg().withDescription("index location").create(INDEX_OPTION));

    CommandLine cmdline = null;
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        System.exit(-1);
    }

    if (!cmdline.hasOption(INDEX_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(ExtractTweetidsFromIndex.class.getName(), options);
        System.exit(-1);
    }

    File indexLocation = new File(cmdline.getOptionValue(INDEX_OPTION));
    if (!indexLocation.exists()) {
        System.err.println("Error: " + indexLocation + " does not exist!");
        System.exit(-1);
    }

    IndexReader reader = DirectoryReader.open(FSDirectory.open(indexLocation));
    PrintStream out = new PrintStream(System.out, true, "UTF-8");
    for (int i = 0; i < reader.maxDoc(); i++) {
        Document doc = reader.document(i);
        out.println(doc.getField(StatusField.ID.name).stringValue() + "\t"
                + doc.getField(StatusField.SCREEN_NAME.name).stringValue());
    }
    out.close();
    reader.close();
}

From source file:org.alfresco.util.xml.SchemaHelper.java

public static void main(String... args) {
    if (args.length < 2 || !args[0].startsWith("--compile-xsd=") && !args[1].startsWith("--output-dir=")) {
        System.out.println("Usage: SchemaHelper --compile-xsd=<URL> --output-dir=<directory>");
        System.exit(1);// w w w  .ja v a2s  . c o  m
    }
    final String urlStr = args[0].substring(14);
    if (urlStr.length() == 0) {
        System.out.println("Usage: SchemaHelper --compile-xsd=<URL> --output-dir=<directory>");
        System.exit(1);
    }
    final String dirStr = args[1].substring(13);
    if (dirStr.length() == 0) {
        System.out.println("Usage: SchemaHelper --compile-xsd=<URL> --output-dir=<directory>");
        System.exit(1);
    }
    try {
        URL url = ResourceUtils.getURL(urlStr);
        File dir = new File(dirStr);
        if (!dir.exists() || !dir.isDirectory()) {
            System.out.println("Output directory not found: " + dirStr);
            System.exit(1);
        }

        ErrorListener errorListener = new ErrorListener() {
            public void warning(SAXParseException e) {
                System.out.println("WARNING: " + e.getMessage());
            }

            public void info(SAXParseException e) {
                System.out.println("INFO: " + e.getMessage());
            }

            public void fatalError(SAXParseException e) {
                handleException(urlStr, e);
            }

            public void error(SAXParseException e) {
                handleException(urlStr, e);
            }
        };

        SchemaCompiler compiler = XJC.createSchemaCompiler();
        compiler.setErrorListener(errorListener);
        compiler.parseSchema(new InputSource(url.toExternalForm()));
        S2JJAXBModel model = compiler.bind();
        if (model == null) {
            System.out.println("Failed to produce binding model for URL " + urlStr);
            System.exit(1);
        }
        JCodeModel codeModel = model.generateCode(null, errorListener);
        codeModel.build(dir);
    } catch (Throwable e) {
        handleException(urlStr, e);
        System.exit(1);
    }
}

From source file:it.crs4.features.ImageToAvro.java

public static void main(String[] args) throws Exception {
    Options opts = new Options();
    CommandLine cmd = null;/*from   w w w  .j a  v a2s  .  c  om*/
    try {
        cmd = parseCmdLine(opts, args);
    } catch (ParseException e) {
        System.err.println("ERROR: " + e.getMessage());
        System.exit(1);
    }
    String fn = null;
    try {
        fn = cmd.getArgs()[0];
    } catch (ArrayIndexOutOfBoundsException e) {
        HelpFormatter fmt = new HelpFormatter();
        fmt.printHelp("java ImageToAvro IMG_FILE", opts);
        System.exit(2);
    }
    String outDirName = null;
    if (cmd.hasOption("outdir")) {
        outDirName = cmd.getOptionValue("outdir");
        File outDir = new File(outDirName);
        if (!outDir.exists()) {
            boolean ret = outDir.mkdirs();
            if (!ret) {
                System.err.format("ERROR: can't create %s\n", outDirName);
                System.exit(3);
            }
        }
    }

    String name = PathTools.stripext(PathTools.basename(fn));
    ImageReader reader = new ImageReader();
    reader.setId(fn);
    LOGGER.info("Reading from {}", fn);
    BioImgFactory factory = new BioImgFactory(reader);
    int seriesCount = factory.getSeriesCount();

    // FIXME: add support for XY slicing
    String seriesName;
    String outFn;
    for (int i = 0; i < seriesCount; i++) {
        seriesName = String.format("%s_%d", name, i);
        outFn = new File(outDirName, seriesName + ".avro").getPath();
        factory.setSeries(i);
        factory.writeSeries(seriesName, outFn);
        LOGGER.info("Writing to {}", outFn);
    }
    reader.close();
    LOGGER.info("All done");
}

From source file:Example6.java

public static void main(String[] args) throws IOException, InterruptedException {
    //check if the executable exists
    File file = new File("./examples/dtlz2_socket.exe");

    if (!file.exists()) {
        if (!SystemUtils.IS_OS_UNIX) {
            System.err.println(//from   ww w  .  j a v  a 2 s. co m
                    "This example only works on POSIX-compliant systems; see the Makefile for details");
            return;
        }

        System.err.println("Please compile the executable by running make in the ./examples/ folder");
        return;
    }

    //run the executable and wait one second for the process to startup
    new ProcessBuilder(file.toString()).start();
    Thread.sleep(1000);

    //configure and run the DTLZ2 function
    NondominatedPopulation result = new Executor().withProblemClass(MyDTLZ2.class).withAlgorithm("NSGAII")
            .withMaxEvaluations(10000).run();

    //display the results
    System.out.format("Objective1  Objective2%n");

    for (Solution solution : result) {
        System.out.format("%.4f      %.4f%n", solution.getObjective(0), solution.getObjective(1));
    }
}

From source file:com.thoughtworks.go.server.DevelopmentServer.java

public static void main(String[] args) throws Exception {
    LogConfigurator logConfigurator = new LogConfigurator(DEFAULT_LOGBACK_CONFIGURATION_FILE);
    logConfigurator.initialize();/* w ww . j av  a  2  s . c  o m*/
    copyDbFiles();
    copyPluginAssets();
    File webApp = new File("webapp");
    if (!webApp.exists()) {
        throw new RuntimeException("No webapp found in " + webApp.getAbsolutePath());
    }

    assertActivationJarPresent();
    SystemEnvironment systemEnvironment = new SystemEnvironment();
    systemEnvironment.setProperty(GENERATE_STATISTICS, "true");

    systemEnvironment.setProperty(SystemEnvironment.PARENT_LOADER_PRIORITY, "true");
    systemEnvironment.setProperty(SystemEnvironment.CRUISE_SERVER_WAR_PROPERTY, webApp.getAbsolutePath());
    systemEnvironment.set(SystemEnvironment.PLUGIN_LOCATION_MONITOR_INTERVAL_IN_SECONDS, 5);

    systemEnvironment.set(SystemEnvironment.DEFAULT_PLUGINS_ZIP, "/plugins.zip");
    systemEnvironment.set(SystemEnvironment.PLUGIN_ACTIVATOR_JAR_PATH, "go-plugin-activator.jar");
    systemEnvironment.set(SystemEnvironment.FAIL_STARTUP_ON_DATA_ERROR, true);
    systemEnvironment.setProperty(GoConstants.I18N_CACHE_LIFE, "0"); //0 means reload when stale
    systemEnvironment.set(SystemEnvironment.GO_SERVER_MODE, "development");
    setupPeriodicGC(systemEnvironment);
    assertPluginsZipExists();
    GoServer server = new GoServer();
    systemEnvironment.setProperty(GoConstants.USE_COMPRESSED_JAVASCRIPT, Boolean.toString(false));
    try {
        server.startServer();

        String hostName = systemEnvironment.getListenHost();
        if (hostName == null) {
            hostName = "localhost";
        }

        System.out.println("GoCD server dashboard started on http://" + hostName + ":"
                + systemEnvironment.getServerPort());
        System.out.println("* credentials: \"admin\" / \"badger\"");
    } catch (Exception e) {
        System.err.println("Failed to start GoCD server. Exception:");
        e.printStackTrace();
    }
}

From source file:com.daon.identityx.utils.GenerateAndroidFacet.java

public static void main(String[] args) {

    String androidKeystoreLocation = System.getProperty("ANDROID_KEYSTORE_LOCATION",
            DEFAULT_ANDROID_KEYSTORE_LOCATION);
    String androidKeystorePassword = System.getProperty("ANDROID_KEYSTORE_PASSWORD",
            DEFAULT_ANDROID_KEYSTORE_PASSWORD);
    String androidKeystoreCert = System.getProperty("ANDROID_KEYSTORE_CERT_NAME",
            DEFAULT_ANDROID_KEYSTORE_CERT_NAME);
    String hashingAlgorithm = System.getProperty("HASHING_ALGORITHM", DEFAULT_HASHING_ALGORITHM);

    try {/*from   w  w  w.j a v a 2  s  .c om*/
        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        File filePath = new File(androidKeystoreLocation);
        if (!filePath.exists()) {
            System.err.println(
                    "The filepath to the debug keystore could not be located at: " + androidKeystoreCert);
            System.exit(1);
        } else {
            System.out.println("Found the Android Studio keystore at: " + androidKeystoreLocation);
        }

        keyStore.load(new FileInputStream(filePath), androidKeystorePassword.toCharArray());
        System.out.println("Keystore loaded - password and location were OK");

        Certificate cert = keyStore.getCertificate(androidKeystoreCert);
        if (cert == null) {
            System.err.println(
                    "Could not location the certification in the store with the name: " + androidKeystoreCert);
            System.exit(1);
        } else {
            System.out.println("Certificate found in the store with name: " + androidKeystoreCert);
        }

        byte[] certBytes = cert.getEncoded();

        MessageDigest digest = MessageDigest.getInstance(hashingAlgorithm);
        System.out.println("Hashing algorithm: " + hashingAlgorithm + " found.");
        byte[] hashedCert = digest.digest(certBytes);
        String base64HashedCert = Base64.getEncoder().encodeToString(hashedCert);
        System.out.println("Base64 encoded SHA-1 hash of the certificate: " + base64HashedCert);
        String base64HashedCertRemoveTrailing = StringUtils.deleteAny(base64HashedCert, "=");
        System.out.println(
                "Add the following facet to the Facets file in order for the debug app to be trusted by the FIDO client");
        System.out.println("\"android:apk-key-hash:" + base64HashedCertRemoveTrailing + "\"");

    } catch (Throwable ex) {
        ex.printStackTrace();
    }

}

From source file:com.cyphercove.dayinspace.desktop.AtlasGenerator.java

public static void main(String[] args) throws Exception {

    //Delete old pack
    File oldPackFile = new File(TARGET_DIR + "/" + Assets.MAIN_ATLAS + Assets.ATLAS_EXTENSION);
    if (oldPackFile.exists()) {
        System.out.println("Deleting old pack file");
        oldPackFile.delete();/*from   w  ww . jav  a2 s.  co  m*/
    }

    //Delete old font files
    Collection<File> oldFontFiles = FileUtils.listFiles(new File(TARGET_DIR), new RegexFileFilter(".*\\.fnt"),
            TrueFileFilter.INSTANCE);
    for (File file : oldFontFiles) {
        System.out.println("Copying font file: " + file.getName());
        FileUtils.deleteQuietly(file);
    }

    //Create PNGs for GIF frames
    GifProcessor gifProcessor = new GifProcessor(0.015f);
    ArrayList<FileProcessor.Entry> gifFrames = gifProcessor.process(SOURCE_DIR, SOURCE_DIR);

    //Pack them
    TexturePacker.Settings settings = new TexturePacker.Settings();
    settings.atlasExtension = Assets.ATLAS_EXTENSION;
    TexturePacker.process(settings, SOURCE_DIR, TARGET_DIR, Assets.MAIN_ATLAS);

    //Copy over any fonts
    Collection<File> fontFiles = FileUtils.listFiles(new File(SOURCE_DIR), new RegexFileFilter(".*\\.fnt"),
            TrueFileFilter.INSTANCE);
    File destDir = new File(TARGET_DIR);
    for (File file : fontFiles) {
        System.out.println("Copying font file: " + file.getName());
        FileUtils.copyFileToDirectory(file, destDir);
    }

    //Delete the GIF frames that were generated.
    for (File file : gifProcessor.getGeneratedFiles())
        file.delete();
}