Example usage for org.apache.commons.cli CommandLine getArgList

List of usage examples for org.apache.commons.cli CommandLine getArgList

Introduction

In this page you can find the example usage for org.apache.commons.cli CommandLine getArgList.

Prototype

public List getArgList() 

Source Link

Document

Retrieve any left-over non-recognized options and arguments

Usage

From source file:org.psystems.dicom.daemon.Repeater.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    CommandLine cl = parse(args);
    for (;;) {/*from  ww w  .  j av a 2s.c  o m*/
        Repeater dcmsnd = new Repeater(cl.hasOption("device") ? cl.getOptionValue("device") : "DCMSND");
        final List<String> argList = cl.getArgList();
        String remoteAE = argList.get(0);
        String[] calledAETAddress = split(remoteAE, '@');
        dcmsnd.setCalledAET(calledAETAddress[0]);
        if (calledAETAddress[1] == null) {
            dcmsnd.setRemoteHost("127.0.0.1");
            dcmsnd.setRemotePort(104);
        } else {
            String[] hostPort = split(calledAETAddress[1], ':');
            dcmsnd.setRemoteHost(hostPort[0]);
            dcmsnd.setRemotePort(toPort(hostPort[1]));
        }
        if (cl.hasOption("L")) {
            String localAE = cl.getOptionValue("L");
            String[] localPort = split(localAE, ':');
            if (localPort[1] != null) {
                dcmsnd.setLocalPort(toPort(localPort[1]));
            }
            String[] callingAETHost = split(localPort[0], '@');
            dcmsnd.setCalling(callingAETHost[0]);
            if (callingAETHost[1] != null) {
                dcmsnd.setLocalHost(callingAETHost[1]);
            }
        }
        dcmsnd.setOfferDefaultTransferSyntaxInSeparatePresentationContext(cl.hasOption("ts1"));
        dcmsnd.setSendFileRef(cl.hasOption("fileref"));
        if (cl.hasOption("username")) {
            String username = cl.getOptionValue("username");
            UserIdentity userId;
            if (cl.hasOption("passcode")) {
                String passcode = cl.getOptionValue("passcode");
                userId = new UserIdentity.UsernamePasscode(username, passcode.toCharArray());
            } else {
                userId = new UserIdentity.Username(username);
            }
            userId.setPositiveResponseRequested(cl.hasOption("uidnegrsp"));
            dcmsnd.setUserIdentity(userId);
        }
        dcmsnd.setStorageCommitment(cl.hasOption("stgcmt"));
        String remoteStgCmtAE = null;
        if (cl.hasOption("stgcmtae")) {
            try {
                remoteStgCmtAE = cl.getOptionValue("stgcmtae");
                String[] aet_hostport = split(remoteStgCmtAE, '@');
                String[] host_port = split(aet_hostport[1], ':');
                dcmsnd.setStgcmtCalledAET(aet_hostport[0]);
                dcmsnd.setRemoteStgcmtHost(host_port[0]);
                dcmsnd.setRemoteStgcmtPort(toPort(host_port[1]));
            } catch (Exception e) {
                exit("illegal argument of option -stgcmtae");
            }
        }
        if (cl.hasOption("connectTO"))
            dcmsnd.setConnectTimeout(parseInt(cl.getOptionValue("connectTO"),
                    "illegal argument of option -connectTO", 1, Integer.MAX_VALUE));
        if (cl.hasOption("reaper"))
            dcmsnd.setAssociationReaperPeriod(parseInt(cl.getOptionValue("reaper"),
                    "illegal argument of option -reaper", 1, Integer.MAX_VALUE));
        if (cl.hasOption("rspTO"))
            dcmsnd.setDimseRspTimeout(parseInt(cl.getOptionValue("rspTO"), "illegal argument of option -rspTO",
                    1, Integer.MAX_VALUE));
        if (cl.hasOption("acceptTO"))
            dcmsnd.setAcceptTimeout(parseInt(cl.getOptionValue("acceptTO"),
                    "illegal argument of option -acceptTO", 1, Integer.MAX_VALUE));
        if (cl.hasOption("releaseTO"))
            dcmsnd.setReleaseTimeout(parseInt(cl.getOptionValue("releaseTO"),
                    "illegal argument of option -releaseTO", 1, Integer.MAX_VALUE));
        if (cl.hasOption("soclosedelay"))
            dcmsnd.setSocketCloseDelay(parseInt(cl.getOptionValue("soclosedelay"),
                    "illegal argument of option -soclosedelay", 1, 10000));
        if (cl.hasOption("shutdowndelay"))
            dcmsnd.setShutdownDelay(parseInt(cl.getOptionValue("shutdowndelay"),
                    "illegal argument of option -shutdowndelay", 1, 10000));
        if (cl.hasOption("rcvpdulen"))
            dcmsnd.setMaxPDULengthReceive(
                    parseInt(cl.getOptionValue("rcvpdulen"), "illegal argument of option -rcvpdulen", 1, 10000)
                            * KB);
        if (cl.hasOption("sndpdulen"))
            dcmsnd.setMaxPDULengthSend(
                    parseInt(cl.getOptionValue("sndpdulen"), "illegal argument of option -sndpdulen", 1, 10000)
                            * KB);
        if (cl.hasOption("sosndbuf"))
            dcmsnd.setSendBufferSize(
                    parseInt(cl.getOptionValue("sosndbuf"), "illegal argument of option -sosndbuf", 1, 10000)
                            * KB);
        if (cl.hasOption("sorcvbuf"))
            dcmsnd.setReceiveBufferSize(
                    parseInt(cl.getOptionValue("sorcvbuf"), "illegal argument of option -sorcvbuf", 1, 10000)
                            * KB);
        if (cl.hasOption("bufsize"))
            dcmsnd.setTranscoderBufferSize(
                    parseInt(cl.getOptionValue("bufsize"), "illegal argument of option -bufsize", 1, 10000)
                            * KB);
        dcmsnd.setPackPDV(!cl.hasOption("pdv1"));
        dcmsnd.setTcpNoDelay(!cl.hasOption("tcpdelay"));
        if (cl.hasOption("async"))
            dcmsnd.setMaxOpsInvoked(
                    parseInt(cl.getOptionValue("async"), "illegal argument of option -async", 0, 0xffff));
        if (cl.hasOption("lowprior"))
            dcmsnd.setPriority(CommandUtils.LOW);
        if (cl.hasOption("highprior"))
            dcmsnd.setPriority(CommandUtils.HIGH);
        if (cl.hasOption("rescan"))
            dcmsnd.setRescanTimeout(parseInt(cl.getOptionValue("rescan"),
                    "illegal argument of option -releaseTO", 1, Integer.MAX_VALUE));

        //        System.out.println("Scanning files to send.");
        long t1 = System.currentTimeMillis();
        for (int i = 1, n = argList.size(); i < n; ++i)
            dcmsnd.addFile(new File(argList.get(i)));
        long t2 = System.currentTimeMillis();
        if (dcmsnd.getNumberOfFilesToSend() == 0) {
            //TODO  
            //           System.out.println("waiting new files "+RESCAN+" ms.");
            try {
                Thread.sleep(RESCAN);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            continue;
            //            System.exit(2);
        }
        System.out.println("\nScanned " + dcmsnd.getNumberOfFilesToSend() + " files in " + ((t2 - t1) / 1000F)
                + "s (=" + ((t2 - t1) / dcmsnd.getNumberOfFilesToSend()) + "ms/file)");
        dcmsnd.configureTransferCapability();
        if (cl.hasOption("tls")) {
            String cipher = cl.getOptionValue("tls");
            if ("NULL".equalsIgnoreCase(cipher)) {
                dcmsnd.setTlsWithoutEncyrption();
            } else if ("3DES".equalsIgnoreCase(cipher)) {
                dcmsnd.setTls3DES_EDE_CBC();
            } else if ("AES".equalsIgnoreCase(cipher)) {
                dcmsnd.setTlsAES_128_CBC();
            } else {
                exit("Invalid parameter for option -tls: " + cipher);
            }

            if (cl.hasOption("tls1")) {
                dcmsnd.setTlsProtocol(TLS1);
            } else if (cl.hasOption("ssl3")) {
                dcmsnd.setTlsProtocol(SSL3);
            } else if (cl.hasOption("no_tls1")) {
                dcmsnd.setTlsProtocol(NO_TLS1);
            } else if (cl.hasOption("no_ssl3")) {
                dcmsnd.setTlsProtocol(NO_SSL3);
            } else if (cl.hasOption("no_ssl2")) {
                dcmsnd.setTlsProtocol(NO_SSL2);
            }
            dcmsnd.setTlsNeedClientAuth(!cl.hasOption("noclientauth"));

            if (cl.hasOption("keystore")) {
                dcmsnd.setKeyStoreURL(cl.getOptionValue("keystore"));
            }
            if (cl.hasOption("keystorepw")) {
                dcmsnd.setKeyStorePassword(cl.getOptionValue("keystorepw"));
            }
            if (cl.hasOption("keypw")) {
                dcmsnd.setKeyPassword(cl.getOptionValue("keypw"));
            }
            if (cl.hasOption("truststore")) {
                dcmsnd.setTrustStoreURL(cl.getOptionValue("truststore"));
            }
            if (cl.hasOption("truststorepw")) {
                dcmsnd.setTrustStorePassword(cl.getOptionValue("truststorepw"));
            }
            try {
                dcmsnd.initTLS();
            } catch (Exception e) {
                System.err.println("ERROR: Failed to initialize TLS context:" + e.getMessage());
                System.exit(2);
            }
        }

        try {
            dcmsnd.start();
        } catch (Exception e) {
            System.err.println("ERROR: Failed to start server for receiving " + "Storage Commitment results:"
                    + e.getMessage());
            System.exit(2);
        }
        try {
            t1 = System.currentTimeMillis();
            try {
                dcmsnd.open();
            } catch (Exception e) {
                System.err.println("ERROR: Failed to establish association:" + e.getMessage());
                continue;
                //                System.exit(2);
            }
            t2 = System.currentTimeMillis();
            System.out.println("Connected to " + remoteAE + " in " + ((t2 - t1) / 1000F) + "s");

            t1 = System.currentTimeMillis();
            dcmsnd.send();
            t2 = System.currentTimeMillis();
            prompt(dcmsnd, (t2 - t1) / 1000F);
            if (dcmsnd.isStorageCommitment()) {
                t1 = System.currentTimeMillis();
                if (dcmsnd.commit()) {
                    t2 = System.currentTimeMillis();
                    System.out.println(
                            "Request Storage Commitment from " + remoteAE + " in " + ((t2 - t1) / 1000F) + "s");
                    System.out.println("Waiting for Storage Commitment Result..");
                    try {
                        DicomObject cmtrslt = dcmsnd.waitForStgCmtResult();
                        t1 = System.currentTimeMillis();
                        promptStgCmt(cmtrslt, ((t1 - t2) / 1000F));
                    } catch (InterruptedException e) {
                        System.err.println("ERROR:" + e.getMessage());
                    }
                }
            }
            dcmsnd.close();
            System.out.println("Released connection to " + remoteAE);
            if (remoteStgCmtAE != null) {
                t1 = System.currentTimeMillis();
                try {
                    dcmsnd.openToStgcmtAE();
                } catch (Exception e) {
                    System.err.println("ERROR: Failed to establish association:" + e.getMessage());
                    continue;
                    //                    System.exit(2);
                }
                t2 = System.currentTimeMillis();
                System.out.println("Connected to " + remoteStgCmtAE + " in " + ((t2 - t1) / 1000F) + "s");
                t1 = System.currentTimeMillis();
                if (dcmsnd.commit()) {
                    t2 = System.currentTimeMillis();
                    System.out.println("Request Storage Commitment from " + remoteStgCmtAE + " in "
                            + ((t2 - t1) / 1000F) + "s");
                    System.out.println("Waiting for Storage Commitment Result..");
                    try {
                        DicomObject cmtrslt = dcmsnd.waitForStgCmtResult();
                        t1 = System.currentTimeMillis();
                        promptStgCmt(cmtrslt, ((t1 - t2) / 1000F));
                    } catch (InterruptedException e) {
                        System.err.println("ERROR:" + e.getMessage());
                    }
                }
                dcmsnd.close();
                System.out.println("Released connection to " + remoteStgCmtAE);
            }
        } finally {
            dcmsnd.stop();
        }
    }

}

From source file:org.psystems.dicomweb.Dcm2Dcm.java

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    CommandLine cl = parse(args);
    Dcm2Dcm dcm2dcm = new Dcm2Dcm();
    dcm2dcm.setNoFileMetaInformation(cl.hasOption("no-fmi"));
    dcm2dcm.setTransferSyntax(transferSyntax(cl));
    if (cl.hasOption("buffer")) {
        dcm2dcm.setTranscoderBufferSize(
                parseInt(cl.getOptionValue("buffer"), "illegal argument of option --buffer", 1, 10000) * KB);
    }//w ww.  ja  v a 2  s.  co m
    if (cl.hasOption("s")) {
        dcm2dcm.overwriteObject = new BasicDicomObject();
        String[] matchingKeys = cl.getOptionValues("s");
        for (int i = 1; i < matchingKeys.length; i++, i++) {
            int[] tag = Tag.toTagPath(matchingKeys[i - 1]);
            String svalue = matchingKeys[i];
            //                System.out.println("TAG "+tag[0]+"="+svalue);
            dcm2dcm.overwriteObject.putString(tag, null, svalue);
        }

    }

    List<String> argList = (List<String>) cl.getArgList();
    int argc = argList.size();

    File dest = new File((String) argList.get(argc - 1));
    long t1 = System.currentTimeMillis();
    int count;
    if (dest.isDirectory()) {
        count = dcm2dcm.mconvert(argList, 0, dest);
    } else {
        File src = new File((String) argList.get(0));
        if (argc > 2 || src.isDirectory()) {
            exit("dcm2dcm: when converting several files, " + "last argument must be a directory\n");
        }
        count = dcm2dcm.mconvert(src, dest);
    }
    long t2 = System.currentTimeMillis();
    System.out.println("\nconverted " + count + " file(s) in " + (t2 - t1) / 1000f + " s.");
}

From source file:org.psystems.dicomweb.Dcm2DcmCopy.java

private static CommandLine parse(String[] args) {
    Options opts = new Options();

    opts.addOption(null, "no-fmi", false, "Encode result without File Meta Information. At default, "
            + " File Meta Information is included.");
    opts.addOption("e", "explicit", false, "Encode result with Explicit VR Little Endian Transfer Syntax. "
            + "At default, Implicit VR Little Endian is used.");
    opts.addOption("b", "big-endian", false, "Encode result with Explicit VR Big Endian Transfer Syntax. "
            + "At default, Implicit VR Little Endian is used.");
    opts.addOption("z", "deflated", false, "Encode result with Deflated Explicit VR Little Endian Syntax. "
            + "At default, Implicit VR Little Endian is used.");

    OptionBuilder.withArgName("[seq/]attr=value");
    OptionBuilder.hasArgs(2);/*from  w  w  w. ja  v a  2  s  .  c o m*/
    OptionBuilder.withValueSeparator('=');
    OptionBuilder.withDescription(
            "specify value to set in the output stream.  Currently only works when transcoding images.");
    opts.addOption(OptionBuilder.create("s"));

    opts.addOption("t", "syntax", true,
            "Encode result with the specified transfer syntax - recodes" + " the image typically.");

    OptionBuilder.withArgName("KB");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("transcoder buffer size in KB, 1KB by default");
    OptionBuilder.withLongOpt("buffer");
    opts.addOption(OptionBuilder.create(null));

    opts.addOption("h", "help", false, "print this message");
    opts.addOption("V", "version", false, "print the version information and exit");
    CommandLine cl = null;
    try {
        cl = new PosixParser().parse(opts, args);
    } catch (ParseException e) {
        exit("dcm2dcm: " + e.getMessage());
        throw new RuntimeException("unreachable");
    }
    if (cl.hasOption('V')) {
        Package p = Dcm2DcmCopy.class.getPackage();
        System.out.println("dcm2dcm v" + p.getImplementationVersion());
        System.exit(0);
    }
    if (cl.hasOption('h') || cl.getArgList().size() < 2) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(USAGE, DESCRIPTION, opts, EXAMPLE);
        System.exit(0);
    }
    return cl;
}

From source file:org.psystems.dicomweb.Dcm2DcmCopy.java

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    CommandLine cl = parse(args);
    Dcm2DcmCopy dcm2dcm = new Dcm2DcmCopy();
    dcm2dcm.setNoFileMetaInformation(cl.hasOption("no-fmi"));
    dcm2dcm.setTransferSyntax(transferSyntax(cl));
    if (cl.hasOption("buffer")) {
        dcm2dcm.setTranscoderBufferSize(
                parseInt(cl.getOptionValue("buffer"), "illegal argument of option --buffer", 1, 10000) * KB);
    }//from  w  w w .j av a 2s .co  m
    if (cl.hasOption("s")) {
        dcm2dcm.overwriteObject = new BasicDicomObject();
        String[] matchingKeys = cl.getOptionValues("s");
        for (int i = 1; i < matchingKeys.length; i++, i++) {
            int[] tag = Tag.toTagPath(matchingKeys[i - 1]);
            String svalue = matchingKeys[i];
            dcm2dcm.overwriteObject.putString(tag, null, svalue);
        }

    }

    List<String> argList = (List<String>) cl.getArgList();
    int argc = argList.size();

    File dest = new File((String) argList.get(argc - 1));
    long t1 = System.currentTimeMillis();
    int count;
    if (dest.isDirectory()) {
        count = dcm2dcm.mconvert(argList, 0, dest);
    } else {
        File src = new File((String) argList.get(0));
        if (argc > 2 || src.isDirectory()) {
            exit("dcm2dcm: when converting several files, " + "last argument must be a directory\n");
        }

        count = dcm2dcm.mconvert(src, dest);
    }
    long t2 = System.currentTimeMillis();
    System.out.println("\nconverted " + count + " file(s) in " + (t2 - t1) / 1000f + " s.");
}

From source file:org.psystems.dicomweb.Dcm2DcmOld.java

private static CommandLine parse(String[] args) {
    Options opts = new Options();

    opts.addOption(null, "no-fmi", false, "Encode result without File Meta Information. At default, "
            + " File Meta Information is included.");
    opts.addOption("e", "explicit", false, "Encode result with Explicit VR Little Endian Transfer Syntax. "
            + "At default, Implicit VR Little Endian is used.");
    opts.addOption("b", "big-endian", false, "Encode result with Explicit VR Big Endian Transfer Syntax. "
            + "At default, Implicit VR Little Endian is used.");
    opts.addOption("z", "deflated", false, "Encode result with Deflated Explicit VR Little Endian Syntax. "
            + "At default, Implicit VR Little Endian is used.");

    OptionBuilder.withArgName("[seq/]attr=value");
    OptionBuilder.hasArgs(2);/*from  w w  w.j  av a  2  s  .c om*/
    OptionBuilder.withValueSeparator('=');
    OptionBuilder.withDescription(
            "specify value to set in the output stream.  Currently only works when transcoding images.");
    opts.addOption(OptionBuilder.create("s"));

    opts.addOption("t", "syntax", true,
            "Encode result with the specified transfer syntax - recodes" + " the image typically.");

    OptionBuilder.withArgName("KB");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("transcoder buffer size in KB, 1KB by default");
    OptionBuilder.withLongOpt("buffer");
    opts.addOption(OptionBuilder.create(null));

    opts.addOption("h", "help", false, "print this message");
    opts.addOption("V", "version", false, "print the version information and exit");
    CommandLine cl = null;
    try {
        cl = new PosixParser().parse(opts, args);
    } catch (ParseException e) {
        exit("dcm2dcm: " + e.getMessage());
        throw new RuntimeException("unreachable");
    }
    if (cl.hasOption('V')) {
        Package p = Dcm2DcmOld.class.getPackage();
        System.out.println("dcm2dcm v" + p.getImplementationVersion());
        System.exit(0);
    }
    if (cl.hasOption('h') || cl.getArgList().size() < 2) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(USAGE, DESCRIPTION, opts, EXAMPLE);
        System.exit(0);
    }
    return cl;
}

From source file:org.psystems.dicomweb.Dcm2DcmOld.java

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    CommandLine cl = parse(args);
    Dcm2DcmOld dcm2dcm = new Dcm2DcmOld();
    dcm2dcm.setNoFileMetaInformation(cl.hasOption("no-fmi"));
    dcm2dcm.setTransferSyntax(transferSyntax(cl));
    if (cl.hasOption("buffer")) {
        dcm2dcm.setTranscoderBufferSize(
                parseInt(cl.getOptionValue("buffer"), "illegal argument of option --buffer", 1, 10000) * KB);
    }/*from   w ww  . j a v  a  2  s.  c  om*/
    if (cl.hasOption("s")) {
        dcm2dcm.overwriteObject = new BasicDicomObject();
        String[] matchingKeys = cl.getOptionValues("s");
        for (int i = 1; i < matchingKeys.length; i++, i++) {
            int[] tag = Tag.toTagPath(matchingKeys[i - 1]);
            String svalue = matchingKeys[i];
            dcm2dcm.overwriteObject.putString(tag, null, svalue);
        }

    }

    List<String> argList = (List<String>) cl.getArgList();
    int argc = argList.size();

    File dest = new File((String) argList.get(argc - 1));
    long t1 = System.currentTimeMillis();
    int count;
    if (dest.isDirectory()) {
        count = dcm2dcm.mconvert(argList, 0, dest);
    } else {
        File src = new File((String) argList.get(0));
        if (argc > 2 || src.isDirectory()) {
            exit("dcm2dcm: when converting several files, " + "last argument must be a directory\n");
        }

        count = dcm2dcm.mconvert(src, dest);
    }
    long t2 = System.currentTimeMillis();
    System.out.println("\nconverted " + count + " file(s) in " + (t2 - t1) / 1000f + " s.");
}

From source file:org.psystems.dicomweb.DcmRcv.java

private static CommandLine parse(String[] args) {
    Options opts = new Options();

    OptionBuilder.withArgName("name");
    OptionBuilder.hasArg();/*from w  w  w.ja  v a  2  s .  co m*/
    OptionBuilder.withDescription("set device name, use DCMRCV by default");
    opts.addOption(OptionBuilder.create("device"));

    OptionBuilder.withArgName("NULL|3DES|AES");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("enable TLS connection without, 3DES or AES encryption");
    opts.addOption(OptionBuilder.create("tls"));

    OptionGroup tlsProtocol = new OptionGroup();
    tlsProtocol.addOption(new Option("tls1", "disable the use of SSLv3 and SSLv2 for TLS connections"));
    tlsProtocol.addOption(new Option("ssl3", "disable the use of TLSv1 and SSLv2 for TLS connections"));
    tlsProtocol.addOption(new Option("no_tls1", "disable the use of TLSv1 for TLS connections"));
    tlsProtocol.addOption(new Option("no_ssl3", "disable the use of SSLv3 for TLS connections"));
    tlsProtocol.addOption(new Option("no_ssl2", "disable the use of SSLv2 for TLS connections"));
    opts.addOptionGroup(tlsProtocol);

    opts.addOption("noclientauth", false, "disable client authentification for TLS");

    OptionBuilder.withArgName("file|url");
    OptionBuilder.hasArg();
    OptionBuilder
            .withDescription("file path or URL of P12 or JKS keystore, resource:tls/test_sys_2.p12 by default");
    opts.addOption(OptionBuilder.create("keystore"));

    OptionBuilder.withArgName("password");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("password for keystore file, 'secret' by default");
    opts.addOption(OptionBuilder.create("keystorepw"));

    OptionBuilder.withArgName("password");
    OptionBuilder.hasArg();
    OptionBuilder
            .withDescription("password for accessing the key in the keystore, keystore password by default");
    opts.addOption(OptionBuilder.create("keypw"));

    OptionBuilder.withArgName("file|url");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("file path or URL of JKS truststore, resource:tls/mesa_certs.jks by default");
    opts.addOption(OptionBuilder.create("truststore"));

    OptionBuilder.withArgName("password");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("password for truststore file, 'secret' by default");
    opts.addOption(OptionBuilder.create("truststorepw"));

    OptionBuilder.withArgName("dir");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("store received objects into files in specified directory <dir>."
            + " Do not store received objects by default.");
    opts.addOption(OptionBuilder.create("dest"));

    OptionBuilder.withArgName("file|url");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("file path or URL of properties for mapping Calling AETs to "
            + "sub-directories of the storage directory specified by "
            + "-dest, to separate the storage location dependend on " + "Calling AETs.");
    opts.addOption(OptionBuilder.create("calling2dir"));

    OptionBuilder.withArgName("file|url");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("file path or URL of properties for mapping Called AETs to "
            + "sub-directories of the storage directory specified by "
            + "-dest, to separate the storage location dependend on " + "Called AETs.");
    opts.addOption(OptionBuilder.create("called2dir"));

    OptionBuilder.withArgName("sub-dir");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("storage sub-directory used for Calling AETs for which no "
            + " mapping is defined by properties specified by " + "-calling2dir, 'OTHER' by default.");
    opts.addOption(OptionBuilder.create("callingdefdir"));

    OptionBuilder.withArgName("sub-dir");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("storage sub-directory used for Called AETs for which no "
            + " mapping is defined by properties specified by " + "-called2dir, 'OTHER' by default.");
    opts.addOption(OptionBuilder.create("calleddefdir"));

    OptionBuilder.withArgName("dir");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("register stored objects in cache journal files in specified directory <dir>."
            + " Do not register stored objects by default.");
    opts.addOption(OptionBuilder.create("journal"));

    OptionBuilder.withArgName("pattern");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("cache journal file path, with "
            + "'yyyy' will be replaced by the current year, "
            + "'MM' by the current month, 'dd' by the current date, "
            + "'HH' by the current hour and 'mm' by the current minute. " + "'yyyy/MM/dd/HH/mm' by default.");
    opts.addOption(OptionBuilder.create("journalfilepath"));

    opts.addOption("defts", false, "accept only default transfer syntax.");
    opts.addOption("bigendian", false, "accept also Explict VR Big Endian transfer syntax.");
    opts.addOption("native", false, "accept only transfer syntax with uncompressed pixel data.");

    OptionBuilder.withArgName("maxops");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "maximum number of outstanding operations performed " + "asynchronously, unlimited by default.");
    opts.addOption(OptionBuilder.create("async"));

    opts.addOption("pdv1", false, "send only one PDV in one P-Data-TF PDU, "
            + "pack command and data PDV in one P-DATA-TF PDU by default.");
    opts.addOption("tcpdelay", false, "set TCP_NODELAY socket option to false, true by default");

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("delay in ms for Socket close after sending A-ABORT, 50ms by default");
    opts.addOption(OptionBuilder.create("soclosedelay"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("delay in ms for DIMSE-RSP; useful for testing asynchronous mode");
    opts.addOption(OptionBuilder.create("rspdelay"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("timeout in ms for receiving -ASSOCIATE-RQ, 5s by default");
    opts.addOption(OptionBuilder.create("requestTO"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("timeout in ms for receiving A-RELEASE-RP, 5s by default");
    opts.addOption(OptionBuilder.create("releaseTO"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("period in ms to check for outstanding DIMSE-RSP, 10s by default");
    opts.addOption(OptionBuilder.create("reaper"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("timeout in ms for receiving DIMSE-RQ, 60s by default");
    opts.addOption(OptionBuilder.create("idleTO"));

    OptionBuilder.withArgName("KB");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("maximal length in KB of received P-DATA-TF PDUs, 16KB by default");
    opts.addOption(OptionBuilder.create("rcvpdulen"));

    OptionBuilder.withArgName("KB");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("maximal length in KB of sent P-DATA-TF PDUs, 16KB by default");
    opts.addOption(OptionBuilder.create("sndpdulen"));

    OptionBuilder.withArgName("KB");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("set SO_RCVBUF socket option to specified value in KB");
    opts.addOption(OptionBuilder.create("sorcvbuf"));

    OptionBuilder.withArgName("KB");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("set SO_SNDBUF socket option to specified value in KB");
    opts.addOption(OptionBuilder.create("sosndbuf"));

    OptionBuilder.withArgName("KB");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("minimal buffer size to write received object to file, 1KB by default");
    opts.addOption(OptionBuilder.create("bufsize"));

    opts.addOption("h", "help", false, "print this message");
    opts.addOption("V", "version", false, "print the version information and exit");
    CommandLine cl = null;
    try {
        cl = new GnuParser().parse(opts, args);
    } catch (ParseException e) {
        exit("dcmrcv: " + e.getMessage());
        throw new RuntimeException("unreachable");
    }
    if (cl.hasOption("V")) {
        Package p = DcmRcv.class.getPackage();
        System.out.println("dcmrcv v" + p.getImplementationVersion());
        System.exit(0);
    }
    if (cl.hasOption("h") || cl.getArgList().size() == 0) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(USAGE, DESCRIPTION, opts, EXAMPLE);
        System.exit(0);
    }
    return cl;
}

From source file:org.psystems.dicomweb.DcmRcv.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    CommandLine cl = parse(args);
    DcmRcv dcmrcv = new DcmRcv(cl.hasOption("device") ? cl.getOptionValue("device") : "DCMRCV");
    final List<String> argList = cl.getArgList();
    String port = argList.get(0);
    String[] aetPort = split(port, ':', 1);
    dcmrcv.setPort(parseInt(aetPort[1], "illegal port number", 1, 0xffff));
    if (aetPort[0] != null) {
        String[] aetHost = split(aetPort[0], '@', 0);
        dcmrcv.setAEtitle(aetHost[0]);//from   w w  w .ja v  a  2 s  .  c  o m
        if (aetHost[1] != null) {
            dcmrcv.setHostname(aetHost[1]);
        }
    }

    if (cl.hasOption("dest"))
        dcmrcv.setDestination(cl.getOptionValue("dest"));
    if (cl.hasOption("calling2dir"))
        dcmrcv.setCalling2Dir(loadProperties(cl.getOptionValue("calling2dir")));
    if (cl.hasOption("called2dir"))
        dcmrcv.setCalled2Dir(loadProperties(cl.getOptionValue("called2dir")));
    if (cl.hasOption("callingdefdir"))
        dcmrcv.setCallingDefDir(cl.getOptionValue("callingdefdir"));
    if (cl.hasOption("calleddefdir"))
        dcmrcv.setCalledDefDir(cl.getOptionValue("calleddefdir"));
    if (cl.hasOption("journal"))
        dcmrcv.setJournal(cl.getOptionValue("journal"));
    if (cl.hasOption("journalfilepath"))
        dcmrcv.setJournalFilePathFormat(cl.getOptionValue("journalfilepath"));

    if (cl.hasOption("defts"))
        dcmrcv.setTransferSyntax(ONLY_DEF_TS);
    else if (cl.hasOption("native"))
        dcmrcv.setTransferSyntax(cl.hasOption("bigendian") ? NATIVE_TS : NATIVE_LE_TS);
    else if (cl.hasOption("bigendian"))
        dcmrcv.setTransferSyntax(NON_RETIRED_TS);
    if (cl.hasOption("reaper"))
        dcmrcv.setAssociationReaperPeriod(parseInt(cl.getOptionValue("reaper"),
                "illegal argument of option -reaper", 1, Integer.MAX_VALUE));
    if (cl.hasOption("idleTO"))
        dcmrcv.setIdleTimeout(parseInt(cl.getOptionValue("idleTO"), "illegal argument of option -idleTO", 1,
                Integer.MAX_VALUE));
    if (cl.hasOption("requestTO"))
        dcmrcv.setRequestTimeout(parseInt(cl.getOptionValue("requestTO"),
                "illegal argument of option -requestTO", 1, Integer.MAX_VALUE));
    if (cl.hasOption("releaseTO"))
        dcmrcv.setReleaseTimeout(parseInt(cl.getOptionValue("releaseTO"),
                "illegal argument of option -releaseTO", 1, Integer.MAX_VALUE));
    if (cl.hasOption("soclosedelay"))
        dcmrcv.setSocketCloseDelay(parseInt(cl.getOptionValue("soclosedelay"),
                "illegal argument of option -soclosedelay", 1, 10000));
    if (cl.hasOption("rspdelay"))
        dcmrcv.setDimseRspDelay(
                parseInt(cl.getOptionValue("rspdelay"), "illegal argument of option -rspdelay", 0, 10000));
    if (cl.hasOption("rcvpdulen"))
        dcmrcv.setMaxPDULengthReceive(
                parseInt(cl.getOptionValue("rcvpdulen"), "illegal argument of option -rcvpdulen", 1, 10000)
                        * KB);
    if (cl.hasOption("sndpdulen"))
        dcmrcv.setMaxPDULengthSend(
                parseInt(cl.getOptionValue("sndpdulen"), "illegal argument of option -sndpdulen", 1, 10000)
                        * KB);
    if (cl.hasOption("sosndbuf"))
        dcmrcv.setSendBufferSize(
                parseInt(cl.getOptionValue("sosndbuf"), "illegal argument of option -sosndbuf", 1, 10000) * KB);
    if (cl.hasOption("sorcvbuf"))
        dcmrcv.setReceiveBufferSize(
                parseInt(cl.getOptionValue("sorcvbuf"), "illegal argument of option -sorcvbuf", 1, 10000) * KB);
    if (cl.hasOption("bufsize"))
        dcmrcv.setFileBufferSize(
                parseInt(cl.getOptionValue("bufsize"), "illegal argument of option -bufsize", 1, 10000) * KB);

    dcmrcv.setPackPDV(!cl.hasOption("pdv1"));
    dcmrcv.setTcpNoDelay(!cl.hasOption("tcpdelay"));
    if (cl.hasOption("async"))
        dcmrcv.setMaxOpsPerformed(
                parseInt(cl.getOptionValue("async"), "illegal argument of option -async", 0, 0xffff));
    dcmrcv.initTransferCapability();
    if (cl.hasOption("tls")) {
        String cipher = cl.getOptionValue("tls");
        if ("NULL".equalsIgnoreCase(cipher)) {
            dcmrcv.setTlsWithoutEncyrption();
        } else if ("3DES".equalsIgnoreCase(cipher)) {
            dcmrcv.setTls3DES_EDE_CBC();
        } else if ("AES".equalsIgnoreCase(cipher)) {
            dcmrcv.setTlsAES_128_CBC();
        } else {
            exit("Invalid parameter for option -tls: " + cipher);
        }
        if (cl.hasOption("tls1")) {
            dcmrcv.setTlsProtocol(TLS1);
        } else if (cl.hasOption("ssl3")) {
            dcmrcv.setTlsProtocol(SSL3);
        } else if (cl.hasOption("no_tls1")) {
            dcmrcv.setTlsProtocol(NO_TLS1);
        } else if (cl.hasOption("no_ssl3")) {
            dcmrcv.setTlsProtocol(NO_SSL3);
        } else if (cl.hasOption("no_ssl2")) {
            dcmrcv.setTlsProtocol(NO_SSL2);
        }
        dcmrcv.setTlsNeedClientAuth(!cl.hasOption("noclientauth"));

        if (cl.hasOption("keystore")) {
            dcmrcv.setKeyStoreURL(cl.getOptionValue("keystore"));
        }
        if (cl.hasOption("keystorepw")) {
            dcmrcv.setKeyStorePassword(cl.getOptionValue("keystorepw"));
        }
        if (cl.hasOption("keypw")) {
            dcmrcv.setKeyPassword(cl.getOptionValue("keypw"));
        }
        if (cl.hasOption("truststore")) {
            dcmrcv.setTrustStoreURL(cl.getOptionValue("truststore"));
        }
        if (cl.hasOption("truststorepw")) {
            dcmrcv.setTrustStorePassword(cl.getOptionValue("truststorepw"));
        }
        try {
            dcmrcv.initTLS();
        } catch (Exception e) {
            System.err.println("ERROR: Failed to initialize TLS context:" + e.getMessage());
            System.exit(2);
        }
    }
    try {
        dcmrcv.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.raml.jaxrs.ramltojaxrs.Main.java

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

    Options options = new Options();
    options.addOption("m", "model-package", true, "model package");
    options.addOption("s", "support-package", true, "support package");
    options.addOption(//from w w w.j  a va2s . c o m
            Option.builder("r").longOpt("resource-package").hasArg().desc("resource package").build());
    options.addOption("g", "generate-types-with", true,
            "generate types with plugins (jackson, gson, jaxb, javadoc, jsr303)");
    options.addOption(
            Option.builder("d").required().longOpt("directory").hasArg().desc("generation directory").build());

    try {

        CommandLineParser parser = new DefaultParser();
        CommandLine command = parser.parse(options, args);
        String modelDir = command.getOptionValue("m");
        String supportDir = command.getOptionValue("s");
        String resourceDir = command.getOptionValue("r");
        String directory = command.getOptionValue("d");
        String extensions = command.getOptionValue("e");

        List<String> ramlFiles = command.getArgList();

        Configuration configuration = new Configuration();
        configuration.setModelPackage(modelDir);
        configuration.setResourcePackage(resourceDir);
        configuration.setSupportPackage(supportDir);
        configuration.setOutputDirectory(new File(directory));

        if (extensions != null) {
            configuration.setTypeConfiguration(extensions.split(("\\s*,\\s*")));
        }

        RamlScanner scanner = new RamlScanner(configuration);

        for (String ramlFile : ramlFiles) {

            scanner.handle(new File(ramlFile));
        }

    } catch (ParseException e) {

        HelpFormatter formatter = new HelpFormatter();
        System.err.println(e.getMessage());
        formatter.printHelp("ramltojaxrs", options, true);
    }

    System.getProperties().remove("ramltojaxrs");
}

From source file:org.rhq.server.control.ControlCommand.java

public int exec(String[] args) {
    Options options = getOptions();/*from   w  w w  . j  a  v  a2 s . com*/
    int rValue = RHQControl.EXIT_CODE_OK;
    try {
        CommandLineParser parser = new RHQPosixParser(false);
        CommandLine cmdLine = parser.parse(options, args, true);
        if (!cmdLine.getArgList().isEmpty()) {
            // there were some unrecognized args
            System.out.println("Unrecognized arguments: " + cmdLine.getArgList());
            printUsage();
            return RHQControl.EXIT_CODE_INVALID_ARGUMENT;
        }
        rValue = exec(cmdLine);

        if (rhqctlConfig != null) {
            rhqctlConfig.save();
        }
    } catch (ParseException e) {
        printUsage();
        rValue = RHQControl.EXIT_CODE_INVALID_ARGUMENT;
    } catch (ConfigurationException e) {
        throw new RHQControlException("Failed to update " + getRhqCtlProperties(), e);
    }
    return rValue;
}