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.pshdl.model.simulation.PStoEXCompiler.java

@Override
public String invoke(CommandLine cli) throws Exception {
    @SuppressWarnings("unchecked")
    final List<String> argList = cli.getArgList();
    if (argList.size() == 0) {
        getUsage().printHelp(System.out);
        return "Missing module and file arguments";
    }//from www  .j  a v  a 2  s . co m
    if (argList.size() == 1) {
        getUsage().printHelp(System.out);
        return "Missing file arguments";
    }
    final HDLQualifiedName unitName = new HDLQualifiedName(argList.get(0));
    System.out.println("Using module:\t" + unitName);
    final List<File> files = Lists.newLinkedList();
    final String type = cli.getOptionValue("type");
    if ((type != null) && !providers.containsKey(type.toLowerCase()))
        return "Invalid type argument, no such type " + type;
    System.out.println("Parsing files:");
    for (int i = 1; i < argList.size(); i++) {
        final File source = new File(argList.get(i));
        System.out.println("\t" + source.getAbsolutePath());
        if (!source.exists())
            return "The file: " + source + " can not be found";
        files.add(source);
    }
    if (addFiles(files))
        return "Exiting because of syntax errors in the input";
    System.out.println("Validating:");
    if (validatePackages())
        return "Exiting because of errors in the input";
    final HDLUnit unit = findUnit(unitName);
    if (unit == null)
        return "Unit: " + unitName + " not found";
    final String src = unit.getLibrary().getSrc(unitName);
    String outDir = cli.getOptionValue("outputDir");
    if (outDir == null) {
        outDir = "src-gen/psex";
    }
    final File dir = new File(outDir);
    if (!dir.exists()) {
        System.out.println("Output directory " + dir + " does not exist, creating it");
        if (!dir.mkdirs())
            throw new IllegalArgumentException("Failed to create direcory:" + dir);
    }
    final ExecutableModel em = createExecutable(unit, src, cli.hasOption("ir"), !cli.hasOption("allSignals"));
    if (cli.hasOption("em")) {
        IOUtil.writeExecutableModel(System.currentTimeMillis(), em, new File(dir, unitName.toString() + ".em"));
    }
    if (type != null) {
        final ITypeOuptutProvider ito = providers.get(type.toLowerCase());
        final List<CompileResult> results = ito.invoke(cli, em, null);
        for (final CompileResult cr : results) {
            writeFiles(dir, cr);
        }
    }
    return null;
}

From source file:org.psidnell.omnifocus.cli.ActiveOptionProcessor.java

public boolean processOptions(P program, String[] args, int phase) throws Exception {

    CommandLineParser parser = new FixedParser();
    CommandLine cl = parser.parse(options, args);

    // If there are unrecognised options then stop
    @SuppressWarnings("unchecked")
    List<String> unrecognized = cl.getArgList();
    if (!unrecognized.isEmpty()) {
        if (!unrecognized.isEmpty()) {
            System.out.println("Unrecognised command line arguments: " + unrecognized);
        }/*from w w  w  .  j a  va  2  s .c o m*/
        printHelp();
        return false;
    }

    // Set the option values on the options
    for (Object o : options.getOptions()) {
        @SuppressWarnings("unchecked")
        ActiveOption<P> opt = (ActiveOption<P>) o;
        opt.setValues(cl.getOptionValues(opt.getOpt()));
    }

    // Walk through the options processing in order
    for (Object o : cl.getOptions()) {
        @SuppressWarnings("unchecked")
        ActiveOption<P> opt = (ActiveOption<P>) o;
        if (opt.getPhase() == phase) {
            opt.process(program);
        }
    }

    return true;
}

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

@SuppressWarnings("unchecked")
public static void main(String args[]) throws Exception {
    CommandLine cl = parse(args);
    Dcm2Jpg dcm2jpg = new Dcm2Jpg();
    if (cl.hasOption("f")) {
        dcm2jpg.setFrameNumber(/* w  ww. j a v  a 2  s . c  o m*/
                parseInt(cl.getOptionValue("f"), "illegal argument of option -f", 1, Integer.MAX_VALUE));
    }
    if (cl.hasOption("p")) {
        dcm2jpg.setPresentationState(loadDicomObject(new File(cl.getOptionValue("p"))));
    }
    if (cl.hasOption("pv2gray")) {
        dcm2jpg.setPValue2Gray(loadPVal2Gray(new File(cl.getOptionValue("pv2gray"))));
    }
    if (cl.hasOption("c")) {
        dcm2jpg.setWindowCenter(parseFloat(cl.getOptionValue("c"), "illegal argument of option -c"));
    }
    if (cl.hasOption("w")) {
        dcm2jpg.setWindowWidth(parseFloat(cl.getOptionValue("w"), "illegal argument of option -w"));
    }
    if (cl.hasOption("sigmoid")) {
        dcm2jpg.setVoiLutFunction(DicomImageReadParam.SIGMOID);
    }
    dcm2jpg.setAutoWindowing(!cl.hasOption("noauto"));
    if (cl.hasOption("jpgext")) {
        dcm2jpg.setFileExt(cl.getOptionValue("jpgext"));
    }
    final List<String> argList = cl.getArgList();
    int argc = argList.size();

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

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

private static CommandLine parse(String[] args) {
    Options opts = new Options();
    OptionBuilder.withArgName("frame");
    OptionBuilder.hasArg();/*from   ww w  .  ja  v  a 2s .c  om*/
    OptionBuilder.withDescription("frame to convert, 1 (= first frame) by default");
    opts.addOption(OptionBuilder.create("f"));
    OptionBuilder.withArgName("prfile");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("file path of presentation state to apply");
    opts.addOption(OptionBuilder.create("p"));
    OptionBuilder.withArgName("center");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Window Center");
    opts.addOption(OptionBuilder.create("c"));
    OptionBuilder.withArgName("width");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Window Width");
    opts.addOption(OptionBuilder.create("w"));
    opts.addOption("sigmoid", false, "apply sigmoid VOI LUT function with given Window Center/Width");
    opts.addOption("noauto", false, "disable auto-windowing for images w/o VOI attributes");
    OptionBuilder.withArgName("file");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("file path of P-Value to gray value map");
    opts.addOption(OptionBuilder.create("pv2gray"));
    OptionBuilder.withArgName(".xxx");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "jpeg file extension used with destination directory argument," + " default: '.jpg'.");
    opts.addOption(OptionBuilder.create("jpgext"));
    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("dcm2jpg: " + e.getMessage());
        throw new RuntimeException("unreachable");
    }
    if (cl.hasOption('V')) {
        Package p = Dcm2Jpg.class.getPackage();
        System.out.println("dcm2jpg 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.dicom.daemon.DcmRcvOriginal.java

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

    OptionBuilder.withArgName("name");
    OptionBuilder.hasArg();// w w  w.  j ava  2  s .c om
    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 = DcmRcvOriginal.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.dicom.daemon.DcmRcvOriginal.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    CommandLine cl = parse(args);
    DcmRcvOriginal dcmrcv = new DcmRcvOriginal(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]);/*  ww w .ja va 2s .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.psystems.dicom.daemon.DcmSnd.java

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

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

    OptionBuilder.withArgName("aet[@host][:port]");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("set AET, local address and listening port of local "
            + "Application Entity, use device name and pick up any valid "
            + "local address to bind the socket by default");
    opts.addOption(OptionBuilder.create("L"));

    opts.addOption("ts1", false,
            "offer Default Transfer Syntax in " + "separate Presentation Context. By default offered with "
                    + "Explicit VR Little Endian TS in one PC.");

    opts.addOption("fileref", false,
            "send objects without pixel data, but with a reference to "
                    + "the DICOM file using DCM4CHE URI Referenced Transfer Syntax "
                    + "to import DICOM objects on a given file system to a DCM4CHEE " + "archive.");

    OptionBuilder.withArgName("username");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "enable User Identity Negotiation with specified username and " + " optional passcode");
    opts.addOption(OptionBuilder.create("username"));

    OptionBuilder.withArgName("passcode");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "optional passcode for User Identity Negotiation, " + "only effective with option -username");
    opts.addOption(OptionBuilder.create("passcode"));

    opts.addOption("uidnegrsp", false,
            "request positive User Identity Negotation response, " + "only effective with option -username");

    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("aet@host:port");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("request storage commitment of (successfully) sent objects "
            + "afterwards in new association to specified remote " + "Application Entity");
    opts.addOption(OptionBuilder.create("stgcmtae"));

    opts.addOption("stgcmt", false,
            "request storage commitment of (successfully) sent objects " + "afterwards in same association");

    OptionBuilder.withArgName("maxops");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("maximum number of outstanding operations it may invoke "
            + "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("timeout in ms for TCP connect, no timeout by default");
    opts.addOption(OptionBuilder.create("connectTO"));

    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 closing the listening socket, " + "1000ms by default");
    opts.addOption(OptionBuilder.create("shutdowndelay"));

    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-RSP, 10s by default");
    opts.addOption(OptionBuilder.create("rspTO"));

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

    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("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("transcoder buffer size in KB, 1KB by default");
    opts.addOption(OptionBuilder.create("bufsize"));

    opts.addOption("lowprior", false, "LOW priority of the C-STORE operation, MEDIUM by default");
    opts.addOption("highprior", false, "HIGH priority of the C-STORE operation, MEDIUM by default");
    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("dcmsnd: " + e.getMessage());
        throw new RuntimeException("unreachable");
    }
    if (cl.hasOption('V')) {
        Package p = DcmSnd.class.getPackage();
        System.out.println("dcmsnd 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.dicom.daemon.DcmSnd.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    CommandLine cl = parse(args);
    DcmSnd dcmsnd = new DcmSnd(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);//from   w  w  w  .j  av a 2 s .c  o m
    } 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);
    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) {
        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());
            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());
                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.dicom.daemon.Jpg2Dcm.java

public static void main(String[] args) {
    try {//from w  w w .  ja  va 2  s  .c om
        CommandLine cl = parse(args);
        Jpg2Dcm jpg2Dcm = new Jpg2Dcm();
        if (cl.hasOption(LONG_OPT_CHARSET)) {
            jpg2Dcm.setCharset(cl.getOptionValue(LONG_OPT_CHARSET));
        }
        if (cl.hasOption("c")) {
            jpg2Dcm.loadConfiguration(new File(cl.getOptionValue("c")), true);
        }
        if (cl.hasOption("C")) {
            jpg2Dcm.loadConfiguration(new File(cl.getOptionValue("C")), false);
        }
        if (cl.hasOption(LONG_OPT_UID_PREFIX)) {
            UIDUtils.setRoot(cl.getOptionValue(LONG_OPT_UID_PREFIX));
        }
        if (cl.hasOption(LONG_OPT_MPEG)) {
            jpg2Dcm.setTransferSyntax(UID.MPEG2);
        }
        if (cl.hasOption(LONG_OPT_TRANSFER_SYNTAX)) {
            jpg2Dcm.setTransferSyntax(cl.getOptionValue(LONG_OPT_TRANSFER_SYNTAX));
        }
        jpg2Dcm.setNoAPPn(cl.hasOption(LONG_OPT_NO_APPN));

        List argList = cl.getArgList();
        File jpgFile = new File((String) argList.get(0));
        File dcmFile = new File((String) argList.get(1));
        long start = System.currentTimeMillis();
        jpg2Dcm.convert(jpgFile, dcmFile);
        long fin = System.currentTimeMillis();
        System.out.println("Encapsulated " + jpgFile + " to " + dcmFile + " in " + (fin - start) + "ms.");
    } catch (IOException e) {
        e.printStackTrace();
    }
}

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

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

    OptionBuilder.withArgName("name");
    OptionBuilder.hasArg();//from www  .  j av a 2  s.  co  m
    OptionBuilder.withDescription("set device name, use DCMSND by default");
    opts.addOption(OptionBuilder.create("device"));

    OptionBuilder.withArgName("aet[@host][:port]");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("set AET, local address and listening port of local "
            + "Application Entity, use device name and pick up any valid "
            + "local address to bind the socket by default");
    opts.addOption(OptionBuilder.create("L"));

    opts.addOption("ts1", false,
            "offer Default Transfer Syntax in " + "separate Presentation Context. By default offered with "
                    + "Explicit VR Little Endian TS in one PC.");

    opts.addOption("fileref", false,
            "send objects without pixel data, but with a reference to "
                    + "the DICOM file using DCM4CHE URI Referenced Transfer Syntax "
                    + "to import DICOM objects on a given file system to a DCM4CHEE " + "archive.");

    OptionBuilder.withArgName("username");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "enable User Identity Negotiation with specified username and " + " optional passcode");
    opts.addOption(OptionBuilder.create("username"));

    OptionBuilder.withArgName("passcode");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "optional passcode for User Identity Negotiation, " + "only effective with option -username");
    opts.addOption(OptionBuilder.create("passcode"));

    opts.addOption("uidnegrsp", false,
            "request positive User Identity Negotation response, " + "only effective with option -username");

    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("aet@host:port");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("request storage commitment of (successfully) sent objects "
            + "afterwards in new association to specified remote " + "Application Entity");
    opts.addOption(OptionBuilder.create("stgcmtae"));

    opts.addOption("stgcmt", false,
            "request storage commitment of (successfully) sent objects " + "afterwards in same association");

    OptionBuilder.withArgName("maxops");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("maximum number of outstanding operations it may invoke "
            + "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("timeout in ms for TCP connect, no timeout by default");
    opts.addOption(OptionBuilder.create("connectTO"));

    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 closing the listening socket, " + "1000ms by default");
    opts.addOption(OptionBuilder.create("shutdowndelay"));

    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-RSP, 10s by default");
    opts.addOption(OptionBuilder.create("rspTO"));

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

    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("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("transcoder buffer size in KB, 1KB by default");
    opts.addOption(OptionBuilder.create("bufsize"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("timeout in ms for rescan source folder. Sended file removed.");
    opts.addOption(OptionBuilder.create("rescan"));

    opts.addOption("lowprior", false, "LOW priority of the C-STORE operation, MEDIUM by default");
    opts.addOption("highprior", false, "HIGH priority of the C-STORE operation, MEDIUM by default");
    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("dcmsnd: " + e.getMessage());
        throw new RuntimeException("unreachable");
    }
    if (cl.hasOption('V')) {
        Package p = Repeater.class.getPackage();
        System.out.println("dcmsnd 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;
}