Example usage for java.lang String equals

List of usage examples for java.lang String equals

Introduction

In this page you can find the example usage for java.lang String equals.

Prototype

public boolean equals(Object anObject) 

Source Link

Document

Compares this string to the specified object.

Usage

From source file:com.joliciel.lefff.Lefff.java

/**
 * @param args//from ww w .j av a  2s  .c  om
 */
public static void main(String[] args) throws Exception {
    long startTime = (new Date()).getTime();
    String command = args[0];

    String memoryBaseFilePath = "";
    String lefffFilePath = "";
    String posTagSetPath = "";
    String posTagMapPath = "";
    String word = null;
    List<String> categories = null;
    int startLine = -1;
    int stopLine = -1;

    boolean firstArg = true;
    for (String arg : args) {
        if (firstArg) {
            firstArg = false;
            continue;
        }
        int equalsPos = arg.indexOf('=');
        String argName = arg.substring(0, equalsPos);
        String argValue = arg.substring(equalsPos + 1);
        if (argName.equals("memoryBase"))
            memoryBaseFilePath = argValue;
        else if (argName.equals("lefffFile"))
            lefffFilePath = argValue;
        else if (argName.equals("startLine"))
            startLine = Integer.parseInt(argValue);
        else if (argName.equals("stopLine"))
            stopLine = Integer.parseInt(argValue);
        else if (argName.equals("posTagSet"))
            posTagSetPath = argValue;
        else if (argName.equals("posTagMap"))
            posTagMapPath = argValue;
        else if (argName.equals("word"))
            word = argValue;
        else if (argName.equals("categories")) {
            String[] parts = argValue.split(",");
            categories = new ArrayList<String>();
            for (String part : parts) {
                categories.add(part);
            }
        } else
            throw new RuntimeException("Unknown argument: " + argName);
    }

    final LefffServiceLocator locator = new LefffServiceLocator();
    locator.setDataSourcePropertiesFile("jdbc-live.properties");

    TalismaneServiceLocator talismaneServiceLocator = TalismaneServiceLocator.getInstance();

    final LefffService lefffService = locator.getLefffService();
    if (command.equals("load")) {
        if (lefffFilePath.length() == 0)
            throw new RuntimeException("Required argument: lefffFile");
        final LefffLoader loader = lefffService.getLefffLoader();
        File file = new File(lefffFilePath);
        if (startLine > 0)
            loader.setStartLine(startLine);
        if (stopLine > 0)
            loader.setStopLine(stopLine);

        loader.LoadFile(file);
    } else if (command.equals("serialiseBase")) {
        if (memoryBaseFilePath.length() == 0)
            throw new RuntimeException("Required argument: memoryBase");
        if (posTagSetPath.length() == 0)
            throw new RuntimeException("Required argument: posTagSet");
        if (posTagMapPath.length() == 0)
            throw new RuntimeException("Required argument: posTagMap");

        PosTaggerServiceLocator posTaggerServiceLocator = talismaneServiceLocator.getPosTaggerServiceLocator();
        PosTaggerService posTaggerService = posTaggerServiceLocator.getPosTaggerService();
        File posTagSetFile = new File(posTagSetPath);
        PosTagSet posTagSet = posTaggerService.getPosTagSet(posTagSetFile);

        File posTagMapFile = new File(posTagMapPath);
        LefffPosTagMapper posTagMapper = lefffService.getPosTagMapper(posTagMapFile, posTagSet);

        Map<PosTagSet, LefffPosTagMapper> posTagMappers = new HashMap<PosTagSet, LefffPosTagMapper>();
        posTagMappers.put(posTagSet, posTagMapper);

        LefffMemoryLoader loader = new LefffMemoryLoader();
        LefffMemoryBase memoryBase = loader.loadMemoryBaseFromDatabase(lefffService, posTagMappers, categories);
        File memoryBaseFile = new File(memoryBaseFilePath);
        memoryBaseFile.delete();
        loader.serializeMemoryBase(memoryBase, memoryBaseFile);
    } else if (command.equals("deserialiseBase")) {
        if (memoryBaseFilePath.length() == 0)
            throw new RuntimeException("Required argument: memoryBase");

        LefffMemoryLoader loader = new LefffMemoryLoader();
        File memoryBaseFile = new File(memoryBaseFilePath);
        LefffMemoryBase memoryBase = loader.deserializeMemoryBase(memoryBaseFile);

        String[] testWords = new String[] { "avoir" };
        if (word != null) {
            testWords = word.split(",");
        }

        for (String testWord : testWords) {
            Set<PosTag> possiblePosTags = memoryBase.findPossiblePosTags(testWord);
            LOG.debug("##### PosTags for '" + testWord + "': " + possiblePosTags.size());
            int i = 1;
            for (PosTag posTag : possiblePosTags) {
                LOG.debug("### PosTag " + (i++) + ":" + posTag);
            }

            List<? extends LexicalEntry> entriesForWord = memoryBase.getEntries(testWord);
            LOG.debug("##### Entries for '" + testWord + "': " + entriesForWord.size());
            i = 1;
            for (LexicalEntry entry : entriesForWord) {
                LOG.debug("### Entry " + (i++) + ":" + entry.getWord());
                LOG.debug("Category " + entry.getCategory());
                LOG.debug("Predicate " + entry.getPredicate());
                LOG.debug("Lemma " + entry.getLemma());
                LOG.debug("Morphology " + entry.getMorphology());
            }

            List<? extends LexicalEntry> entriesForLemma = memoryBase.getEntriesForLemma(testWord, "");
            LOG.debug("##### Entries for '" + testWord + "' lemma: " + entriesForLemma.size());
            for (LexicalEntry entry : entriesForLemma) {
                LOG.debug("### Entry " + entry.getWord());
                LOG.debug("Category " + entry.getCategory());
                LOG.debug("Predicate " + entry.getPredicate());
                LOG.debug("Lemma " + entry.getLemma());
                LOG.debug("Morphology " + entry.getMorphology());
                for (PredicateArgument argument : entry.getPredicateArguments()) {
                    LOG.debug("Argument: " + argument.getFunction() + ",Optional? " + argument.isOptional());
                    for (String realisation : argument.getRealisations()) {
                        LOG.debug("Realisation: " + realisation);
                    }
                }
            }
        }

    } else {
        System.out.println("Usage : Lefff load filepath");
    }
    long endTime = (new Date()).getTime() - startTime;
    LOG.debug("Total runtime: " + ((double) endTime / 1000) + " seconds");
}

From source file:com.annuletconsulting.homecommand.server.HomeCommand.java

/**
 * This class will accept commands from a node in each room. For it to react to events on the server
 * computer, it must be also running as a node.  However the server can cause all nodes to react
 * to an event happening on any node, such as an email or text arriving.  A call on a node device
 * could pause all music devices, for example.
 * //from   w w w  .  j av  a2  s  .  co  m
 * @param args
 */
public static void main(String[] args) {
    try {
        socket = Integer.parseInt(HomeComandProperties.getInstance().getServerPort());
        nonJavaUserModulesPath = HomeComandProperties.getInstance().getNonJavaUserDir();
    } catch (Exception exception) {
        System.out.println("Error loading from properties file.");
        exception.printStackTrace();
    }
    try {
        sharedKey = HomeComandProperties.getInstance().getSharedKey();
        if (sharedKey == null)
            System.out.println("shared_key is null, commands without valid signatures will be processed.");
    } catch (Exception exception) {
        System.out.println("shared_key not found in properties file.");
        exception.printStackTrace();
    }
    try {
        if (args.length > 0) {
            String arg0 = args[0];
            if (arg0.equals("help") || arg0.equals("?") || arg0.equals("usage") || arg0.equals("-help")
                    || arg0.equals("-?")) {
                System.out.println(
                        "The defaults can be changed by editing the HomeCommand.properties file, or you can override them temporarily using command line options.");
                System.out.println("\nHome Command Server command line overrride usage:");
                System.out.println(
                        "hcserver [server_port] [java_user_module_directory] [non_java_user_module_directory]"); //TODO make hcserver.sh
                System.out.println("\nDefaults:");
                System.out.println("server_port: " + socket);
                System.out.println("java_user_module_directory: " + userModulesPath);
                System.out.println("non_java_user_module_directory: " + nonJavaUserModulesPath);
                System.out.println("\n2013 | Annulet, LLC");
            }
            socket = Integer.parseInt(arg0);
        }
        if (args.length > 1)
            userModulesPath = args[1];
        if (args.length > 2)
            nonJavaUserModulesPath = args[2];

        System.out.println("Config loaded, initializing modules.");
        modules.add(new HueLightModule());
        System.out.println("HueLightModule initialized.");
        modules.add(new QuestionModule());
        System.out.println("QuestionModule initialized.");
        modules.add(new MathModule());
        System.out.println("MathModule initialized.");
        modules.add(new MusicModule());
        System.out.println("MusicModule initialized.");
        modules.add(new NonCopyrightInfringingGenericSpaceExplorationTVShowModule());
        System.out.println("NonCopyrightInfringingGenericSpaceExplorationTVShowModule initialized.");
        modules.add(new HelpModule());
        System.out.println("HelpModule initialized.");
        modules.add(new SetUpModule());
        System.out.println("SetUpModule initialized.");
        modules.addAll(NonJavaUserModuleLoader.loadModulesAt(nonJavaUserModulesPath));
        System.out.println("NonJavaUserModuleLoader initialized.");
        ServerSocket serverSocket = new ServerSocket(socket);
        System.out.println("Listening...");
        while (!end) {
            Socket socket = serverSocket.accept();
            InputStreamReader isr = new InputStreamReader(socket.getInputStream());
            PrintWriter output = new PrintWriter(socket.getOutputStream(), true);
            int character;
            StringBuffer inputStrBuffer = new StringBuffer();
            while ((character = isr.read()) != 13) {
                inputStrBuffer.append((char) character);
            }
            System.out.println(inputStrBuffer.toString());
            String[] cmd; // = inputStrBuffer.toString().split(" ");
            String result = "YOUR REQUEST WAS NOT VALID JSON";
            if (inputStrBuffer.substring(0, 1).equals("{")) {
                nodeType = extractElement(inputStrBuffer.toString(), "node_type");
                if (sharedKey != null) {
                    if (validateSignature(extractElement(inputStrBuffer.toString(), "time_stamp"),
                            extractElement(inputStrBuffer.toString(), "signature"))) {
                        if ("Y".equalsIgnoreCase(extractElement(inputStrBuffer.toString(), "cmd_encoded")))
                            cmd = decryptCommand(extractElement(inputStrBuffer.toString(), "command"));
                        else
                            cmd = extractElement(inputStrBuffer.toString(), "command").split(" ");
                        result = getResult(cmd);
                    } else
                        result = "YOUR SIGNATURE DID NOT MATCH, CHECK SHARED KEY";
                } else {
                    cmd = extractElement(inputStrBuffer.toString(), "command").split(" ");
                    result = getResult(cmd);
                }
            }
            System.out.println(result);
            output.print(result);
            output.print((char) 13);
            output.close();
            isr.close();
            socket.close();
        }
        serverSocket.close();
        System.out.println("Shutting down.");
    } catch (Exception exception) {
        exception.printStackTrace();
    }
}

From source file:org.fcrepo.server.utilities.ServerUtility.java

/**
 * Command-line entry point to reload policies. Takes 3 args: protocol user
 * pass//  w  w  w  .  ja  v a2 s .  c  o m
 */
public static void main(String[] args) {

    if (args.length < 1) {
        System.out.println("Parameters:  method arg1 arg2 arg3 etc");
        System.out.println("");
        System.out.println("Methods:");
        System.out.println("    reloadpolicies");
        System.out.println("    migratedatastreamcontrolgroup");
        System.exit(0);
    }

    String method = args[0].toLowerCase();

    if (method.equals("reloadpolicies")) {
        if (args.length == 4) {
            try {
                reloadPolicies(args[1], args[2], args[3]);
                System.out.println("SUCCESS: Policies have been reloaded");
                System.exit(0);
            } catch (Throwable th) {
                th.printStackTrace();
                System.err.println("ERROR: Reloading policies failed; see above");
                System.exit(1);
            }
        } else {
            System.err.println("ERROR: Three arguments required: " + "http|https username password");
            System.exit(1);
        }

    } else if (method.equals("migratedatastreamcontrolgroup")) {

        // too many args
        if (args.length > 10) {
            System.err.println("ERROR: too many arguments provided");
            System.exit(1);
        }

        // too few
        if (args.length < 7) {

            System.err.println("ERROR: insufficient arguments provided.  Arguments are: ");
            System.err.println("    protocol [http|https]"); // 1; 0 is method
            System.err.println("    user"); // 2
            System.err.println("    password"); // 3
            System.err.println("    pid - either"); // 4
            System.err.println("        a single pid, eg demo:object");
            System.err.println("        list of pids separated by commas, eg demo:object1,demo:object2");
            System.err.println("        name of file containing pids, eg file:///path/to/file");
            System.err.println("    dsid - either"); // 5
            System.err.println("        a single datastream id, eg DC");
            System.err.println("        list of ids separated by commas, eg DC,RELS-EXT");
            System.err.println("    controlGroup - target control group (note only M is implemented)"); // 6
            System.err.println(
                    "    addXMLHeader - add an XML header to the datastream [true|false, default false]"); // 7
            System.err.println("    reformat - reformat the XML [true|false, default false]"); // 8
            System.err.println(
                    "    setMIMETypeCharset - add charset=UTF-8 to the MIMEType [true|false, default false]"); // 9
            System.exit(1);
        }

        try {
            // optional args
            boolean addXMLHeader = getArgBoolean(args, 7, false);
            boolean reformat = getArgBoolean(args, 8, false);
            boolean setMIMETypeCharset = getArgBoolean(args, 9, false);
            ;

            InputStream is = modifyDatastreamControlGroup(args[1], args[2], args[3], args[4], args[5], args[6],
                    addXMLHeader, reformat, setMIMETypeCharset);

            IOUtils.copy(is, System.out);
            is.close();

            System.out.println("SUCCESS: Datastreams modified");
            System.exit(0);

        } catch (Throwable th) {
            th.printStackTrace();
            System.err.println("ERROR: migrating datastream control group failed; see above");
            System.exit(1);
        }

    } else {
        System.err.println("ERROR: unrecognised method " + method);
        System.exit(1);
    }
}

From source file:com.linkedin.databus2.core.schema.tools.AvroConvertMain.java

/**
 * @param args//from w ww .  j  a  v a2  s.  co  m
 */
public static void main(String[] args) throws Exception {

    ConsoleAppender app = new ConsoleAppender(new SimpleLayout());
    Logger.getRootLogger().removeAllAppenders();
    Logger.getRootLogger().addAppender(app);

    AvroConvertCli cli = new AvroConvertCli();

    try {
        cli.parseCommandLine(args);
    } catch (ParseException pe) {
        System.err.println(pe.getMessage());
        cli.printUsage();
        System.exit(1);
    }

    if (!cli.hasOptions() || cli.hasHelpOption()) {
        cli.printUsage();
        System.exit(0);
    }

    int verbosity = cli.getVerbosity();
    switch (verbosity) {
    case 0:
        Logger.getRootLogger().setLevel(Level.ERROR);
        break;
    case 1:
        Logger.getRootLogger().setLevel(Level.INFO);
        break;
    case 2:
        Logger.getRootLogger().setLevel(Level.DEBUG);
        break;
    default:
        Logger.getRootLogger().setLevel(Level.ALL);
        break;
    }

    AvroFormat inputFormat = cli.getInputFormat(AvroFormat.JSON);
    LOG.info("Using input format: " + inputFormat);

    AvroFormat outputFormat = cli.getOutputFormat(AvroFormat.JSON);
    LOG.info("Using output format: " + outputFormat);

    String inputSchemaName = cli.getInputSchema(null);
    if (null == inputSchemaName) {
        System.err.println("Input schema expected");
        cli.printUsage();
        System.exit(4);
    }

    Schema inputSchema = null;
    try {
        inputSchema = openSchema(inputSchemaName);
    } catch (IOException ioe) {
        System.err.println("Unable to open input schema: " + ioe);
        System.exit(2);
    }
    LOG.info("Using input schema:" + inputSchemaName);

    String outputSchemaName = cli.getOutputSchema(inputSchemaName);
    Schema outputSchema = null;
    try {
        outputSchema = outputSchemaName.equals(inputSchemaName) ? inputSchema : openSchema(outputSchemaName);
    } catch (IOException ioe) {
        System.err.println("Unable to open output schema: " + ioe);
        System.exit(3);
    }
    LOG.info("Using output schema:" + outputSchemaName);

    String inputFileName = cli.getInputFileName("-");
    InputStream input = inputFileName.equals("-") ? System.in : new FileInputStream(inputFileName);
    LOG.info("Using input: " + inputFileName);

    String outputFileName = cli.getOutputFileName("-");
    OutputStream output = outputFileName.equals("-") ? System.out : new FileOutputStream(outputFileName);
    LOG.info("Using output: " + outputFileName);

    AvroConverter avroConverter = new AvroConverter(inputFormat, outputFormat, inputSchema, outputSchema);
    avroConverter.convert(input, output);
    if (!inputFileName.equals("-"))
        input.close();
    if (!outputFileName.equals("-"))
        output.close();
}

From source file:com.basho.riak.presto.cli.CLI.java

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

    Injector i = Guice.createInjector(Stage.PRODUCTION, //new JsonModule());
            new Module() {
                @Override/*from  w ww . ja v  a2  s.c o  m*/
                public void configure(Binder binder) {
                    jsonBinder(binder).addDeserializerBinding(Type.class)
                            .to(Deserializer.CLITypeDeserializer.class);
                    binder.bind(ObjectMapper.class).toProvider(ObjectMapperProvider.class);
                    binder.bind(JsonCodecFactory.class).in(Scopes.SINGLETON);
                }
            });
    log.debug("%s", i.getTypeConverterBindings());

    if (args.length < 4) {
        usage();
        return;
    }

    String hostname = args[0];
    String port = args[1];
    String command = args[2];
    String schemaName = args[3];
    RiakConfig config = new RiakConfig(hostname, port);

    // Actual command implementations
    if (command.equals("list-tables") && args.length == 4) {
        new SchemaDef(i, config).listTables(schemaName);
    } else if (command.equals("setup-schema") && args.length == 4) {
        new SchemaDef(i, config).setupSchema(schemaName);

    } else if (args.length == 5) {
        String tableArg = args[4];
        if (command.equals("create-schema")) {
            CLI.log("This option is not currently supported.");
        } else if (command.equals("create-tabledef")) {
            new TableDef(i, config, schemaName, true).create(tableArg);
        } else if (command.equals("show-tabledef")) {
            new TableDef(i, config, schemaName, true).show(tableArg);
        } else if (command.equals("clear-tabledef")) {
            new TableDef(i, config, schemaName, true).clear(tableArg);
        } else if (command.equals("check-tabledef")) {
            new TableDef(i, config, schemaName, false).check(tableArg);
        }

    } else if (args[0].equals("plan")) {
        System.out.println(args[1]);

        String node = args[1];
        String cookie = "riak";
        if (args.length > 2) {
            cookie = args[2];
        }
        System.out.println("connecting to Riak node " + node + " with cookie=" + cookie);

        String self = "client@127.0.0.1";
        try {
            DirectConnection conn = new DirectConnection(self, cookie);
            conn.connect(node);
            //conn.pid();
            //conn.ping();
            Coverage coverage = new Coverage(conn);
            coverage.plan();
            List<SplitTask> splits = coverage.getSplits();

            System.out.println("print coverage plan==============");
            System.out.println(coverage.toString());

            for (SplitTask split : splits) {
                System.out.println("============printing split data at " + split.getHost() + "===============");

                split.fetchAllData(conn, "default", "foobartable");
            }
        } catch (java.io.IOException e) {
            System.err.println(e);
        }
    } else {
        usage();
    }
    // Mock a Wock and don't leave any trash!
    System.gc();
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
    ServerSocket ss = ssf.createServerSocket(443);
    while (true) {
        Socket s = ss.accept();/*from  ww  w. java 2 s  . c o m*/
        PrintStream out = new PrintStream(s.getOutputStream());
        BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
        String info = null;
        String request = null;
        String refer = null;

        while ((info = in.readLine()) != null) {
            if (info.startsWith("GET")) {
                request = info;
            }
            if (info.startsWith("Referer:")) {
                refer = info;
            }
            if (info.equals(""))
                break;
        }
        if (request != null) {
            out.println("HTTP/1.0 200 OK\nMIME_version:1.0\nContent_Type:text/html");
            int sp1 = request.indexOf(' ');
            int sp2 = request.indexOf(' ', sp1 + 1);
            String filename = request.substring(sp1 + 2, sp2);
            if (refer != null) {
                sp1 = refer.indexOf(' ');
                refer = refer.substring(sp1 + 1, refer.length());
                if (!refer.endsWith("/")) {
                    refer = refer + "/";
                }
                filename = refer + filename;
            }
            URL con = new URL(filename);
            InputStream gotoin = con.openStream();
            int n = gotoin.available();
            byte buf[] = new byte[1024];
            out.println("HTTP/1.0 200 OK\nMIME_version:1.0\nContent_Type:text/html");
            out.println("Content_Length:" + n + "\n");
            while ((n = gotoin.read(buf)) >= 0) {
                out.write(buf, 0, n);
            }
            out.close();
            s.close();
            in.close();
        }
    }
}

From source file:VerboseGC.java

public static void main(String[] args) {
    if (args.length < 1) {
        usage();// w ww  .j a v  a  2 s  .  c  o  m
    }

    String hostname = "";
    int port = -1;
    long interval = 5000; // default is 5 second interval
    long mins = 5;
    for (int argIndex = 0; argIndex < args.length; argIndex++) {
        String arg = args[argIndex];
        if (args[argIndex].startsWith("-")) {
            if (arg.equals("-h") || arg.equals("-help") || arg.equals("-?")) {
                usage();
            } else if (arg.startsWith("-interval=")) {
                try {
                    interval = Integer.parseInt(arg.substring(10)) * 1000;
                } catch (NumberFormatException ex) {
                    usage();
                }
            } else if (arg.startsWith("-duration=")) {
                try {
                    mins = Integer.parseInt(arg.substring(10));
                } catch (NumberFormatException ex) {
                    usage();
                }
            } else {
                // Unknown switch
                System.err.println("Unrecognized option: " + arg);
                usage();
            }
        } else {
            String[] arg2 = arg.split(":");
            if (arg2.length != 2) {
                usage();
            }
            hostname = arg2[0];
            try {
                port = Integer.parseInt(arg2[1]);
            } catch (NumberFormatException x) {
                usage();
            }
            if (port < 0) {
                usage();
            }
        }
    }

    // get full thread dump and perform deadlock detection
    VerboseGC vgc = new VerboseGC(hostname, port);
    long samples = (mins * 60 * 1000) / interval;
    vgc.dump(interval, samples);

}

From source file:baldrickv.s3streamingtool.S3StreamingTool.java

public static void main(String args[]) throws Exception {
    BasicParser p = new BasicParser();

    Options o = getOptions();/*  w w w. j  a  v a  2  s .c  o  m*/

    CommandLine cl = p.parse(o, args);

    if (cl.hasOption('h')) {
        HelpFormatter hf = new HelpFormatter();
        hf.setWidth(80);

        StringBuilder sb = new StringBuilder();

        sb.append("\n");
        sb.append("Upload:\n");
        sb.append("    -u -r creds -s 50M -b my_bucket -f hda1.dump -t 10\n");
        sb.append("Download:\n");
        sb.append("    -d -r creds -s 50M -b my_bucket -f hda1.dump -t 10\n");
        sb.append("Upload encrypted:\n");
        sb.append("    -u -r creds -z -k secret_key -s 50M -b my_bucket -f hda1.dump -t 10\n");
        sb.append("Download encrypted:\n");
        sb.append("    -d -r creds -z -k secret_key -s 50M -b my_bucket -f hda1.dump -t 10\n");
        sb.append("Cleanup in-progress multipart uploads\n");
        sb.append("    -c -r creds -b my_bucket\n");
        System.out.println(sb.toString());

        hf.printHelp("See above", o);

        return;
    }

    int n = 0;
    if (cl.hasOption('d'))
        n++;
    if (cl.hasOption('u'))
        n++;
    if (cl.hasOption('c'))
        n++;
    if (cl.hasOption('m'))
        n++;

    if (n != 1) {
        System.err.println("Must specify at exactly one of -d, -u, -c or -m");
        System.exit(-1);
    }

    if (cl.hasOption('m')) {
        //InputStream in = new java.io.BufferedInputStream(System.in,1024*1024*2);
        InputStream in = System.in;
        System.out.println(TreeHashGenerator.calculateTreeHash(in));
        return;
    }

    require(cl, 'b');

    if (cl.hasOption('d') || cl.hasOption('u')) {
        require(cl, 'f');
    }
    if (cl.hasOption('z')) {
        require(cl, 'k');
    }

    AWSCredentials creds = null;

    if (cl.hasOption('r')) {
        creds = Utils.loadAWSCredentails(cl.getOptionValue('r'));
    } else {
        if (cl.hasOption('i') && cl.hasOption('e')) {
            creds = new BasicAWSCredentials(cl.getOptionValue('i'), cl.getOptionValue('e'));
        } else {

            System.out.println("Must specify either credential file (-r) or AWS key ID and secret (-i and -e)");
            System.exit(-1);
        }
    }

    S3StreamConfig config = new S3StreamConfig();
    config.setEncryption(false);
    if (cl.hasOption('z')) {
        config.setEncryption(true);
        config.setSecretKey(Utils.loadSecretKey(cl.getOptionValue("k")));
    }

    if (cl.hasOption("encryption-mode")) {
        config.setEncryptionMode(cl.getOptionValue("encryption-mode"));
    }
    config.setS3Bucket(cl.getOptionValue("bucket"));
    if (cl.hasOption("file")) {
        config.setS3File(cl.getOptionValue("file"));
    }

    if (cl.hasOption("threads")) {
        config.setIOThreads(Integer.parseInt(cl.getOptionValue("threads")));
    }

    if (cl.hasOption("blocksize")) {
        String s = cl.getOptionValue("blocksize");
        s = s.toUpperCase();
        int multi = 1;

        int end = 0;
        while ((end < s.length()) && (s.charAt(end) >= '0') && (s.charAt(end) <= '9')) {
            end++;
        }
        int size = Integer.parseInt(s.substring(0, end));

        if (end < s.length()) {
            String m = s.substring(end);
            if (m.equals("K"))
                multi = 1024;
            else if (m.equals("M"))
                multi = 1048576;
            else if (m.equals("G"))
                multi = 1024 * 1024 * 1024;
            else if (m.equals("KB"))
                multi = 1024;
            else if (m.equals("MB"))
                multi = 1048576;
            else if (m.equals("GB"))
                multi = 1024 * 1024 * 1024;
            else {
                System.out.println("Unknown suffix on block size.  Only K,M and G understood.");
                System.exit(-1);
            }

        }
        size *= multi;
        config.setBlockSize(size);
    }

    Logger.getLogger("").setLevel(Level.FINE);

    S3StreamingDownload.log.setLevel(Level.FINE);
    S3StreamingUpload.log.setLevel(Level.FINE);

    config.setS3Client(new AmazonS3Client(creds));
    config.setGlacierClient(new AmazonGlacierClient(creds));
    config.getGlacierClient().setEndpoint("glacier.us-west-2.amazonaws.com");

    if (cl.hasOption("glacier")) {
        config.setGlacier(true);
        config.setStorageInterface(new StorageGlacier(config.getGlacierClient()));
    } else {
        config.setStorageInterface(new StorageS3(config.getS3Client()));
    }
    if (cl.hasOption("bwlimit")) {
        config.setMaxBytesPerSecond(Double.parseDouble(cl.getOptionValue("bwlimit")));

    }

    if (cl.hasOption('c')) {
        if (config.getGlacier()) {
            GlacierCleanupMultipart.cleanup(config);
        } else {
            S3CleanupMultipart.cleanup(config);
        }
        return;
    }
    if (cl.hasOption('d')) {
        config.setOutputStream(System.out);
        S3StreamingDownload.download(config);
        return;
    }
    if (cl.hasOption('u')) {
        config.setInputStream(System.in);
        S3StreamingUpload.upload(config);
        return;
    }

}

From source file:ca.ualberta.exemplar.core.Exemplar.java

public static void main(String[] rawArgs) throws FileNotFoundException, UnsupportedEncodingException {

    CommandLineParser cli = new BasicParser();

    Options options = new Options();
    options.addOption("h", "help", false, "shows this message");
    options.addOption("b", "benchmark", true, "expects input to be a benchmark file (type = binary | nary)");
    options.addOption("p", "parser", true, "defines which parser to use (parser = stanford | malt)");

    CommandLine line = null;//from  ww w  .j a va 2s . c om

    try {
        line = cli.parse(options, rawArgs);
    } catch (ParseException exp) {
        System.err.println(exp.getMessage());
        System.exit(1);
    }

    String[] args = line.getArgs();
    String parserName = line.getOptionValue("parser", "malt");

    if (line.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("sh ./exemplar", options);
        System.exit(0);
    }

    if (args.length != 2) {
        System.out.println("error: exemplar requires an input file and output file.");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("sh ./exemplar <input> <output>", options);
        System.exit(0);
    }

    File input = new File(args[0]);
    File output = new File(args[1]);

    String benchmarkType = line.getOptionValue("benchmark", "");
    if (!benchmarkType.isEmpty()) {
        if (benchmarkType.equals("binary")) {
            BenchmarkBinary evaluation = new BenchmarkBinary(input, output, parserName);
            evaluation.runAndTime();
            System.exit(0);
        } else {
            if (benchmarkType.equals("nary")) {
                BenchmarkNary evaluation = new BenchmarkNary(input, output, parserName);
                evaluation.runAndTime();
                System.exit(0);
            } else {
                System.out.println("error: benchmark option has to be either 'binary' or 'nary'.");
                System.exit(0);
            }
        }
    }

    Parser parser = null;
    if (parserName.equals("stanford")) {
        parser = new ParserStanford();
    } else {
        if (parserName.equals("malt")) {
            parser = new ParserMalt();
        } else {
            System.out.println(parserName + " is not a valid parser.");
            System.exit(0);
        }
    }

    System.out.println("Starting EXEMPLAR...");

    RelationExtraction exemplar = null;
    try {
        exemplar = new RelationExtraction(parser);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    BlockingQueue<String> inputQueue = new ArrayBlockingQueue<String>(QUEUE_SIZE);
    PlainTextReader reader = null;
    reader = new PlainTextReader(inputQueue, input);

    Thread readerThread = new Thread(reader);
    readerThread.start();

    PrintStream statementsOut = null;

    try {
        statementsOut = new PrintStream(output, "UTF-8");
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
        System.exit(0);
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
        System.exit(0);
    }

    statementsOut.println("Subjects\tRelation\tObjects\tNormalized Relation\tSentence");

    while (true) {
        String doc = null;
        try {
            doc = inputQueue.take();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        if (doc.isEmpty()) {
            break;
        }

        List<RelationInstance> instances = exemplar.extractRelations(doc);

        for (RelationInstance instance : instances) {

            // Output SUBJ arguments in a separate field, for clarity
            boolean first = true;
            for (Argument arg : instance.getArguments()) {
                if (arg.argumentType.equals("SUBJ")) {
                    if (first) {
                        first = false;
                    } else {
                        statementsOut.print(",,");
                    }
                    statementsOut.print(arg.argumentType + ":" + arg.entityId);
                }
            }

            // Output the original relation
            statementsOut.print("\t" + instance.getOriginalRelation() + "\t");

            // Output the DOBJ arguments, followed by POBJ
            first = true;
            for (Argument arg : instance.getArguments()) {
                if (arg.argumentType.equals("DOBJ")) {
                    if (first) {
                        first = false;
                    } else {
                        statementsOut.print(",,");
                    }
                    statementsOut.print(arg.argumentType + ":" + arg.entityId);
                }
            }
            for (Argument arg : instance.getArguments()) {
                if (arg.argumentType.startsWith("POBJ")) {
                    if (first) {
                        first = false;
                    } else {
                        statementsOut.print(",,");
                    }
                    statementsOut.print(arg.argumentType + ":" + arg.entityId);
                }
            }
            statementsOut.print("\t" + instance.getNormalizedRelation());
            statementsOut.print("\t" + instance.getSentence());
            statementsOut.println();
        }
    }

    System.out.println("Done!");
    statementsOut.close();

}

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

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

    options.addOption(new Option(HELP_OPTION, "show help"));
    options.addOption(new Option(OPTIMIZE_OPTION, "merge indexes into a single segment"));
    options.addOption(new Option(STORE_TERM_VECTORS_OPTION, "store term vectors"));

    options.addOption(OptionBuilder.withArgName("dir").hasArg().withDescription("source collection directory")
            .create(COLLECTION_OPTION));
    options.addOption(//w  w  w.  java 2  s  . co  m
            OptionBuilder.withArgName("dir").hasArg().withDescription("index location").create(INDEX_OPTION));
    options.addOption(OptionBuilder.withArgName("file").hasArg().withDescription("file with deleted tweetids")
            .create(DELETES_OPTION));
    options.addOption(OptionBuilder.withArgName("id").hasArg().withDescription("max id").create(MAX_ID_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(HELP_OPTION) || !cmdline.hasOption(COLLECTION_OPTION)
            || !cmdline.hasOption(INDEX_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(IndexStatuses.class.getName(), options);
        System.exit(-1);
    }

    String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION);
    String indexPath = cmdline.getOptionValue(INDEX_OPTION);

    final FieldType textOptions = new FieldType();
    textOptions.setIndexed(true);
    textOptions.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
    textOptions.setStored(true);
    textOptions.setTokenized(true);
    if (cmdline.hasOption(STORE_TERM_VECTORS_OPTION)) {
        textOptions.setStoreTermVectors(true);
    }

    LOG.info("collection: " + collectionPath);
    LOG.info("index: " + indexPath);

    LongOpenHashSet deletes = null;
    if (cmdline.hasOption(DELETES_OPTION)) {
        deletes = new LongOpenHashSet();
        File deletesFile = new File(cmdline.getOptionValue(DELETES_OPTION));
        if (!deletesFile.exists()) {
            System.err.println("Error: " + deletesFile + " does not exist!");
            System.exit(-1);
        }
        LOG.info("Reading deletes from " + deletesFile);

        FileInputStream fin = new FileInputStream(deletesFile);
        byte[] ignoreBytes = new byte[2];
        fin.read(ignoreBytes); // "B", "Z" bytes from commandline tools
        BufferedReader br = new BufferedReader(new InputStreamReader(new CBZip2InputStream(fin)));

        String s;
        while ((s = br.readLine()) != null) {
            if (s.contains("\t")) {
                deletes.add(Long.parseLong(s.split("\t")[0]));
            } else {
                deletes.add(Long.parseLong(s));
            }
        }
        br.close();
        fin.close();
        LOG.info("Read " + deletes.size() + " tweetids from deletes file.");
    }

    long maxId = Long.MAX_VALUE;
    if (cmdline.hasOption(MAX_ID_OPTION)) {
        maxId = Long.parseLong(cmdline.getOptionValue(MAX_ID_OPTION));
        LOG.info("index: " + maxId);
    }

    long startTime = System.currentTimeMillis();
    File file = new File(collectionPath);
    if (!file.exists()) {
        System.err.println("Error: " + file + " does not exist!");
        System.exit(-1);
    }

    StatusStream stream = new JsonStatusCorpusReader(file);

    Directory dir = FSDirectory.open(new File(indexPath));
    IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_43, IndexStatuses.ANALYZER);
    config.setOpenMode(OpenMode.CREATE);

    IndexWriter writer = new IndexWriter(dir, config);
    int cnt = 0;
    Status status;
    try {
        while ((status = stream.next()) != null) {
            if (status.getText() == null) {
                continue;
            }

            // Skip deletes tweetids.
            if (deletes != null && deletes.contains(status.getId())) {
                continue;
            }

            if (status.getId() > maxId) {
                continue;
            }

            cnt++;
            Document doc = new Document();
            doc.add(new LongField(StatusField.ID.name, status.getId(), Field.Store.YES));
            doc.add(new LongField(StatusField.EPOCH.name, status.getEpoch(), Field.Store.YES));
            doc.add(new TextField(StatusField.SCREEN_NAME.name, status.getScreenname(), Store.YES));

            doc.add(new Field(StatusField.TEXT.name, status.getText(), textOptions));

            doc.add(new IntField(StatusField.FRIENDS_COUNT.name, status.getFollowersCount(), Store.YES));
            doc.add(new IntField(StatusField.FOLLOWERS_COUNT.name, status.getFriendsCount(), Store.YES));
            doc.add(new IntField(StatusField.STATUSES_COUNT.name, status.getStatusesCount(), Store.YES));

            long inReplyToStatusId = status.getInReplyToStatusId();
            if (inReplyToStatusId > 0) {
                doc.add(new LongField(StatusField.IN_REPLY_TO_STATUS_ID.name, inReplyToStatusId,
                        Field.Store.YES));
                doc.add(new LongField(StatusField.IN_REPLY_TO_USER_ID.name, status.getInReplyToUserId(),
                        Field.Store.YES));
            }

            String lang = status.getLang();
            if (!lang.equals("unknown")) {
                doc.add(new TextField(StatusField.LANG.name, status.getLang(), Store.YES));
            }

            long retweetStatusId = status.getRetweetedStatusId();
            if (retweetStatusId > 0) {
                doc.add(new LongField(StatusField.RETWEETED_STATUS_ID.name, retweetStatusId, Field.Store.YES));
                doc.add(new LongField(StatusField.RETWEETED_USER_ID.name, status.getRetweetedUserId(),
                        Field.Store.YES));
                doc.add(new IntField(StatusField.RETWEET_COUNT.name, status.getRetweetCount(), Store.YES));
                if (status.getRetweetCount() < 0 || status.getRetweetedStatusId() < 0) {
                    LOG.warn("Error parsing retweet fields of " + status.getId());
                }
            }

            writer.addDocument(doc);
            if (cnt % 100000 == 0) {
                LOG.info(cnt + " statuses indexed");
            }
        }

        LOG.info(String.format("Total of %s statuses added", cnt));

        if (cmdline.hasOption(OPTIMIZE_OPTION)) {
            LOG.info("Merging segments...");
            writer.forceMerge(1);
            LOG.info("Done!");
        }

        LOG.info("Total elapsed time: " + (System.currentTimeMillis() - startTime) + "ms");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        writer.close();
        dir.close();
        stream.close();
    }
}