List of usage examples for org.apache.commons.cli CommandLine getArgList
public List getArgList()
From source file:org.dcm4che2.tool.dcmsnd.DcmSnd.java
@SuppressWarnings("unchecked") public static void execute(String[] args) throws Exception { 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 a v a2s . com } 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("set")) { String[] vals = cl.getOptionValues("set"); for (int i = 0; i < vals.length; i++, i++) { dcmsnd.addCoerceAttr(Tag.toTag(vals[i]), vals[i + 1]); } } if (cl.hasOption("setuid")) { dcmsnd.setSuffixUID(cl.getOptionValues("setuid")); } 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 ); throw new RuntimeException(); } 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 ); throw new RuntimeException(); } } try { dcmsnd.start(); } catch (Exception e) { System.err.println("ERROR: Failed to start server for receiving " + "Storage Commitment results:" + e.getMessage()); //System.exit( 2 ); throw new RuntimeException(); } try { t1 = System.currentTimeMillis(); try { dcmsnd.open(); } catch (Exception e) { System.err.println("ERROR: Failed to establish association:" + e.getMessage()); //System.exit( 2 ); throw new RuntimeException(); } 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 ); throw new RuntimeException(); } 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.dcm4che2.tool.dcmups.DcmUPS.java
@SuppressWarnings("unchecked") public static void main(String[] args) { CommandLine cl = parse(args); DcmUPS dcmups = new DcmUPS(cl.hasOption("device") ? cl.getOptionValue("device") : "DCMUPSSCU"); final List<String> argList = cl.getArgList(); Operation op = null;//from www .j av a 2 s . c o m String remoteAE = null; if (!argList.isEmpty()) { op = toOperation(argList.get(0)); dcmups.setSOPClassUID(op.sopClassUID); if (argList.size() < 2) exit("Missing <aet>[@<host>[:<port>]] after <operation>."); remoteAE = argList.get(1); String[] calledAETAddress = split(remoteAE, '@'); dcmups.setCalledAET(calledAETAddress[0]); if (calledAETAddress[1] == null) { dcmups.setRemoteHost("127.0.0.1"); dcmups.setRemotePort(104); } else { String[] hostPort = split(calledAETAddress[1], ':'); dcmups.setRemoteHost(hostPort[0]); dcmups.setRemotePort(toPort(hostPort[1])); } if (argList.size() > 2) exit("Too many arguments."); } if (cl.hasOption("L")) { String localAE = cl.getOptionValue("L"); String[] localPort = split(localAE, ':'); if (localPort[1] != null) dcmups.setLocalPort(toPort(localPort[1])); String[] callingAETHost = split(localPort[0], '@'); dcmups.setCalling(callingAETHost[0]); if (callingAETHost[1] != null) { dcmups.setLocalHost(callingAETHost[1]); } } 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")); dcmups.setUserIdentity(userId); } if (cl.hasOption("connectTO")) dcmups.setConnectTimeout(parseInt(cl.getOptionValue("connectTO"), "illegal argument of option -connectTO", 1, Integer.MAX_VALUE)); if (cl.hasOption("reaper")) dcmups.setAssociationReaperPeriod(parseInt(cl.getOptionValue("reaper"), "illegal argument of option -reaper", 1, Integer.MAX_VALUE)); if (cl.hasOption("cfindrspTO")) dcmups.setDimseRspTimeout(parseInt(cl.getOptionValue("cfindrspTO"), "illegal argument of option -cfindrspTO", 1, Integer.MAX_VALUE)); if (cl.hasOption("acceptTO")) dcmups.setAcceptTimeout(parseInt(cl.getOptionValue("acceptTO"), "illegal argument of option -acceptTO", 1, Integer.MAX_VALUE)); if (cl.hasOption("releaseTO")) dcmups.setReleaseTimeout(parseInt(cl.getOptionValue("releaseTO"), "illegal argument of option -releaseTO", 1, Integer.MAX_VALUE)); if (cl.hasOption("soclosedelay")) dcmups.setSocketCloseDelay(parseInt(cl.getOptionValue("soclosedelay"), "illegal argument of option -soclosedelay", 1, 10000)); if (cl.hasOption("rcvpdulen")) dcmups.setMaxPDULengthReceive( parseInt(cl.getOptionValue("rcvpdulen"), "illegal argument of option -rcvpdulen", 1, 10000) * KB); if (cl.hasOption("sndpdulen")) dcmups.setMaxPDULengthSend( parseInt(cl.getOptionValue("sndpdulen"), "illegal argument of option -sndpdulen", 1, 10000) * KB); if (cl.hasOption("sosndbuf")) dcmups.setSendBufferSize( parseInt(cl.getOptionValue("sosndbuf"), "illegal argument of option -sosndbuf", 1, 10000) * KB); if (cl.hasOption("sorcvbuf")) dcmups.setReceiveBufferSize( parseInt(cl.getOptionValue("sorcvbuf"), "illegal argument of option -sorcvbuf", 1, 10000) * KB); dcmups.setPackPDV(!cl.hasOption("pdv1")); dcmups.setTcpNoDelay(!cl.hasOption("tcpdelay")); if (cl.hasOption("findprior")) dcmups.setPriority(toPriority(cl.getOptionValue("findprior"))); if (cl.hasOption("r")) { String[] returnKeys = cl.getOptionValues("r"); for (int i = 0; i < returnKeys.length; i++) dcmups.addReturnKey(Tag.toTagPath(returnKeys[i])); } else if (op == Operation.find) dcmups.addDefReturnKeys(); if (cl.hasOption("q")) { String[] matchingKeys = cl.getOptionValues("q"); for (int i = 1; i < matchingKeys.length; i++, i++) dcmups.addMatchingKey(Tag.toTagPath(matchingKeys[i - 1]), matchingKeys[i]); } dcmups.configureTransferCapability(cl.hasOption("ivrle") ? IVRLE_TS : NATIVE_LE_TS); if (cl.hasOption("tls")) { String cipher = cl.getOptionValue("tls"); if ("NULL".equalsIgnoreCase(cipher)) { dcmups.setTlsWithoutEncyrption(); } else if ("3DES".equalsIgnoreCase(cipher)) { dcmups.setTls3DES_EDE_CBC(); } else if ("AES".equalsIgnoreCase(cipher)) { dcmups.setTlsAES_128_CBC(); } else { exit("Invalid parameter for option -tls: " + cipher); } if (cl.hasOption("tls1")) { dcmups.setTlsProtocol(TLS1); } else if (cl.hasOption("ssl3")) { dcmups.setTlsProtocol(SSL3); } else if (cl.hasOption("no_tls1")) { dcmups.setTlsProtocol(NO_TLS1); } else if (cl.hasOption("no_ssl3")) { dcmups.setTlsProtocol(NO_SSL3); } else if (cl.hasOption("no_ssl2")) { dcmups.setTlsProtocol(NO_SSL2); } dcmups.setTlsNeedClientAuth(!cl.hasOption("noclientauth")); if (cl.hasOption("keystore")) { dcmups.setKeyStoreURL(cl.getOptionValue("keystore")); } if (cl.hasOption("keystorepw")) { dcmups.setKeyStorePassword(cl.getOptionValue("keystorepw")); } if (cl.hasOption("keypw")) { dcmups.setKeyPassword(cl.getOptionValue("keypw")); } if (cl.hasOption("truststore")) { dcmups.setTrustStoreURL(cl.getOptionValue("truststore")); } if (cl.hasOption("truststorepw")) { dcmups.setTrustStorePassword(cl.getOptionValue("truststorepw")); } long t1 = System.currentTimeMillis(); try { dcmups.initTLS(); } catch (Exception e) { System.err.println("ERROR: Failed to initialize TLS context:" + e.getMessage()); System.exit(2); } long t2 = System.currentTimeMillis(); LOG.info("Initialize TLS context in {} s", Float.valueOf((t2 - t1) / 1000f)); } if (cl.hasOption("f")) try { dcmups.load(new File(cl.getOptionValue("f"))); } catch (Exception e) { exit(e.getMessage()); } else if (op == Operation.create || op == Operation.set) exit("Missing option -f"); if (cl.hasOption("iuid")) dcmups.setSOPInstanceUID(cl.getOptionValue("iuid")); else if (op == Operation.set || op == Operation.get || op == Operation.chstate) exit("Missing option -iuid"); if (cl.hasOption("state")) dcmups.setState(cl.getOptionValue("state")); else if (op == Operation.chstate) exit("Missing option -state"); if (op == Operation.subscribe || op == Operation.unsubscribe || op == Operation.suspend || op == Operation.reqcancel) { if (cl.hasOption("aet")) if (op == Operation.reqcancel) dcmups.setRequestingAE(cl.getOptionValue("aet")); else { dcmups.setReceivingAE(cl.getOptionValue("aet")); if (op == Operation.subscribe) dcmups.setDeletionLock(cl.hasOption("dellock")); } else exit("Missing option -aet"); } if (cl.hasOption("tuid")) dcmups.setTransactionUID(cl.getOptionValue("tuid")); else if (op == Operation.chstate) exit("Missing option -tuid"); if (cl.hasOption("upspush")) dcmups.setSOPClassUID(UID.UnifiedProcedureStepPushSOPClass); if (cl.hasOption("upspull")) dcmups.setSOPClassUID(UID.UnifiedProcedureStepPullSOPClass); if (cl.hasOption("upswatch")) dcmups.setSOPClassUID(UID.UnifiedProcedureStepWatchSOPClass); try { if (!dcmups.start() && op == null) exit("Missing -L aet[@host]:port"); } catch (Exception e) { System.err.println( "ERROR: Failed to start server for receiving " + "requested objects:" + e.getMessage()); System.exit(2); } if (op != null) { long t1 = System.currentTimeMillis(); try { dcmups.open(); } catch (Exception e) { LOG.error("Failed to establish association:", e); System.exit(2); } long t2 = System.currentTimeMillis(); LOG.info("Connected to {} in {} s", remoteAE, Float.valueOf((t2 - t1) / 1000f)); try { op.execute(dcmups); } catch (IOException e) { LOG.error(e.getMessage(), e); } catch (InterruptedException e) { LOG.error(e.getMessage(), e); } finally { try { dcmups.close(); } catch (InterruptedException e) { LOG.error(e.getMessage(), e); } LOG.info("Released connection to {}", remoteAE); } } }
From source file:org.dcm4che2.tool.dcmwado.DcmWado.java
private static CommandLine parse(String[] args) { Options opts = new Options(); OptionBuilder.withArgName("suid:Suid:iuid"); OptionBuilder.hasArgs(3);/*from w w w . j a va 2s. co m*/ OptionBuilder.withValueSeparator(':'); OptionBuilder.withDescription( "Retrieve object with given Study " + "Instance UID, Series Instance UID and SOP Instance UID."); opts.addOption(OptionBuilder.create("uid")); OptionBuilder.withArgName("Suid:iuid"); OptionBuilder.hasArgs(2); OptionBuilder.withValueSeparator(':'); OptionBuilder.withDescription("Series Instance UID and SOP Instance UID " + "of the presentation state storage object to be applied to the " + "image."); opts.addOption(OptionBuilder.create("pr")); opts.addOption("dcm", false, "Request DICOM object. (MIME type: application/dicom)"); opts.addOption("jpeg", false, "Request JPEG image. (MIME type: image/jpeg)"); opts.addOption("gif", false, "Request GIF image. (MIME type: image/gif)"); opts.addOption("png", false, "Request PNG image. (MIME type: image/png)"); opts.addOption("jp2", false, "Request JPEG 2000 image. (MIME type: image/jp2)"); opts.addOption("mpeg", false, "Request MPEG video. (MIME type: video/mpeg)"); opts.addOption("txt", false, "Request plain text document. (MIME type: text/plain)"); opts.addOption("html", false, "Request HTML document. (MIME type: text/html)"); opts.addOption("xml", false, "Request XML document. (MIME type: text/xml)"); opts.addOption("rtf", false, "Request RTF document. (MIME type: text/rtf)"); opts.addOption("pdf", false, "Request PDF document. (MIME type: application/pdf)"); opts.addOption("cda1", false, "Request CDA Level 1 document. " + "(MIME type: application/x-hl7-cda-level-one+xml)"); OptionBuilder.withArgName("type"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Request document with the specified MIME type." + "Alternative MIME types can be specified by additional -mime options."); opts.addOption(OptionBuilder.create("mime")); OptionBuilder.withArgName("uid"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Returned object shall be encoded with " + "the specified Transfer Syntax. Alternative Transfer Syntaxes " + "can be specified by additional -ts options."); opts.addOption(OptionBuilder.create("ts")); OptionBuilder.withArgName("name"); OptionBuilder.hasArg(); OptionBuilder.withDescription( "Returned object shall be encoded with " + "specified Character set. Alternative Character sets " + "can be specified by additional -charset options."); opts.addOption(OptionBuilder.create("charset")); opts.addOption("anonymize", false, "Remove all patient identification" + "information from returned DICOM Object"); OptionBuilder.withArgName("type"); OptionBuilder.hasArg(); OptionBuilder.withDescription( "Burn in patient information" + "(-annotation=patient) and/or technique information " + "(-annotation=technique) in returned pixel data."); opts.addOption(OptionBuilder.create("annotation")); OptionBuilder.withArgName("num"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Maximal number of pixel rows in returned image."); opts.addOption(OptionBuilder.create("rows")); OptionBuilder.withArgName("num"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Maximal number of pixel columns in returned image."); opts.addOption(OptionBuilder.create("columns")); OptionBuilder.withArgName("num"); OptionBuilder.hasArg(); OptionBuilder .withDescription("Return single frame with that number " + "within a multi-frame image object."); opts.addOption(OptionBuilder.create("frame")); OptionBuilder.withArgName("x1:y1:x2:y2"); OptionBuilder.hasArgs(4); OptionBuilder.withValueSeparator(':'); OptionBuilder.withDescription("Return rectangular region of image " + "matrix specified by top left (x1,y1) and bottom right (x2,y2) " + "corner in relative coordinates within the range 0.0 to 1.0."); opts.addOption(OptionBuilder.create("window")); OptionBuilder.withArgName("center/width"); OptionBuilder.hasArgs(2); OptionBuilder.withValueSeparator('/'); OptionBuilder .withDescription("Specifies center and width of the " + "VOI window to be applied to the image."); opts.addOption(OptionBuilder.create("window")); OptionBuilder.withArgName("num"); OptionBuilder.hasArg(); OptionBuilder.withDescription( "Quality of the image to be returned " + "within the range 1 to 100, 100 being the best quality."); opts.addOption(OptionBuilder.create("quality")); OptionBuilder.withArgName("path"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Directory to store retrieved objects, " + "working directory by default"); opts.addOption(OptionBuilder.create("dir")); OptionBuilder.withArgName("dirpath"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Directory to store retrieved objects, " + "working directory by default"); opts.addOption(OptionBuilder.create("dir")); OptionBuilder.withArgName("file"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Store retrieved object to specified file, " + "use SOP Instance UID + format specific file extension as " + "file name by default."); opts.addOption(OptionBuilder.create("o")); opts.addOption("nostore", false, "Do not store retrieved objects to files."); opts.addOption("nokeepalive", false, "Close TCP connection after each response."); opts.addOption("noredirect", false, "Disable HTTP redirects."); OptionBuilder.withArgName("kB"); OptionBuilder.hasArg(); OptionBuilder.withDescription( "Size of byte buffer in KB " + "used for copying the retrieved object to disk, 8 KB by default."); opts.addOption(OptionBuilder.create("buffersize")); 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 (MissingOptionException e) { exit("dcmwado: Missing required option " + e.getMessage()); throw new RuntimeException("unreachable"); } catch (ParseException e) { exit("dcmwado: " + e.getMessage()); throw new RuntimeException("unreachable"); } if (cl.hasOption('V')) { Package p = DcmWado.class.getPackage(); System.out.println("dcmwado v" + p.getImplementationVersion()); System.exit(0); } if (cl.hasOption('h') || cl.getArgList().isEmpty()) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(USAGE, DESCRIPTION, opts, EXAMPLE); System.exit(0); } int narg = cl.getArgList().size(); if (narg == 0) exit("Missing url of WADO server"); if (narg == 1) { if (!cl.hasOption("uid")) { exit("You must either option -uid <uids> or <file>|<directory> specify"); } } else { if (cl.hasOption("uid")) { exit("You may not specify option -uid <uids> together with " + "<file>|<directory>."); } } return cl; }
From source file:org.dcm4che2.tool.dcmwado.DcmWado.java
public static void main(String[] args) { DcmWado dcmwado = new DcmWado(); try {/*from www . ja v a 2 s.c o m*/ CommandLine cl = parse(args); if (cl.hasOption("pr")) { dcmwado.setPresentation(cl.getOptionValues("pr")); } if (cl.hasOption("dcm")) { dcmwado.addContentType("application/dicom"); } if (cl.hasOption("jpeg")) { dcmwado.addContentType("image/jpeg"); } if (cl.hasOption("gif")) { dcmwado.addContentType("image/gif)"); } if (cl.hasOption("png")) { dcmwado.addContentType("image/png"); } if (cl.hasOption("jp2")) { dcmwado.addContentType("image/jp2"); } if (cl.hasOption("mpeg")) { dcmwado.addContentType("video/mpeg"); } if (cl.hasOption("txt")) { dcmwado.addContentType("text/plain"); } if (cl.hasOption("html")) { dcmwado.addContentType("text/html"); } if (cl.hasOption("xml")) { dcmwado.addContentType("text/xml"); } if (cl.hasOption("rtf")) { dcmwado.addContentType("text/rtf"); } if (cl.hasOption("pdf")) { dcmwado.addContentType("application/pdf"); } if (cl.hasOption("cda1")) { dcmwado.addContentType("application/x-hl7-cda-level-one+xml"); } if (cl.hasOption("mime")) { dcmwado.addContentType(cl.getOptionValues("mime")); } if (cl.hasOption("ts")) { dcmwado.setTransferSyntax(cl.getOptionValues("ts")); } dcmwado.setTransferSyntaxSameAsFile(cl.hasOption("tsfile")); if (cl.hasOption("charset")) { dcmwado.setCharset(cl.getOptionValues("charset")); } dcmwado.setAnonymize(cl.hasOption("anonymize")); if (cl.hasOption("annotation")) { dcmwado.setAnnotation(cl.getOptionValues("annotation")); } if (cl.hasOption("rows")) { dcmwado.setRows(parseInt(cl.getOptionValue("h"), "Invalid value of -h", 1, Integer.MAX_VALUE)); } if (cl.hasOption("columns")) { dcmwado.setColumns(parseInt(cl.getOptionValue("w"), "Invalid value of -w", 1, Integer.MAX_VALUE)); } if (cl.hasOption("frame")) { dcmwado.setFrameNumber( parseInt(cl.getOptionValue("f"), "Invalid value of -f", 1, Integer.MAX_VALUE)); } if (cl.hasOption("region")) { dcmwado.setRegion(cl.getOptionValues("reg")); } if (cl.hasOption("window")) { dcmwado.setWindow(cl.getOptionValues("voi")); } if (cl.hasOption("quality")) { dcmwado.setImageQuality( parseInt(cl.getOptionValue("q"), "Invalid value of -q", 1, Integer.MAX_VALUE)); } if (cl.hasOption("dir")) { dcmwado.setDirectory(new File(cl.getOptionValue("dir"))); } if (cl.hasOption("o")) { dcmwado.setOutput(new File(cl.getOptionValue("o"))); } if (cl.hasOption("nostore")) { dcmwado.setDirectory(null); } dcmwado.setNoKeepAlive(cl.hasOption("nokeepalive")); dcmwado.setFollowsRedirect(!cl.hasOption("noredirect")); if (cl.hasOption("buffersize")) { dcmwado.setBufferSize(parseInt(cl.getOptionValue("bs"), "Invalid value of -bs", 1, 1000) * KB); } List argList = cl.getArgList(); dcmwado.setBaseURL((String) argList.get(0)); if (cl.hasOption("uid")) { dcmwado.setUIDs(cl.getOptionValues("uid")); } else { System.out.println("Scanning files for uids"); long t1 = System.currentTimeMillis(); for (int i = 1, n = argList.size(); i < n; i++) { dcmwado.addFile(new File((String) argList.get(i))); } long t2 = System.currentTimeMillis(); System.out.println( "\nScanned " + dcmwado.getNumberOfRequests() + " files in " + ((t2 - t1) / 1000F) + "s"); } } catch (Exception e) { exit(e.getMessage()); } long t1 = System.currentTimeMillis(); dcmwado.fetchObjects(); long t2 = System.currentTimeMillis(); float seconds = (t2 - t1) / 1000F; System.out.println( "\nFetch " + dcmwado.getNumberOfRequests() + " objects (=" + promptBytes(dcmwado.getTotalSize()) + ") in " + seconds + "s (=" + promptBytes(dcmwado.getTotalSize() / seconds) + "/s)"); }
From source file:org.dcm4che2.tool.fixjpegls.FixJpegLS.java
@SuppressWarnings("unchecked") public static void main(String[] args) { try {//from w w w .jav a2 s .c o m CommandLine cl = parseCommandLine(args); if (cl == null) return; List<String> argList = cl.getArgList(); File target = removeTarget(argList); FixJpegLS fixJpegLS = new FixJpegLS(); if (cl.hasOption("no-check-impl-cuid")) fixJpegLS.setImplClassUID(null); else if (cl.hasOption("check-impl-cuid")) fixJpegLS.setImplClassUID(cl.getOptionValue("check-impl-cuid")); if (cl.hasOption("no-new-impl-cuid")) fixJpegLS.setNewImplClassUID(null); else if (cl.hasOption("new-impl-cuid")) fixJpegLS.setNewImplClassUID(cl.getOptionValue("new-impl-cuid")); int[] counts = new int[2]; long start = System.currentTimeMillis(); for (String arg : argList) fixJpegLS.fix(new File(arg), target, counts); long end = System.currentTimeMillis(); System.out.println(); System.out.println("Fix " + counts[1] + " of " + counts[0] + " scanned files in " + ((end - start) / 1000.f) + " s."); } catch (ParseException e) { System.err.println("fixjpegls: " + e.getMessage()); System.err.println("Try `fixjpegls --help' for more information."); System.exit(1); } catch (Exception e) { System.err.println("fixjpegls: " + e.getMessage()); System.exit(1); } }
From source file:org.dcm4che2.tool.jpg2dcm.Jpg2Dcm.java
@SuppressWarnings("rawtypes") public static void main(String[] args) { try {/*from w w w .j a v a 2s .c o m*/ 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, 1); long fin = System.currentTimeMillis(); System.out.println("Encapsulated " + jpgFile + " to " + dcmFile + " in " + (fin - start) + "ms."); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.dcm4che2.tool.jpg2dcm.Jpg2Dcm.java
private static CommandLine parse(String[] args) { Options opts = new Options(); OptionBuilder.withArgName("code"); OptionBuilder.hasArg();/*from www . j a v a 2 s . c om*/ OptionBuilder.withDescription(OPT_CHARSET_DESC); OptionBuilder.withLongOpt(LONG_OPT_CHARSET); opts.addOption(OptionBuilder.create()); OptionBuilder.withArgName("file"); OptionBuilder.hasArg(); OptionBuilder.withDescription(OPT_AUGMENT_CONFIG_DESC); opts.addOption(OptionBuilder.create("c")); OptionBuilder.withArgName("file"); OptionBuilder.hasArg(); OptionBuilder.withDescription(OPT_REPLACE_CONFIG_DESC); opts.addOption(OptionBuilder.create("C")); OptionBuilder.withArgName("prefix"); OptionBuilder.hasArg(); OptionBuilder.withDescription(OPT_UID_PREFIX_DESC); OptionBuilder.withLongOpt(LONG_OPT_UID_PREFIX); opts.addOption(OptionBuilder.create()); OptionBuilder.withArgName("uid"); OptionBuilder.hasArg(); OptionBuilder.withDescription(OPT_TRANSFER_SYNTAX_DESC); OptionBuilder.withLongOpt(LONG_OPT_TRANSFER_SYNTAX); opts.addOption(OptionBuilder.create()); opts.addOption(null, LONG_OPT_MPEG, false, OPT_MPEG_DESC); opts.addOption(null, LONG_OPT_NO_APPN, false, OPT_NO_APPN_DESC); opts.addOption("h", "help", false, OPT_HELP_DESC); opts.addOption("V", "version", false, OPT_VERSION_DESC); CommandLine cl = null; try { cl = new PosixParser().parse(opts, args); } catch (ParseException e) { exit("jpg2dcm: " + e.getMessage()); throw new RuntimeException("unreachable"); } if (cl.hasOption('V')) { Package p = Jpg2Dcm.class.getPackage(); System.out.println("jpg2dcm 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.dcm4che2.tool.pdf2dcm.Pdf2Dcm.java
public static void main(String[] args) { try {//w ww.j av a 2s .c o m CommandLine cl = parse(args); Pdf2Dcm pdf2Dcm = new Pdf2Dcm(); if (cl.hasOption("ivrle")) { pdf2Dcm.setTransferSyntax(UID.ImplicitVRLittleEndian); } if (cl.hasOption("cs")) { pdf2Dcm.setCharset(cl.getOptionValue("cs")); } if (cl.hasOption("bs")) { pdf2Dcm.setBufferSize(Integer.parseInt(cl.getOptionValue("bs"))); } if (cl.hasOption("c")) { pdf2Dcm.loadConfiguration(new File(cl.getOptionValue("c"))); } if (cl.hasOption("uid")) { UIDUtils.setRoot(cl.getOptionValue("uid")); } List argList = cl.getArgList(); File pdfFile = new File((String) argList.get(0)); File dcmFile = new File((String) argList.get(1)); long start = System.currentTimeMillis(); pdf2Dcm.convert(pdfFile, dcmFile); long fin = System.currentTimeMillis(); System.out.println("Encapsulated " + pdfFile + " to " + dcmFile + " in " + (fin - start) + "ms."); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.dcm4che2.tool.pdf2dcm.Pdf2Dcm.java
private static CommandLine parse(String[] args) { Options opts = new Options(); OptionBuilder.withArgName("charset"); OptionBuilder.hasArg();/*from w w w .j a v a 2 s . c om*/ OptionBuilder.withDescription("Specific Character Set, ISO_IR 100 by default"); opts.addOption(OptionBuilder.create("cs")); OptionBuilder.withArgName("size"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Buffer size used for copying PDF to DICOM file, 8192 by default"); opts.addOption(OptionBuilder.create("bs")); OptionBuilder.withArgName("file"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Configuration file specifying DICOM attribute values"); opts.addOption(OptionBuilder.create("c")); opts.addOption("ivrle", false, "use Implicit VR Little Endian instead " + "Explicit VR Little Endian Transfer Syntax for DICOM encoding."); opts.addOption("h", "help", false, "print this message"); OptionBuilder.withArgName("prefix"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Generate UIDs with given prefix," + "1.2.40.0.13.1.<host-ip> by default."); opts.addOption(OptionBuilder.create("uid")); 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("pdf2dcm: " + e.getMessage()); throw new RuntimeException("unreachable"); } if (cl.hasOption('V')) { Package p = Pdf2Dcm.class.getPackage(); System.out.println("pdf2dcm 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.dcm4che2.tool.rgb2ybr.Rgb2Ybr.java
private static CommandLine parse(String[] args) { Options opts = new Options(); opts.addOption("p", "partial", false, "convert to YBR_PARTIAL instead to YBR_FULL (=default)"); opts.addOption("i", "invers", false, "convert from YBR_* to RGB"); opts.addOption("h", "help", false, "print this message"); opts.addOption("V", "version", false, "print the version information and exit"); CommandLine cl = null; try {// w w w .ja va 2s .c om cl = new PosixParser().parse(opts, args); } catch (ParseException e) { exit("rgb2ybr: " + e.getMessage()); throw new RuntimeException("unreachable"); } if (cl.hasOption('V')) { Package p = Rgb2Ybr.class.getPackage(); System.out.println("rgb2ybr 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; }