List of usage examples for java.util List size
int size();
From source file:mod.org.dcm4che2.tool.DcmSnd.java
@SuppressWarnings("unchecked") public static void main(String[] args) { CommandLine cl = parse(args);/*from w ww. j a v a2s. c om*/ 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); } 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("anonymize")) dcmsnd.setAnonymize(Long.parseLong(cl.getOptionValue("anonymize"))); 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); if (cl.hasOption("batchsize")) dcmsnd.setBatchSize(Integer.parseInt(cl.getOptionValue("batchsize"))); 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); } } while (dcmsnd.getLastSentFile() < dcmsnd.getNumberOfFilesToSend()) { 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:com.upload.DcmSnd.java
@SuppressWarnings("unchecked") public static void main(String[] args) { CommandLine cl = parse(args);/*from w ww .j av a 2s . co m*/ 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); } 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("anonymize")) dcmsnd.setAnonymize(Long.parseLong(cl.getOptionValue("anonymize"))); 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); if (cl.hasOption("batchsize")) dcmsnd.setBatchSize(Integer.parseInt(cl.getOptionValue("batchsize"))); 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); } } while (dcmsnd.getLastSentFile() < dcmsnd.getNumberOfFilesToSend()) { 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:io.compgen.cgpipe.CGPipe.java
public static void main(String[] args) { String fname = null;/*from w w w . j a v a 2 s .c o m*/ String logFilename = null; String outputFilename = null; PrintStream outputStream = null; int verbosity = 0; boolean silent = false; boolean dryrun = false; boolean silenceStdErr = false; boolean showHelp = false; List<String> targets = new ArrayList<String>(); Map<String, VarValue> confVals = new HashMap<String, VarValue>(); String k = null; for (int i = 0; i < args.length; i++) { String arg = args[i]; if (i == 0) { if (new File(arg).exists()) { fname = arg; silenceStdErr = true; continue; } } else if (args[i - 1].equals("-f")) { fname = arg; continue; } else if (args[i - 1].equals("-l")) { logFilename = arg; continue; } else if (args[i - 1].equals("-o")) { outputFilename = arg; continue; } if (arg.equals("-h") || arg.equals("-help") || arg.equals("--help")) { if (k != null) { if (k.contains("-")) { k = k.replaceAll("-", "_"); } confVals.put(k, VarBool.TRUE); } showHelp = true; } else if (arg.equals("-license")) { license(); System.exit(1); } else if (arg.equals("-s")) { if (k != null) { if (k.contains("-")) { k = k.replaceAll("-", "_"); } confVals.put(k, VarBool.TRUE); } silent = true; } else if (arg.equals("-nolog")) { if (k != null) { if (k.contains("-")) { k = k.replaceAll("-", "_"); } confVals.put(k, VarBool.TRUE); } silenceStdErr = true; } else if (arg.equals("-v")) { if (k != null) { if (k.contains("-")) { k = k.replaceAll("-", "_"); } confVals.put(k, VarBool.TRUE); } verbosity++; } else if (arg.equals("-vv")) { if (k != null) { if (k.contains("-")) { k = k.replaceAll("-", "_"); } confVals.put(k, VarBool.TRUE); } verbosity += 2; } else if (arg.equals("-vvv")) { if (k != null) { if (k.contains("-")) { k = k.replaceAll("-", "_"); } confVals.put(k, VarBool.TRUE); } verbosity += 3; } else if (arg.equals("-dr")) { if (k != null) { if (k.contains("-")) { k = k.replaceAll("-", "_"); } confVals.put(k, VarBool.TRUE); } dryrun = true; } else if (arg.startsWith("--")) { if (k != null) { if (k.contains("-")) { k = k.replaceAll("-", "_"); } confVals.put(k, VarBool.TRUE); } k = arg.substring(2); } else if (k != null) { if (k.contains("-")) { k = k.replaceAll("-", "_"); } if (confVals.containsKey(k)) { try { VarValue val = confVals.get(k); if (val.getClass().equals(VarList.class)) { ((VarList) val).add(VarValue.parseStringRaw(arg)); } else { VarList list = new VarList(); list.add(val); list.add(VarValue.parseStringRaw(arg)); confVals.put(k, list); } } catch (VarTypeException e) { System.err.println("Error setting variable: " + k + " => " + arg); System.exit(1); ; } } else { confVals.put(k, VarValue.parseStringRaw(arg)); } k = null; } else if (arg.charAt(0) != '-') { targets.add(arg); } } if (k != null) { if (k.contains("-")) { k = k.replaceAll("-", "_"); } confVals.put(k, VarBool.TRUE); } confVals.put("cgpipe.loglevel", new VarInt(verbosity)); if (fname == null) { usage(); System.exit(1); } if (!showHelp) { switch (verbosity) { case 0: SimpleFileLoggerImpl.setLevel(Level.INFO); break; case 1: SimpleFileLoggerImpl.setLevel(Level.DEBUG); break; case 2: SimpleFileLoggerImpl.setLevel(Level.TRACE); break; case 3: default: SimpleFileLoggerImpl.setLevel(Level.ALL); break; } } else { SimpleFileLoggerImpl.setLevel(Level.FATAL); } SimpleFileLoggerImpl.setSilent(silenceStdErr || showHelp); Log log = LogFactory.getLog(CGPipe.class); log.info("Starting new run: " + fname); if (logFilename != null) { confVals.put("cgpipe.log", new VarString(logFilename)); } if (System.getenv("CGPIPE_DRYRUN") != null && !System.getenv("CGPIPE_DRYRUN").equals("")) { dryrun = true; } JobRunner runner = null; try { // Load config values from global config. RootContext root = new RootContext(); loadInitFiles(root); // Load settings from environment variables. root.loadEnvironment(); // Set cmd-line arguments if (silent) { root.setOutputStream(null); } if (outputFilename != null) { outputStream = new PrintStream(new FileOutputStream(outputFilename)); root.setOutputStream(outputStream); } for (String k1 : confVals.keySet()) { log.info("config: " + k1 + " => " + confVals.get(k1).toString()); } root.update(confVals); root.set("cgpipe.procs", new VarInt(Runtime.getRuntime().availableProcessors())); // update the URL Source loader configs SourceLoader.updateRemoteHandlers(root.cloneString("cgpipe.remote")); // Now check for help, only after we've setup the remote handlers... if (showHelp) { try { Parser.showHelp(fname); System.exit(0); } catch (IOException e) { System.err.println("Unable to find pipeline: " + fname); System.exit(1); } } // Set the global config values // globalConfig.putAll(root.cloneValues()); // Parse the AST and run it Parser.exec(fname, root); // Load the job runner *after* we execute the script to capture any config changes runner = JobRunner.load(root, dryrun); // find a build-target, and submit the job(s) to a runner if (targets.size() > 0) { for (String target : targets) { log.debug("building: " + target); BuildTarget initTarget = root.build(target); if (initTarget != null) { runner.submitAll(initTarget, root); } else { System.out.println("CGPIPE ERROR: Unable to find target: " + target); } } } else { BuildTarget initTarget = root.build(); if (initTarget != null) { runner.submitAll(initTarget, root); // Leave this commented out - it should be allowed to run cgpipe scripts w/o a target defined (testing) // } else { // System.out.println("CGPIPE ERROR: Unable to find default target"); } } runner.done(); if (outputStream != null) { outputStream.close(); } } catch (ASTParseException | ASTExecException | RunnerException | FileNotFoundException e) { if (outputStream != null) { outputStream.close(); } if (runner != null) { runner.abort(); } if (e.getClass().equals(ExitException.class)) { System.exit(((ExitException) e).getReturnCode()); } System.out.println("CGPIPE ERROR " + e.getMessage()); if (verbosity > 0) { e.printStackTrace(); } System.exit(1); } }
From source file:be.ibridge.kettle.spoon.Spoon.java
/** * This is the main procedure for Spoon. * /* w w w. j a v a 2 s . co m*/ * @param a Arguments are available in the "Get System Info" step. */ public static void main(String[] a) throws KettleException { EnvUtil.environmentInit(); ArrayList args = new ArrayList(); for (int i = 0; i < a.length; i++) args.add(a[i]); Display display = new Display(); Splash splash = new Splash(display); StringBuffer optionRepname, optionUsername, optionPassword, optionJobname, optionTransname, optionFilename, optionDirname, optionLogfile, optionLoglevel; CommandLineOption options[] = new CommandLineOption[] { new CommandLineOption("rep", "Repository name", optionRepname = new StringBuffer()), new CommandLineOption("user", "Repository username", optionUsername = new StringBuffer()), new CommandLineOption("pass", "Repository password", optionPassword = new StringBuffer()), new CommandLineOption("job", "The name of the job to launch", optionJobname = new StringBuffer()), new CommandLineOption("trans", "The name of the transformation to launch", optionTransname = new StringBuffer()), new CommandLineOption("dir", "The directory (don't forget the leading /)", optionDirname = new StringBuffer()), new CommandLineOption("file", "The filename (Transformation in XML) to launch", optionFilename = new StringBuffer()), new CommandLineOption("level", "The logging level (Basic, Detailed, Debug, Rowlevel, Error, Nothing)", optionLoglevel = new StringBuffer()), new CommandLineOption("logfile", "The logging file to write to", optionLogfile = new StringBuffer()), new CommandLineOption("log", "The logging file to write to (deprecated)", optionLogfile = new StringBuffer(), false, true), }; // Parse the options... CommandLineOption.parseArguments(args, options); String kettleRepname = Const.getEnvironmentVariable("KETTLE_REPOSITORY", null); String kettleUsername = Const.getEnvironmentVariable("KETTLE_USER", null); String kettlePassword = Const.getEnvironmentVariable("KETTLE_PASSWORD", null); if (!Const.isEmpty(kettleRepname)) optionRepname = new StringBuffer(kettleRepname); if (!Const.isEmpty(kettleUsername)) optionUsername = new StringBuffer(kettleUsername); if (!Const.isEmpty(kettlePassword)) optionPassword = new StringBuffer(kettlePassword); // Before anything else, check the runtime version!!! String version = Const.JAVA_VERSION; if ("1.4".compareToIgnoreCase(version) > 0) { System.out.println("The System is running on Java version " + version); System.out.println("Unfortunately, it needs version 1.4 or higher to run."); return; } // Set default Locale: Locale.setDefault(Const.DEFAULT_LOCALE); LogWriter log; LogWriter.setConsoleAppenderDebug(); if (Const.isEmpty(optionLogfile)) { log = LogWriter.getInstance(Const.SPOON_LOG_FILE, false, LogWriter.LOG_LEVEL_BASIC); } else { log = LogWriter.getInstance(optionLogfile.toString(), true, LogWriter.LOG_LEVEL_BASIC); } if (log.getRealFilename() != null) log.logBasic(APP_NAME, Messages.getString("Spoon.Log.LoggingToFile") + log.getRealFilename());//"Logging goes to " if (!Const.isEmpty(optionLoglevel)) { log.setLogLevel(optionLoglevel.toString()); log.logBasic(APP_NAME, Messages.getString("Spoon.Log.LoggingAtLevel") + log.getLogLevelDesc());//"Logging is at level : " } /* Load the plugins etc.*/ StepLoader stloader = StepLoader.getInstance(); if (!stloader.read()) { log.logError(APP_NAME, Messages.getString("Spoon.Log.ErrorLoadingAndHaltSystem"));//Error loading steps & plugins... halting Spoon! return; } /* Load the plugins etc. we need to load jobentry*/ JobEntryLoader jeloader = JobEntryLoader.getInstance(); if (!jeloader.read()) { log.logError("Spoon", "Error loading job entries & plugins... halting Kitchen!"); return; } final Spoon spoon = new Spoon(log, display, null); staticSpoon = spoon; spoon.setDestroy(true); spoon.setArguments((String[]) args.toArray(new String[args.size()])); log.logBasic(APP_NAME, Messages.getString("Spoon.Log.MainWindowCreated"));//Main window is created. RepositoryMeta repositoryMeta = null; UserInfo userinfo = null; if (Const.isEmpty(optionRepname) && Const.isEmpty(optionFilename) && spoon.props.showRepositoriesDialogAtStartup()) { log.logBasic(APP_NAME, Messages.getString("Spoon.Log.AskingForRepository"));//"Asking for repository" int perms[] = new int[] { PermissionMeta.TYPE_PERMISSION_TRANSFORMATION, PermissionMeta.TYPE_PERMISSION_JOB }; splash.hide(); RepositoriesDialog rd = new RepositoriesDialog(spoon.disp, perms, Messages.getString("Spoon.Application.Name"));//"Spoon" if (rd.open()) { repositoryMeta = rd.getRepository(); userinfo = rd.getUser(); if (!userinfo.useTransformations()) { MessageBox mb = new MessageBox(spoon.shell, SWT.OK | SWT.ICON_ERROR); mb.setMessage(Messages.getString("Spoon.Dialog.RepositoryUserCannotWork.Message"));//"Sorry, this repository user can't work with transformations from the repository." mb.setText(Messages.getString("Spoon.Dialog.RepositoryUserCannotWork.Title"));//"Error!" mb.open(); userinfo = null; repositoryMeta = null; } } else { // Exit point: user pressed CANCEL! if (rd.isCancelled()) { splash.dispose(); spoon.quitFile(); return; } } } try { // Read kettle transformation specified on command-line? if (!Const.isEmpty(optionRepname) || !Const.isEmpty(optionFilename)) { if (!Const.isEmpty(optionRepname)) { RepositoriesMeta repsinfo = new RepositoriesMeta(log); if (repsinfo.readData()) { repositoryMeta = repsinfo.findRepository(optionRepname.toString()); if (repositoryMeta != null) { // Define and connect to the repository... spoon.rep = new Repository(log, repositoryMeta, userinfo); if (spoon.rep.connect(Messages.getString("Spoon.Application.Name")))//"Spoon" { if (Const.isEmpty(optionDirname)) optionDirname = new StringBuffer(RepositoryDirectory.DIRECTORY_SEPARATOR); // Check username, password spoon.rep.userinfo = new UserInfo(spoon.rep, optionUsername.toString(), optionPassword.toString()); if (spoon.rep.userinfo.getID() > 0) { // Options /file, /job and /trans are mutually exclusive int t = (Const.isEmpty(optionFilename) ? 0 : 1) + (Const.isEmpty(optionJobname) ? 0 : 1) + (Const.isEmpty(optionTransname) ? 0 : 1); if (t > 1) { log.logError(APP_NAME, Messages.getString("Spoon.Log.MutuallyExcusive")); // "More then one mutually exclusive options /file, /job and /trans are specified." } else if (t == 1) { if (!Const.isEmpty(optionFilename)) { spoon.openFile(optionFilename.toString(), false); } else { // OK, if we have a specified job or transformation, try to load it... // If not, keep the repository logged in. RepositoryDirectory repdir = spoon.rep.getDirectoryTree() .findDirectory(optionDirname.toString()); if (repdir == null) { log.logError(APP_NAME, Messages.getString( "Spoon.Log.UnableFindDirectory", optionDirname.toString())); //"Can't find directory ["+dirname+"] in the repository." } else { if (!Const.isEmpty(optionTransname)) { TransMeta transMeta = new TransMeta(spoon.rep, optionTransname.toString(), repdir); transMeta.setFilename(optionRepname.toString()); transMeta.clearChanged(); spoon.addSpoonGraph(transMeta); } else { // Try to load a specified job if any JobMeta jobMeta = new JobMeta(log, spoon.rep, optionJobname.toString(), repdir); jobMeta.setFilename(optionRepname.toString()); jobMeta.clearChanged(); spoon.addChefGraph(jobMeta); } } } } } else { log.logError(APP_NAME, Messages.getString("Spoon.Log.UnableVerifyUser"));//"Can't verify username and password." spoon.rep.disconnect(); spoon.rep = null; } } else { log.logError(APP_NAME, Messages.getString("Spoon.Log.UnableConnectToRepository"));//"Can't connect to the repository." } } else { log.logError(APP_NAME, Messages.getString("Spoon.Log.NoRepositoryRrovided"));//"No repository provided, can't load transformation." } } else { log.logError(APP_NAME, Messages.getString("Spoon.Log.NoRepositoriesDefined"));//"No repositories defined on this system." } } else if (!Const.isEmpty(optionFilename)) { spoon.openFile(optionFilename.toString(), false); } } else // Normal operations, nothing on the commandline... { // Can we connect to the repository? if (repositoryMeta != null && userinfo != null) { spoon.rep = new Repository(log, repositoryMeta, userinfo); if (!spoon.rep.connect(Messages.getString("Spoon.Application.Name"))) //"Spoon" { spoon.rep = null; } } if (spoon.props.openLastFile()) { log.logDetailed(APP_NAME, Messages.getString("Spoon.Log.TryingOpenLastUsedFile"));//"Trying to open the last file used." List lastUsedFiles = spoon.props.getLastUsedFiles(); if (lastUsedFiles.size() > 0) { LastUsedFile lastUsedFile = (LastUsedFile) lastUsedFiles.get(0); spoon.loadLastUsedFile(lastUsedFile, repositoryMeta); } } } } catch (KettleException ke) { log.logError(APP_NAME, Messages.getString("Spoon.Log.ErrorOccurred") + Const.CR + ke.getMessage());//"An error occurred: " spoon.rep = null; // ke.printStackTrace(); } spoon.open(); splash.dispose(); try { while (!spoon.isDisposed()) { if (!spoon.readAndDispatch()) spoon.sleep(); } } catch (Throwable e) { log.logError(APP_NAME, Messages.getString("Spoon.Log.UnexpectedErrorOccurred") + Const.CR + e.getMessage());//"An unexpected error occurred in Spoon: probable cause: please close all windows before stopping Spoon! " e.printStackTrace(); } spoon.dispose(); log.logBasic(APP_NAME, APP_NAME + " " + Messages.getString("Spoon.Log.AppHasEnded"));//" has ended." // Close the logfile log.close(); // Kill all remaining things in this VM! System.exit(0); }
From source file:Main.java
public static <T> T firstOrNull(List<T> list) { return list.size() > 0 ? list.get(0) : null; }
From source file:Main.java
public static <T> T single(List<T> list) { if (list.size() != 1) throw new RuntimeException("Expected list with one element, got " + list.size() + " instead"); return list.get(0); }
From source file:Main.java
public static <T> void removeWithoutUsingRemoveMethod(List<T> list, int index) { if (index < 0 || index >= list.size()) { throw new IllegalArgumentException("index out of range"); }//from w w w . ja v a 2 s .c om List<T> part1 = new ArrayList<T>(list.subList(0, index)); List<T> part2 = new ArrayList<T>(list.subList(index + 1, list.size())); list.clear(); list.addAll(part1); list.addAll(part2); }
From source file:Main.java
public static <T> T head(List<T> list) { if (list.size() == 0) { throw new IllegalStateException("head of empty list"); }//from w w w.j a va2 s . c o m return list.get(0); }
From source file:Main.java
public static <T> T fourth(List<T> list) { if (list.size() < 4) { throw new NoSuchElementException("Collection does not have a enough elements"); }//from www . jav a2 s .c o m return list.get(3); }
From source file:Main.java
public static <T> T third(List<T> list) { if (list.size() < 3) { throw new NoSuchElementException("Collection does not have a enough elements"); }/*from ww w . j a v a 2 s . co m*/ return list.get(2); }