Example usage for java.io File toString

List of usage examples for java.io File toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns the pathname string of this abstract pathname.

Usage

From source file:io.reactiverse.vertx.maven.plugin.FileFilterMain.java

public static void main(String[] args) {

    Commandline commandline = new Commandline();
    commandline.setExecutable("java");
    commandline.createArg().setValue("io.vertx.core.Launcher");
    commandline.createArg().setValue("--redeploy=target/**/*");

    System.out.println(commandline);//from w  ww  . j  av a2s .c om

    File baseDir = new File("/Users/kameshs/git/reactiverse/vertx-maven-plugin/samples/vertx-demo");
    List<String> includes = new ArrayList<>();
    includes.add("src/**/*.java");
    //FileAlterationMonitor monitor  = null;
    try {

        Set<Path> inclDirs = new HashSet<>();

        includes.forEach(s -> {
            try {

                if (s.startsWith("**")) {
                    Path rootPath = Paths.get(baseDir.toString());
                    if (Files.exists(rootPath)) {
                        File[] dirs = rootPath.toFile().listFiles((dir, name) -> dir.isDirectory());
                        Objects.requireNonNull(dirs);
                        Stream.of(dirs).forEach(f -> inclDirs.add(Paths.get(f.toString())));
                    }
                } else if (s.contains("**")) {
                    String root = s.substring(0, s.indexOf("/**"));
                    Path rootPath = Paths.get(baseDir.toString(), root);
                    if (Files.exists(rootPath)) {
                        File[] dirs = rootPath.toFile().listFiles((dir, name) -> dir.isDirectory());
                        Objects.requireNonNull(dirs);
                        Stream.of(dirs).forEach(f -> inclDirs.add(Paths.get(f.toString())));
                    }
                }

                List<Path> dirs = FileUtils.getFileAndDirectoryNames(baseDir, s, null, true, true, true, true)
                        .stream().map(FileUtils::dirname).map(Paths::get)
                        .filter(p -> Files.exists(p) && Files.isDirectory(p)).collect(Collectors.toList());

                inclDirs.addAll(dirs);

            } catch (Exception e) {
                e.printStackTrace();
            }
        });

        FileAlterationMonitor monitor = fileWatcher(inclDirs);

        Runnable monitorTask = () -> {
            try {
                monitor.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        };

        monitorTask.run();

    } catch (Exception e) {
        e.printStackTrace();
    }

}

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(// w ww .j  a  v a 2  s .  c o  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:edu.utsa.sifter.som.MainSOM.java

public static void main(String[] args)
        throws IOException, InterruptedException, CorruptIndexException, NoSuchFieldException {
    final File evPath = new File(args[0]);
    final File idxPath = new File(evPath, "primary-idx");

    final long begin = System.currentTimeMillis();

    // createIndex(path);
    final Path outPath = new Path(new Path(evPath.toString()), "docVectors.seq");
    final Configuration hadoopConf = new Configuration();
    final LocalFileSystem fs = FileSystem.getLocal(hadoopConf);
    final SequenceFile.Writer file = SequenceFile.createWriter(fs, hadoopConf, outPath, LongWritable.class,
            IntArrayWritable.class);

    final DirectoryReader dirReader = DirectoryReader.open(FSDirectory.open(idxPath));

    final SifterConfig conf = new SifterConfig();
    InputStream xmlProps = null;/*from w  ww  .j  a  v  a2  s  . co  m*/
    try {
        xmlProps = new FileInputStream("sifter_props.xml");
    } catch (FileNotFoundException ex) {
        ; // swallow exeption
    }
    conf.loadFromXML(xmlProps); // safe with null

    final MainSOM builder = new MainSOM(dirReader, conf);
    IndexWriter writer = null;
    FileOutputStream somJSFile = null;
    try {
        builder.initTerms();
        builder.writeVectors(file);
        file.close();

        final SequenceFile.Reader seqRdr = new SequenceFile.Reader(fs, outPath, hadoopConf);
        writer = builder.createWriter(new File(evPath, "som-idx"), conf);

        somJSFile = new FileOutputStream(new File(evPath, "som.js"));
        final CharsetEncoder utf8 = Charset.forName("UTF-8").newEncoder();
        utf8.onMalformedInput(CodingErrorAction.IGNORE);
        final Writer somJS = new BufferedWriter(new OutputStreamWriter(somJSFile, utf8));
        builder.makeSOM(conf, seqRdr, writer, somJS);
        writer.forceMerge(1);
    } catch (Exception e) {
        e.printStackTrace(System.err);
    } finally {
        file.close();
        if (writer != null) {
            writer.close();
        }
        if (somJSFile != null) {
            somJSFile.close();
        }
        dirReader.close();

        System.out.println("Number of docs written: " + builder.getNumDocs());
        System.out.println("Number of outlier docs: " + builder.getNumOutliers());
        System.out.println("Total term dimensions: " + builder.getTermsMap().size());
        System.out.println("Max terms per doc: " + builder.getMaxDocTerms());
        System.out.println("Avg terms per doc: " + builder.getAvgDocTerms());
        System.out.println("Duration: " + ((System.currentTimeMillis() - begin) / 1000) + " seconds");

        conf.storeToXML(new FileOutputStream("sifter_props.xml"));
    }
}

From source file:fedora.server.utilities.rebuild.Rebuild.java

public static void main(String[] args) {
    // tell commons-logging to use log4j
    System.setProperty("org.apache.commons.logging.LogFactory", "org.apache.commons.logging.impl.Log4jFactory");
    System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger");
    // log4j//from   w  ww.j  a v a2s. c  o m
    // File log4jConfig = new File(new File(homeDir), "config/log4j.xml");
    // DOMConfigurator.configure(log4jConfig.getPath());
    String profile = null;
    if (args.length > 0) {
        profile = args[0];
    }
    if (args.length > 1) {
        fail("Too many arguments", true, true);
    }
    try {
        File serverDir = new File(new File(Constants.FEDORA_HOME), "server");
        ServerConfiguration serverConfig = getServerConfig(serverDir, profile);
        System.err.println();
        System.err.println("                       Fedora Rebuild Utility");
        System.err.println("                     ..........................");
        System.err.println();
        System.err.println("WARNING: Live rebuilds are not currently supported.");
        System.err.println("         Make sure your server is stopped before continuing.");
        System.err.println();
        System.err.println("Server directory is " + serverDir.toString());
        if (profile != null) {
            System.err.print("Server profile is " + profile);
        }
        System.err.println();
        System.err.println("---------------------------------------------------------------------");
        System.err.println();
        Rebuilder rebuilder = getRebuilder();
        Map<String, String> options = getUserInput(rebuilder, serverDir, serverConfig);
        new Rebuild(rebuilder, options, serverConfig);
    } catch (Throwable th) {
        String msg = th.getMessage();
        if (msg == null) {
            msg = th.getClass().getName();
        }
        fail(msg, false, false);
        th.printStackTrace();
    }
}

From source file:gov.nasa.jpl.memex.pooledtimeseries.PoT.java

public static void main(String[] args) {
      System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
      Option fileOpt = OptionBuilder.withArgName("file").hasArg().withLongOpt("file")
              .withDescription("Path to a single file").create('f');

      Option dirOpt = OptionBuilder.withArgName("directory").hasArg().withLongOpt("dir")
              .withDescription("A directory with image files in it").create('d');

      Option helpOpt = OptionBuilder.withLongOpt("help").withDescription("Print this message.").create('h');

      Option pathFileOpt = OptionBuilder.withArgName("path file").hasArg().withLongOpt("pathfile")
              .withDescription(//from w  w w. j  ava  2s. c o  m
                      "A file containing full absolute paths to videos. Previous default was memex-index_temp.txt")
              .create('p');

      Option outputFileOpt = OptionBuilder.withArgName("output file").withLongOpt("outputfile").hasArg()
              .withDescription("File containing similarity results. Defaults to ./similarity.txt").create('o');

      Option jsonOutputFlag = OptionBuilder.withArgName("json output").withLongOpt("json")
              .withDescription("Set similarity output format to JSON. Defaults to .txt").create('j');

      Option similarityFromFeatureVectorsOpt = OptionBuilder
              .withArgName("similarity from FeatureVectors directory")
              .withLongOpt("similarityFromFeatureVectorsDirectory").hasArg()
              .withDescription("calculate similarity matrix from given directory of feature vectors").create('s');

      Options options = new Options();
      options.addOption(dirOpt);
      options.addOption(pathFileOpt);
      options.addOption(fileOpt);
      options.addOption(helpOpt);
      options.addOption(outputFileOpt);
      options.addOption(jsonOutputFlag);
      options.addOption(similarityFromFeatureVectorsOpt);

      // create the parser
      CommandLineParser parser = new GnuParser();

      try {
          // parse the command line arguments
          CommandLine line = parser.parse(options, args);
          String directoryPath = null;
          String pathFile = null;
          String singleFilePath = null;
          String similarityFromFeatureVectorsDirectory = null;
          ArrayList<Path> videoFiles = null;

          if (line.hasOption("dir")) {
              directoryPath = line.getOptionValue("dir");
          }

          if (line.hasOption("pathfile")) {
              pathFile = line.getOptionValue("pathfile");
          }

          if (line.hasOption("file")) {
              singleFilePath = line.getOptionValue("file");
          }

          if (line.hasOption("outputfile")) {
              outputFile = line.getOptionValue("outputfile");
          }

          if (line.hasOption("json")) {
              outputFormat = OUTPUT_FORMATS.JSON;
          }

          if (line.hasOption("similarityFromFeatureVectorsDirectory")) {
              similarityFromFeatureVectorsDirectory = line
                      .getOptionValue("similarityFromFeatureVectorsDirectory");
          }

          if (line.hasOption("help")
                  || (line.getOptions() == null || (line.getOptions() != null && line.getOptions().length == 0))
                  || (directoryPath != null && pathFile != null && !directoryPath.equals("")
                          && !pathFile.equals(""))) {
              HelpFormatter formatter = new HelpFormatter();
              formatter.printHelp("pooled_time_series", options);
              System.exit(1);
          }

          if (directoryPath != null) {
              File dir = new File(directoryPath);
              List<File> files = (List<File>) FileUtils.listFiles(dir, TrueFileFilter.INSTANCE,
                      TrueFileFilter.INSTANCE);
              videoFiles = new ArrayList<Path>(files.size());

              for (File file : files) {
                  String filePath = file.toString();

                  // When given a directory to load videos from we need to ensure that we
                  // don't try to load the of.txt and hog.txt intermediate result files
                  // that results from previous processing runs.
                  if (!filePath.contains(".txt")) {
                      videoFiles.add(file.toPath());
                  }
              }

              LOG.info("Added " + videoFiles.size() + " video files from " + directoryPath);

          }

          if (pathFile != null) {
              Path list_file = Paths.get(pathFile);
              videoFiles = loadFiles(list_file);
              LOG.info("Loaded " + videoFiles.size() + " video files from " + pathFile);
          }

          if (singleFilePath != null) {
              Path singleFile = Paths.get(singleFilePath);
              LOG.info("Loaded file: " + singleFile);
              videoFiles = new ArrayList<Path>(1);
              videoFiles.add(singleFile);
          }

          if (similarityFromFeatureVectorsDirectory != null) {
              File dir = new File(similarityFromFeatureVectorsDirectory);
              List<File> files = (List<File>) FileUtils.listFiles(dir, TrueFileFilter.INSTANCE,
                      TrueFileFilter.INSTANCE);
              videoFiles = new ArrayList<Path>(files.size());

              for (File file : files) {
                  String filePath = file.toString();

                  // We need to load only the *.of.txt and *.hog.txt values
                  if (filePath.endsWith(".of.txt")) {
                      videoFiles.add(file.toPath());
                  }

                  if (filePath.endsWith(".hog.txt")) {
                      videoFiles.add(file.toPath());
                  }
              }

              LOG.info("Added " + videoFiles.size() + " feature vectors from "
                      + similarityFromFeatureVectorsDirectory);
              evaluateSimilarity(videoFiles, 1);
          } else {
              evaluateSimilarity(videoFiles, 1);
          }
          LOG.info("done.");

      } catch (ParseException exp) {
          // oops, something went wrong
          System.err.println("Parsing failed.  Reason: " + exp.getMessage());
      }

  }

From source file:com.blackducksoftware.tools.vuln_collector.VCRunner.java

public static void main(String[] args) throws Exception {
    System.out.println(TITLE);//from   w  ww. j a  v a2  s  . c o m
    CommandLineParser parser = new DefaultParser();

    options.addOption("h", "help", false, "show help.");

    Option projectNameOption = new Option("projectName", true, "Name of Project (optional)");
    projectNameOption.setRequired(false);
    options.addOption(projectNameOption);

    Option configFileOption = new Option("config", true, "Location of configuration file (required)");
    configFileOption.setRequired(true);
    options.addOption(configFileOption);

    try {

        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("h"))
            help();

        String[] projectNameList = null;
        File configFile = null;

        if (cmd.hasOption(VCConstants.CL_PROJECT_NAME)) {
            String projectName = cmd.getOptionValue(VCConstants.CL_PROJECT_NAME);
            log.info("Project name: " + projectName);
            // Could be a single project or comma delim
            projectNameList = VCProcessor.getProjectList(projectName);
        }

        // Config File
        if (cmd.hasOption(VCConstants.CL_CONFIG)) {
            String configFilePath = cmd.getOptionValue(VCConstants.CL_CONFIG);
            log.info("Config file location: " + configFilePath);
            configFile = new File(configFilePath);
            if (!configFile.exists()) {
                log.error("Configuration file does not exist at location: " + configFile);
                System.exit(-1);
            }
        } else {
            log.error("Must specify configuration file!");
            help();
        }

        VCProcessor processor = new VCProcessor(configFile.toString(), projectNameList);
        processor.processReport();

    } catch (ParseException e) {
        log.error("Error parsing: " + e.getMessage());
        help();
    } catch (Exception e) {
        log.error("General error: " + e.getMessage());

    }

}

From source file:com.zimbra.kabuki.tools.img.ImageMerger.java

public static void main(String[] argv) throws Exception {
    // parse command-line
    CommandLineParser parser = new GnuParser();
    CommandLine cl = null;/*from www.j a  va2 s  . c o m*/
    try {
        cl = parser.parse(OPTIONS, argv);
    } catch (ParseException pe) {
        System.err.println(pe);
        printUsageAndExit();
    }
    if (cl == null) {
        printUsageAndExit();
    }

    // handle options
    ImageMerger merger = new ImageMerger();
    List<File> inputDirs = new LinkedList<File>();
    if (cl.hasOption(O_INPUT)) {
        for (String dirname : cl.getOptionValue(O_INPUT).split("[;,]")) {
            File dir = new File(dirname);
            assertAndExit(dir.exists(), "directory %s doesn't exist", dir.toString());
            assertAndExit(dir.isDirectory(), "%s is not a directory", dir.toString());
            inputDirs.add(dir);
        }
    }
    if (cl.hasOption(O_OUTPUT)) {
        File dir = new File(cl.getOptionValue(O_OUTPUT));
        assertAndExit(dir.exists(), "directory %s doesn't exist", dir.toString());
        assertAndExit(dir.isDirectory(), "%s is not a directory", dir.toString());
        merger.setOutputDirectory(dir);
    }
    if (cl.hasOption(O_CSS_PATH) && cl.hasOption(O_CSS_FILENAME)) {
        merger.setCssPath(cl.getOptionValue(O_CSS_PATH));
        merger.setCssFilename(cl.getOptionValue(O_CSS_FILENAME));
        String cacheFilename = cl.getOptionValue(O_CACHE_FILENAME);
        if (cacheFilename != null) {
            merger.setCacheFilename(cacheFilename);
        }
    }
    if (cl.hasOption(O_JS_FILENAME)) {
        merger.setJsFilename(cl.getOptionValue(O_JS_FILENAME));
    }
    if (cl.hasOption(O_COPY)) {
        merger.setCopyFiles(true);
    }
    if (cl.hasOption(O_NO_APPEND)) {
        merger.setAppendOutput(false);
    }
    if (cl.hasOption(O_VERBOSE)) {
        merger.setVerbose(true);
    }
    if (cl.hasOption(O_DISABLED_IMAGES)) {
        printWarning("option -%s is deprecated", O_DISABLED_IMAGES);
    }
    if (cl.hasOption(O_SPACER_IMAGES)) {
        merger.setSpacerImagesPath(cl.getOptionValue(O_SPACER_IMAGES));
    }
    // process
    assertAndExit(inputDirs.size() > 0, "must specify input directories");
    merger.process(inputDirs);
}

From source file:com.sforce.dataset.DatasetUtilMain.java

public static void main(String[] args) {

    printBanner();//from w  ww.  j  a va2 s . co  m

    DatasetUtilParams params = new DatasetUtilParams();

    if (args.length > 0)
        params.server = false;

    System.out.println("");
    System.out.println("DatsetUtils called with {" + args.length + "} Params:");

    for (int i = 0; i < args.length; i++) {
        if ((i & 1) == 0) {
            System.out.print("{" + args[i] + "}");
        } else {
            if (i > 0 && args[i - 1].equalsIgnoreCase("--p"))
                System.out.println(":{*******}");
            else
                System.out.println(":{" + args[i] + "}");
        }

        if (i > 0 && args[i - 1].equalsIgnoreCase("--server")) {
            if (args[i] != null && args[i].trim().equalsIgnoreCase("false"))
                params.server = false;
            else if (args[i] != null && args[i].trim().equalsIgnoreCase("true"))
                params.server = true;
        }
    }
    System.out.println("");

    if (!printlneula(params.server)) {
        System.out.println(
                "You do not have permission to use this software. Please delete it from this computer");
        System.exit(-1);
    }

    String action = null;

    if (args.length >= 2) {
        for (int i = 1; i < args.length; i = i + 2) {
            if (args[i - 1].equalsIgnoreCase("--help") || args[i - 1].equalsIgnoreCase("-help")
                    || args[i - 1].equalsIgnoreCase("help")) {
                printUsage();
            } else if (args[i - 1].equalsIgnoreCase("--u")) {
                params.username = args[i];
            } else if (args[i - 1].equalsIgnoreCase("--p")) {
                params.password = args[i];
            } else if (args[i - 1].equalsIgnoreCase("--sessionId")) {
                params.sessionId = args[i];
            } else if (args[i - 1].equalsIgnoreCase("--token")) {
                params.token = args[i];
            } else if (args[i - 1].equalsIgnoreCase("--endpoint")) {
                params.endpoint = args[i];
            } else if (args[i - 1].equalsIgnoreCase("--action")) {
                action = args[i];
            } else if (args[i - 1].equalsIgnoreCase("--operation")) {
                if (args[i] != null) {
                    if (args[i].equalsIgnoreCase("overwrite")) {
                        params.Operation = args[i];
                    } else if (args[i].equalsIgnoreCase("upsert")) {
                        params.Operation = args[i];
                    } else if (args[i].equalsIgnoreCase("append")) {
                        params.Operation = args[i];
                    } else if (args[i].equalsIgnoreCase("delete")) {
                        params.Operation = args[i];
                    } else {
                        System.out.println("Invalid Operation {" + args[i]
                                + "} Must be Overwrite or Upsert or Append or Delete");
                        System.exit(-1);
                    }
                }
            } else if (args[i - 1].equalsIgnoreCase("--debug")) {
                params.debug = true;
                DatasetUtilConstants.debug = true;
            } else if (args[i - 1].equalsIgnoreCase("--ext")) {
                DatasetUtilConstants.ext = true;
            } else if (args[i - 1].equalsIgnoreCase("--inputFile")) {
                String tmp = args[i];
                if (tmp != null) {
                    File tempFile = new File(tmp);
                    if (tempFile.exists()) {
                        params.inputFile = tempFile.toString();
                    } else {
                        System.out.println("File {" + args[i] + "} does not exist");
                        System.exit(-1);
                    }
                }
            } else if (args[i - 1].equalsIgnoreCase("--dataset")) {
                params.dataset = args[i];
            } else if (args[i - 1].equalsIgnoreCase("--datasetLabel")) {
                params.datasetLabel = args[i];
            } else if (args[i - 1].equalsIgnoreCase("--app")) {
                params.app = args[i];
            } else if (args[i - 1].equalsIgnoreCase("--useBulkAPI")) {
                if (args[i] != null && args[i].trim().equalsIgnoreCase("true"))
                    params.useBulkAPI = true;
            } else if (args[i - 1].equalsIgnoreCase("--uploadFormat")) {
                if (args[i] != null && args[i].trim().equalsIgnoreCase("csv"))
                    params.uploadFormat = "csv";
                else if (args[i] != null && args[i].trim().equalsIgnoreCase("binary"))
                    params.uploadFormat = "binary";
            } else if (args[i - 1].equalsIgnoreCase("--rowLimit")) {
                if (args[i] != null && !args[i].trim().isEmpty())
                    params.rowLimit = (new BigDecimal(args[i].trim())).intValue();
            } else if (args[i - 1].equalsIgnoreCase("--rootObject")) {
                params.rootObject = args[i];
            } else if (args[i - 1].equalsIgnoreCase("--fileEncoding")) {
                params.fileEncoding = args[i];
            } else if (args[i - 1].equalsIgnoreCase("--server")) {
                if (args[i] != null && args[i].trim().equalsIgnoreCase("true"))
                    params.server = true;
                else if (args[i] != null && args[i].trim().equalsIgnoreCase("false"))
                    params.server = false;
            } else if (args[i - 1].equalsIgnoreCase("--codingErrorAction")) {
                if (args[i] != null) {
                    if (args[i].equalsIgnoreCase("IGNORE")) {
                        params.codingErrorAction = CodingErrorAction.IGNORE;
                    } else if (args[i].equalsIgnoreCase("REPORT")) {
                        params.codingErrorAction = CodingErrorAction.REPORT;
                    } else if (args[i].equalsIgnoreCase("REPLACE")) {
                        params.codingErrorAction = CodingErrorAction.REPLACE;
                    }
                }
            } else {
                printUsage();
                System.out.println("\nERROR: Invalid argument: " + args[i - 1]);
                System.exit(-1);
            }
        } //end for

        if (params.username != null) {
            if (params.endpoint == null || params.endpoint.isEmpty()) {
                params.endpoint = DatasetUtilConstants.defaultEndpoint;
            }
        }
    }

    if (params.server) {
        System.out.println();
        System.out.println("\n*******************************************************************************");
        try {
            DatasetUtilServer datasetUtilServer = new DatasetUtilServer();
            datasetUtilServer.init(args, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("Server ended, exiting JVM.....");
        System.out.println("*******************************************************************************\n");
        System.out.println("QUITAPP");
        System.exit(0);
    }

    if (params.sessionId == null) {
        if (params.username == null || params.username.trim().isEmpty()) {
            params.username = getInputFromUser("Enter salesforce username: ", true, false);
        }

        if (params.username.equals("-1")) {
            params.sessionId = getInputFromUser("Enter salesforce sessionId: ", true, false);
            params.username = null;
            params.password = null;
        } else {
            if (params.password == null || params.password.trim().isEmpty()) {
                params.password = getInputFromUser("Enter salesforce password: ", true, true);
            }
        }
    }

    if (params.sessionId != null && !params.sessionId.isEmpty()) {
        while (params.endpoint == null || params.endpoint.trim().isEmpty()) {
            params.endpoint = getInputFromUser("Enter salesforce instance url: ", true, false);
            if (params.endpoint == null || params.endpoint.trim().isEmpty())
                System.out.println("\nERROR: endpoint must be specified when sessionId is specified");
        }

        while (params.endpoint.toLowerCase().contains("login.salesforce.com")
                || params.endpoint.toLowerCase().contains("test.salesforce.com")
                || params.endpoint.toLowerCase().contains("test")
                || params.endpoint.toLowerCase().contains("prod")
                || params.endpoint.toLowerCase().contains("sandbox")) {
            System.out.println("\nERROR: endpoint must be the actual serviceURL and not the login url");
            params.endpoint = getInputFromUser("Enter salesforce instance url: ", true, false);
        }
    } else {
        if (params.endpoint == null || params.endpoint.isEmpty()) {
            params.endpoint = getInputFromUser("Enter salesforce instance url (default=prod): ", false, false);
            if (params.endpoint == null || params.endpoint.trim().isEmpty()) {
                params.endpoint = DatasetUtilConstants.defaultEndpoint;
            }
        }
    }

    try {
        if (params.endpoint.equalsIgnoreCase("PROD") || params.endpoint.equalsIgnoreCase("PRODUCTION")) {
            params.endpoint = DatasetUtilConstants.defaultEndpoint;
        } else if (params.endpoint.equalsIgnoreCase("TEST") || params.endpoint.equalsIgnoreCase("SANDBOX")) {
            params.endpoint = DatasetUtilConstants.defaultEndpoint.replace("login", "test");
        }

        URL uri = new URL(params.endpoint);
        String protocol = uri.getProtocol();
        String host = uri.getHost();
        if (protocol == null || !protocol.equalsIgnoreCase("https")) {
            if (host == null || !(host.toLowerCase().endsWith("internal.salesforce.com")
                    || host.toLowerCase().endsWith("localhost"))) {
                System.out.println("\nERROR: Invalid endpoint. UNSUPPORTED_CLIENT: HTTPS Required in endpoint");
                System.exit(-1);
            }
        }

        if (uri.getPath() == null || uri.getPath().isEmpty() || uri.getPath().equals("/")) {
            uri = new URL(uri.getProtocol(), uri.getHost(), uri.getPort(),
                    DatasetUtilConstants.defaultSoapEndPointPath);
        }
        params.endpoint = uri.toString();
    } catch (MalformedURLException e) {
        e.printStackTrace();
        System.out.println("\nERROR: endpoint is not a valid URL");
        System.exit(-1);
    }

    PartnerConnection partnerConnection = null;
    if (params.username != null || params.sessionId != null) {
        try {
            partnerConnection = DatasetUtils.login(0, params.username, params.password, params.token,
                    params.endpoint, params.sessionId, params.debug);
        } catch (ConnectionException e) {
            e.printStackTrace();
            System.exit(-1);
        } catch (MalformedURLException e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    if (args.length == 0 || action == null) {
        //         System.out.println("\n*******************************************************************************");               
        ////         FileListenerUtil.startAllListener(partnerConnection);
        //         try {
        //            Thread.sleep(1000);
        //         } catch (InterruptedException e) {
        //         }
        //         System.out.println("*******************************************************************************\n");   
        //         System.out.println();         

        //         System.out.println("\n*******************************************************************************");               
        //           try {
        //              DatasetUtilServer datasetUtilServer = new DatasetUtilServer();
        //            datasetUtilServer.init(args, false);
        //         } catch (Exception e) {
        //            e.printStackTrace();
        //         }
        //         System.out.println("*******************************************************************************\n");   
        //         System.out.println();         

        while (true) {
            action = getActionFromUser();
            if (action == null || action.isEmpty()) {
                System.exit(-1);
            }
            params = new DatasetUtilParams();
            getRequiredParams(action, partnerConnection, params);
            @SuppressWarnings("unused")
            boolean status = doAction(action, partnerConnection, params);
            //            if(status)
            //            {
            //               if(action.equalsIgnoreCase("load") && params.debug)
            //                  createListener(partnerConnection, params);
            //            }
        }
    } else {
        doAction(action, partnerConnection, params);
    }

}

From source file:com.spinn3r.api.Main.java

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

    // NOTE this could be cleaned up to pass the values into the config
    // object directly.

    // parse out propeties.

    String api = null;//from w  ww  .j a  v a2s .c o m

    for (int i = 0; i < args.length; ++i) {
        String v = args[i];

        if (v.startsWith("--api")) {
            api = getOpt(v);
        }

    }

    if (api == null)
        api = "permalink";

    // First. Determine which API you'd like to use.

    long after = -1;
    Format format = Format.PROTOSTREAM;
    String vendor = null;
    String remoteFilter = null;
    Long sleep_duration = null;
    boolean skip_description = false;
    String host = "api.spinn3r.com";

    for (int i = 0; i < args.length; ++i) {

        String v = args[i];

        if (v.startsWith("--vendor")) {
            vendor = getOpt(v);
            continue;
        }

        if (v.startsWith("--filter")) {
            filter = getOpt(v);
            continue;
        }

        if (v.startsWith("--remote-filter")) {
            remoteFilter = getOpt(v);
            continue;
        }

        if (v.startsWith("--show_results")) {
            show_results = Integer.parseInt(getOpt(v));
            continue;
        }

        /*
         * The code for the --afterTimestamp must come
         * before the code for --after because --afterTimestamp
         * also matches startsWith("after");
         */
        if (v.startsWith("--afterTimestamp")) {
            after = Long.parseLong(getOpt(v));
            continue;
        }

        if (v.startsWith("--after")) {
            after = getOptAsTimeInMillis(v);
            continue;
        }

        /*
         * The code for the --beforeTimestamp must come
         * before the code for --before because --beforeTimestamp
         * also matches startsWith("before");
         */
        if (v.startsWith("--beforeTimestamp")) {
            before = Long.parseLong(getOpt(v));
            continue;
        }

        if (v.startsWith("--before")) {
            before = getOptAsTimeInMillis(v);
            continue;
        }

        if (v.startsWith("--range")) {
            range = Long.parseLong(getOpt(v));
            continue;
        }

        if (v.startsWith("--recover")) {
            restore = true;
            continue;
        }

        if (v.startsWith("--sleep_duration")) {
            sleep_duration = Long.parseLong(getOpt(v));
            continue;
        }

        if (v.startsWith("--save=")) {
            save = getOpt(v);
            continue;
        }

        if (v.startsWith("--save_method=")) {
            save_method = getOpt(v);
            continue;
        }

        if (v.startsWith("--skip_description=")) {
            skip_description = Boolean.parseBoolean(getOpt(v));
            continue;
        }

        if (v.startsWith("--save_compressed=")) {
            saveCompressed = Boolean.parseBoolean(getOpt(v));
            continue;
        }

        if (v.startsWith("--timing")) {
            timing = "true".equals(getOpt(v));
            continue;
        }

        if (v.startsWith("--debug")) {
            logLevel = Level.FINE;
            debugLogFilePath = getOpt(v);
            continue;
        }

        /*
         * if ( v.startsWith( "--spam_probability" ) ) {
         * config.setSpamProbability( Double.parseDouble( getOpt( v ) ) );
         * continue; }
         */

        if (v.startsWith("--dump_fields=")) {
            dumpFields = Boolean.parseBoolean(getOpt(v));
            continue;
        }

        if (v.startsWith("--dump=")) {
            dump = Boolean.parseBoolean(getOpt(v));
            continue;
        }

        if (v.startsWith("--csv=")) {
            csv = Boolean.parseBoolean(getOpt(v));
            continue;
        }

        if (v.startsWith("--memory")) {

            System.out.printf("max memory: %s\n", Runtime.getRuntime().maxMemory());
            System.exit(0);
        }

        if (v.startsWith("--host")) {
            host = getOpt(v);
            continue;
        }

        if (v.startsWith("--enable3")) {
            // is now default
            continue;
        }

        if (v.startsWith("com.spinn3r"))
            continue;

        if (v.startsWith("--api"))
            continue;

        // That's an unknown command line option. Exit.
        System.err.printf("Unknown command line option: %s\n", v);
        syntax();
        System.exit(1);

    }

    /*
     * Set the log level
     */
    Logger anonymousLogger = Logger.getAnonymousLogger();
    anonymousLogger.setLevel(logLevel);
    if (debugLogFilePath != null) {
        anonymousLogger.addHandler(new FileHandler(debugLogFilePath));
    }

    Factory factory = new Factory();
    String restoreURL = null;

    if (save != null && restore) {
        File savedir = new File(save);
        Collection<File> logFiles = getLogFiles(savedir);
        PermalinkLogReaderAdapter adapter = getRestoreURLS(logFiles);

        restoreURL = adapter.getLastUrl();
        long ctr = adapter.getLastCtr();

        for (File file : logFiles) {
            if (!file.delete())
                throw new IOException("Failed to delete " + file.toString());
        }

        factory.enableLogging(savedir, 1000000);
        if (restoreURL != null) {
            factory.enableRestart(ctr, restoreURL);
        }
        logManager = factory.getInjector().getInstance(TransactionHistoryManager.class);
    } else {
        logManager = factory.getInjector().getInstance(TransactionHistoryManager.class);
    }

    Config<? extends BaseResult> config = null;
    BaseClient<? extends BaseResult> client = null;

    if (api.startsWith("feed")) {
        config = new FeedConfig();
        client = new FeedClient();
    } else if (api.startsWith("comment")) {
        config = new CommentConfig();
        client = new CommentClient();
    } else {
        config = new PermalinkConfig();
        client = new PermalinkClient(
                restoreURL != null ? ImmutableList.of(restoreURL) : Collections.<String>emptyList());
    }

    config.setCommandLine(StringUtils.join(args, " "));

    config.setApi(api);
    config.setFormat(format);
    config.setVendor(vendor);
    config.setHost(host);
    config.setFilter(remoteFilter);
    config.setSkipDescription(skip_description);
    if (sleep_duration != null)
        client.setSleepDuration(sleep_duration);

    // assert that we have all required options.

    if (config.getVendor() == null) {
        syntax();
        System.exit(1);
    }

    long maxMemory = Runtime.getRuntime().maxMemory();
    long requiredMemory = (save == null) ? PARSE_REQUIRED_MEMORY : SAVE_REQUIRED_MEMORY;

    if (maxMemory < requiredMemory) {

        System.out.printf("ERROR: Reference client requires at least 2GB of memory.\n");
        System.out.printf("\n");
        System.out.printf("Now running with: %s vs %s required\n", maxMemory, requiredMemory);
        System.out.printf("\n");
        System.out.printf("Add -Xmx%dM to your command line and run again.\n", requiredMemory / (1024 * 1024));

        System.exit(1);

    }

    // use defaults

    System.out.println("Using vendor: " + config.getVendor());
    System.out.println("Using api:    " + api);

    if (after > -1)
        System.out.printf("After: %s (%s)\n", ISO8601DateParser.toString(Config.timestampToDate(after)), after);

    if (before > -1)
        System.out.printf("Before: %s (%s)\n", ISO8601DateParser.toString(Config.timestampToDate(before)),
                before);

    System.out.println("Saving results to disk: " + save);

    // Fetch for the last 5 minutes and then try to get up to date. In
    // production you'd want to call setFirstRequestURL from the
    // getLastRequestURL returned from fetch() below

    if (after == -1) {
        after = Config.millisecondsToTimestamp(System.currentTimeMillis());
        after = after - INTERVAL;
    }

    config.setAfterTimestamp(after);

    new Main().exec(client, config);

}

From source file:com.kynetx.ParseRuleset.java

public static void main(String[] args) throws Exception {
    File f = new File(args[0]);
    int notparsed = 0;
    int parsed = 0;

    File[] files = null;// ww  w  .  j  ava2s. c om
    if (f.isDirectory()) {
        files = f.listFiles();
    } else {
        files = new File[1];
        files[0] = new File(args[0]);
    }
    for (int i = 0; i < files.length; i++) {
        File thefile = files[i];
        long start = System.currentTimeMillis();
        boolean skipfile = false;
        for (int ii = 0; ii < ignore.length; ii++) {
            if (thefile.getCanonicalPath().indexOf(ignore[ii] + ".krl") > 0) {
                skipfile = true;
                break;
            }
        }
        if (thefile.length() == 0 || thefile.length() == 31 || thefile.length() == 162 || skipfile) {
            notparsed = notparsed + 1;
            //               System.out.println("Skipping: " + thefile + " in " + (System.currentTimeMillis() - start) + "ms." );
            //               System.out.println("Skipping " + thefile);
            continue;
        }
        parsed = parsed + 1;
        try {
            ANTLRFileStream input = new ANTLRFileStream(thefile.getCanonicalPath());
            com.kynetx.RuleSetLexer lexer = new com.kynetx.RuleSetLexer(input);
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            com.kynetx.RuleSetParser parser = new com.kynetx.RuleSetParser(tokens);
            parser.ruleset();
            JSONObject js = new JSONObject(parser.rule_json);
            if (parser.parse_errors.size() > 0) {
                for (int ii = 0; ii < parser.parse_errors.size(); ii++) {
                    System.err
                            .println("ERROR FOUND " + parser.parse_errors.get(ii) + " - " + thefile.toString());
                }
            }
            //               System.out.println("Parsed: " + thefile + " in " + (System.currentTimeMillis() - start) + "ms." );
            //System.out.println(unescapeUnicode(js.toString()));
            System.out.println(js.toString());
            //System.out.println("=============");
            //System.out.println(js.toString());
        } catch (Exception e) {
            //               System.out.println("Error: " + thefile + " in " + (System.currentTimeMillis() - start) + "ms." );
            System.out.println("Error " + thefile + " " + e.getMessage());
            e.printStackTrace();
        }
    }
    //         System.out.println("Not Parsed " + notparsed);
    //         System.out.println("Parsed " + parsed);

}