List of usage examples for java.io IOException getMessage
public String getMessage()
From source file:avantssar.aslanpp.testing.Tester.java
public static void main(String[] args) { Debug.initLog(LogLevel.INFO);//w ww. j av a 2 s.c om TesterCommandLineOptions options = new TesterCommandLineOptions(); try { options.getParser().parseArgument(args); options.ckeckAtEnd(); } catch (CmdLineException ex) { reportException("Inconsistent options.", ex, System.err); options.showShortHelp(System.err); return; } if (options.isShowHelp()) { options.showLongHelp(System.out); return; } ASLanPPConnectorImpl translator = new ASLanPPConnectorImpl(); if (options.isShowVersion()) { System.out.println(translator.getFullTitleLine()); return; } ISpecificationBundleProvider sbp; File realInDir; if (options.isLibrary()) { if (options.getHornClausesLevel() != HornClausesLevel.ALL) { System.out.println("When checking the internal library we output all Horn clauses."); options.setHornClausesLevel(HornClausesLevel.ALL); } if (!options.isStripOutput()) { System.out.println( "When checking the internal library, the ouput is stripped of comments and line information."); options.setStripOutput(true); } File modelsDir = new File(FilenameUtils.concat(options.getOut().getAbsolutePath(), "_models")); try { FileUtils.forceMkdir(modelsDir); } catch (IOException e1) { System.out.println("Failed to create models folder: " + e1.getMessage()); Debug.logger.error("Failed to create models folder.", e1); } realInDir = modelsDir; sbp = new LibrarySpecificationsProvider(modelsDir.getAbsolutePath()); } else { realInDir = options.getIn(); sbp = new DiskSpecificationsProvider(options.getIn().getAbsolutePath()); } System.setProperty(EntityManager.ASLAN_ENVVAR, sbp.getASLanPath()); // try { // EntityManager.loadASLanPath(); // } // catch (IOException e) { // System.out.println("Exception while reloading ASLANPATH: " + // e.getMessage()); // Debug.logger.error("Exception while loading ASLANPATH.", e); // } try { bm = BackendsManager.instance(); if (bm != null) { for (IBackendRunner br : bm.getBackendRunners()) { System.out.println(br.getFullDescription()); if (br.getTimeout() > finalTimeout) { finalTimeout = br.getTimeout(); } } } } catch (IOException e) { System.out.println("Failed to load backends: " + e); } int threadsCount = 50; if (options.getThreads() > 0) { threadsCount = options.getThreads(); } System.out.println("Will launch " + threadsCount + " threads in parallel (+ will show that a thread starts, - that a thread ends)."); TranslationReport rep = new TranslationReport( bm != null ? bm.getBackendRunners() : new ArrayList<IBackendRunner>(), options.getOut()); long startTime = System.currentTimeMillis(); int specsCount = 0; pool = Executors.newFixedThreadPool(threadsCount); for (ITestTask task : sbp) { doTest(rep, task, realInDir, options.getOut(), translator, options, System.err); specsCount++; } pool.shutdown(); String reportFile = FilenameUtils.concat(options.getOut().getAbsolutePath(), "index.html"); try { while (!pool.awaitTermination(finalTimeout, TimeUnit.SECONDS)) { } } catch (InterruptedException e) { Debug.logger.error("Interrupted while waiting for pool termination.", e); System.out.println("Interrupted while waiting for pool termination: " + e.getMessage()); System.out.println("The report may be incomplete."); } long endTime = System.currentTimeMillis(); long duration = (endTime - startTime) / 1000; System.out.println(); System.out.println(specsCount + " specifications checked in " + duration + " seconds."); rep.report(reportFile); System.out.println("You can find an overview report at '" + reportFile + "'."); }
From source file:com.tresys.jalop.utils.jnltest.JNLTest.java
/** * Main entry point for the JNLTest program. This takes a single argument, * the full path to a configuration file to use. * * @param args// w w w.j ava 2 s .c o m * The command line arguments * @throws BEEPException * @throws JNLException */ public static void main(final String[] args) throws JNLException, BEEPException { if (args.length != 1) { System.err.println("Must specify exactly one argument that is " + " the configuration file to use"); System.exit(1); } Config config; try { config = Config.parse(args[0]); } catch (final IOException e) { System.err.println("Caught IO exception: " + e.getMessage()); System.exit(1); throw new RuntimeException("Failed to call exit()"); } catch (final ParseException e) { System.err.print(e.toString()); System.exit(1); throw new RuntimeException("Failed to call exit()"); } catch (final ConfigurationException e) { System.err.println("Exception processing the config file: " + e.getMessage()); System.exit(1); throw new RuntimeException("Failed to call exit()"); } final JNLTest jt = new JNLTest(config); System.out.println("Started Connections"); jt.start(); }
From source file:com.sun.faban.harness.util.CLI.java
/** * The first argument to the CLI is the action. It can be:<ul> * <li>pending</li>// ww w . j a v a 2s . co m * <li>status runId</li> * <li>submit benchmark profile configfile.xml</ul> * </ul> * * @param args The command line arguments. */ public static void main(String[] args) { if (args.length == 0) { printUsage(); System.exit(1); } ArrayList<String> argList = new ArrayList<String>(); // Do the getopt thing. char opt = (char) -1; String master = null; String user = null; String password = null; for (String arg : args) { if (arg.startsWith("-M")) { String optArg = arg.substring(2); if (optArg.length() == 0) { opt = 'M'; continue; } master = optArg; } else if (arg.startsWith("-U")) { String optArg = arg.substring(2); if (optArg.length() == 0) { opt = 'U'; continue; } user = optArg; } else if (arg.startsWith("-P")) { String optArg = arg.substring(2); if (optArg.length() == 0) { opt = 'P'; continue; } password = optArg; } else if (opt != (char) -1) { switch (opt) { case 'M': master = arg; opt = (char) -1; break; case 'U': user = arg; opt = (char) -1; break; case 'P': password = arg; opt = (char) -1; break; } } else { argList.add(arg); opt = (char) -1; } } if (master == null) master = "http://localhost:9980/"; else if (!master.endsWith("/")) master += '/'; CLI cli = new CLI(); String action = argList.get(0); try { if ("pending".equals(action)) { cli.doGet(master + "pending"); } else if ("status".equals(action)) { if (argList.size() > 1) cli.doGet(master + "status/" + argList.get(1)); else printUsage(); } else if ("submit".equals(action)) { if (argList.size() > 3) { cli.doPostSubmit(master, user, password, argList); } else { printUsage(); System.exit(1); } } else if ("kill".equals(action)) { if (argList.size() > 1) { cli.doPostKill(master, user, password, argList); } else { printUsage(); System.exit(1); } } else if ("wait".equals(action)) { if (argList.size() > 1) { cli.pollStatus(master + "status/" + argList.get(1)); } else { printUsage(); System.exit(1); } } else if ("showlogs".equals(action)) { StringBuilder url = new StringBuilder(); if (argList.size() > 1) { url.append(master).append("logs/"); url.append(argList.get(1)); } else { printUsage(); } for (int i = 2; i < argList.size(); i++) { if ("-t".equals(argList.get(i))) url.append("/tail"); if ("-f".equals(argList.get(i))) url.append("/follow"); if ("-ft".equals(argList.get(i))) url.append("/tail/follow"); if ("-tf".equals(argList.get(i))) url.append("/tail/follow"); } cli.doGet(url.toString()); } else { printUsage(); } } catch (IOException e) { System.err.println(e.getMessage()); System.exit(1); } }
From source file:collabedit.Telnet.java
/*** * Main for the TelnetClientExample./* ww w . j av a 2s.c o m*/ ***/ public static void main(String[] args) throws Exception { FileOutputStream fout = null; String remoteip = "23.102.136.121"; int remoteport = 8888; try { fout = new FileOutputStream("spy.log", true); } catch (IOException e) { System.err.println("Exception while opening the spy file: " + e.getMessage()); } tc = new TelnetClient(); TerminalTypeOptionHandler ttopt = new TerminalTypeOptionHandler("VT100", false, false, true, false); EchoOptionHandler echoopt = new EchoOptionHandler(true, false, true, false); SuppressGAOptionHandler gaopt = new SuppressGAOptionHandler(true, true, true, true); try { tc.addOptionHandler(ttopt); tc.addOptionHandler(echoopt); tc.addOptionHandler(gaopt); } catch (InvalidTelnetOptionException e) { System.err.println("Error registering option handlers: " + e.getMessage()); } try { tc.connect(remoteip, remoteport); Thread reader = new Thread(new Telnet()); tc.registerNotifHandler(new Telnet()); System.out.println("TelnetClientExample"); System.out.println("Type AYT to send an AYT telnet command"); System.out.println("Type OPT to print a report of status of options (0-24)"); System.out.println("Type REGISTER to register a new SimpleOptionHandler"); System.out.println("Type UNREGISTER to unregister an OptionHandler"); System.out.println("Type SPY to register the spy (connect to port 3333 to spy)"); System.out.println("Type UNSPY to stop spying the connection"); reader.start(); OutputStream outstr = tc.getOutputStream(); byte[] buff = new byte[1024]; int ret_read = 0; /* * do { try { ret_read = System.in.read(buff); if (ret_read > 0) { * if ((new String(buff, 0, ret_read)) .startsWith("AYT")) { try { * System.out.println("Sending AYT"); * * System.out.println("AYT response:" + tc.sendAYT(5000)); } catch * (IOException e) { System.err * .println("Exception waiting AYT response: " + e.getMessage()); } * } else if ((new String(buff, 0, ret_read)) .startsWith("OPT")) { * System.out.println("Status of options:"); for (int ii = 0; ii < * 25; ii++) { System.out.println("Local Option " + ii + ":" + * tc.getLocalOptionState(ii) + " Remote Option " + ii + ":" + * tc.getRemoteOptionState(ii)); } } else if ((new String(buff, 0, * ret_read)) .startsWith("REGISTER")) { StringTokenizer st = new * StringTokenizer( new String(buff)); try { st.nextToken(); int * opcode = Integer.parseInt(st .nextToken()); boolean initlocal = * Boolean.parseBoolean(st .nextToken()); boolean initremote = * Boolean .parseBoolean(st.nextToken()); boolean acceptlocal = * Boolean .parseBoolean(st.nextToken()); boolean acceptremote = * Boolean .parseBoolean(st.nextToken()); SimpleOptionHandler * opthand = new SimpleOptionHandler( opcode, initlocal, initremote, * acceptlocal, acceptremote); tc.addOptionHandler(opthand); } catch * (Exception e) { if (e instanceof InvalidTelnetOptionException) { * System.err .println("Error registering option: " + * e.getMessage()); } else { System.err * .println("Invalid REGISTER command."); System.err .println( * "Use REGISTER optcode initlocal initremote acceptlocal acceptremote" * ); System.err .println("(optcode is an integer.)"); System.err * .println * ("(initlocal, initremote, acceptlocal, acceptremote are boolean)" * ); } } } else if ((new String(buff, 0, ret_read)) * .startsWith("UNREGISTER")) { StringTokenizer st = new * StringTokenizer( new String(buff)); try { st.nextToken(); int * opcode = (new Integer(st.nextToken())) .intValue(); * tc.deleteOptionHandler(opcode); } catch (Exception e) { if (e * instanceof InvalidTelnetOptionException) { System.err * .println("Error unregistering option: " + e.getMessage()); } else * { System.err .println("Invalid UNREGISTER command."); System.err * .println("Use UNREGISTER optcode"); System.err * .println("(optcode is an integer)"); } } } else if ((new * String(buff, 0, ret_read)) .startsWith("SPY")) { * tc.registerSpyStream(fout); } else if ((new String(buff, 0, * ret_read)) .startsWith("UNSPY")) { tc.stopSpyStream(); } else { * post("hi"); } } } catch (IOException e) { * System.err.println("Exception while reading keyboard:" + * e.getMessage()); end_loop = true; } } while ((ret_read > 0) && * (end_loop == false)); */ } catch (IOException e) { System.err.println("Exception while connecting:" + e.getMessage()); System.exit(1); } }
From source file:ColumnStorage.TestColumnStorage.java
public static void main(String[] argv) throws Exception { try {//from w ww . j av a 2 s . c om if (argv.length < 1) { System.out.println("TestColumnStorage cmd[write | read ]"); return; } String cmd = argv[0]; if (cmd.equals("write")) { writeFile1(); writeFile2(); writeFile3(); } else { if (argv.length < 2) { System.out.println("TestColumnStorage read line"); return; } fieldMap.addField(new Field(ConstVar.FieldType_Byte, ConstVar.Sizeof_Byte, (short) 0)); fieldMap.addField(new Field(ConstVar.FieldType_Short, ConstVar.Sizeof_Short, (short) 1)); fieldMap.addField(new Field(ConstVar.FieldType_Int, ConstVar.Sizeof_Int, (short) 2)); fieldMap.addField(new Field(ConstVar.FieldType_Long, ConstVar.Sizeof_Long, (short) 3)); fieldMap.addField(new Field(ConstVar.FieldType_Float, ConstVar.Sizeof_Float, (short) 4)); fieldMap.addField(new Field(ConstVar.FieldType_Byte, ConstVar.Sizeof_Byte, (short) 5)); fieldMap.addField(new Field(ConstVar.FieldType_Short, ConstVar.Sizeof_Short, (short) 6)); fieldMap.addField(new Field(ConstVar.FieldType_Int, ConstVar.Sizeof_Int, (short) 7)); fieldMap.addField(new Field(ConstVar.FieldType_Long, ConstVar.Sizeof_Long, (short) 8)); fieldMap.addField(new Field(ConstVar.FieldType_Double, ConstVar.Sizeof_Double, (short) 9)); fieldMap.addField(new Field(ConstVar.FieldType_String, 0, (short) 10)); int line = Integer.valueOf(argv[1]); getRecordByLine1(line); } } catch (IOException e) { e.printStackTrace(); System.out.println("get IOException:" + e.getMessage()); } catch (Exception e) { e.printStackTrace(); System.out.println("get exception:" + e.getMessage()); } }
From source file:com.weibo.wesync.client.NHttpClient2.java
public static void main(String[] args) throws Exception { RSAPublicKey publicKey = RSAEncrypt.loadPublicKey("D:\\weibo\\meyou_gw\\conf\\public.pem"); // /*from w w w .java 2s . c o m*/ byte[] cipher = RSAEncrypt.encrypt(publicKey, password.getBytes()); password = RSAEncrypt.toHexString(cipher); // HTTP parameters for the client HttpParams params = new SyncBasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 30000) .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 30000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true); // Create HTTP protocol processing chain HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] { // Use standard client-side protocol interceptors new RequestContent(), new RequestTargetHost(), new RequestConnControl(), new RequestUserAgent(), new RequestExpectContinue() }); // Create client-side HTTP protocol handler HttpAsyncRequestExecutor protocolHandler = new HttpAsyncRequestExecutor(); // Create client-side I/O event dispatch final IOEventDispatch ioEventDispatch = new DefaultHttpClientIODispatch(protocolHandler, params); // Create client-side I/O reactor IOReactorConfig config = new IOReactorConfig(); config.setIoThreadCount(1); final ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(config); // Create HTTP connection pool BasicNIOConnPool pool = new BasicNIOConnPool(ioReactor, params); // Limit total number of connections to just two pool.setDefaultMaxPerRoute(2); pool.setMaxTotal(1); // Run the I/O reactor in a separate thread Thread t = new Thread(new Runnable() { public void run() { try { // Ready to go! ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { System.err.println("Interrupted"); } catch (IOException e) { System.err.println("I/O error: " + e.getMessage()); } System.out.println("Shutdown"); } }); // Start the client thread t.start(); // Create HTTP requester // HttpAsyncRequester requester = new HttpAsyncRequester( // httpproc, new DefaultConnectionReuseStrategy(), params); // Execute HTTP GETs to the following hosts and HttpHost[] targets = new HttpHost[] { // new HttpHost("123.125.106.28", 8093, "http"), // new HttpHost("123.125.106.28", 8093, "http"), // new HttpHost("123.125.106.28", 8093, "http"), // new HttpHost("123.125.106.28", 8093, "http"), // new HttpHost("123.125.106.28", 8093, "http"), // new HttpHost("123.125.106.28", 8093, "http"), // new HttpHost("123.125.106.28", 8093, "http"), // new HttpHost("123.125.106.28", 8093, "http"), // new HttpHost("123.125.106.28", 8093, "http"), // new HttpHost("123.125.106.28", 8093, "http"), // new HttpHost("123.125.106.28", 8093, "http"), new HttpHost("123.125.106.28", 8082, "http") }; final CountDownLatch latch = new CountDownLatch(targets.length); int callbackId = 0; for (int i = 0; i < 1; i++) { for (final HttpHost target : targets) { BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/wesync"); // String usrpwd = Base64.encodeBase64String((username + ":" + password).getBytes()); // request.setHeader("authorization", "Basic " + usrpwd); request.setHeader("uid", "2565640713"); Meyou.MeyouPacket packet = null; if (callbackId == 0) { packet = Meyou.MeyouPacket.newBuilder().setCallbackId(String.valueOf(callbackId++)) .setSort(MeyouSort.notice).build(); } else { packet = Meyou.MeyouPacket.newBuilder().setCallbackId(String.valueOf(callbackId++)) .setSort(MeyouSort.wesync).build(); } ByteArrayEntity entity = new ByteArrayEntity(packet.toByteArray()); request.setEntity(entity); // BasicHttpRequest request = new BasicHttpRequest("GET", "/test.html"); System.out.println("send ..."); HttpAsyncRequester requester = new HttpAsyncRequester(httpproc, new DefaultConnectionReuseStrategy(), params); requester.execute(new BasicAsyncRequestProducer(target, request), new BasicAsyncResponseConsumer(), pool, new BasicHttpContext(), // Handle HTTP response from a callback new FutureCallback<HttpResponse>() { public void completed(final HttpResponse response) { StatusLine status = response.getStatusLine(); int code = status.getStatusCode(); if (code == 200) { try { latch.countDown(); DataInputStream in; in = new DataInputStream(response.getEntity().getContent()); int packetLength = in.readInt(); int start = 0; while (packetLength > 0) { ByteArrayOutputStream outstream = new ByteArrayOutputStream( packetLength); byte[] buffer = new byte[1024]; int len = 0; while (start < packetLength && (len = in.read(buffer, start, packetLength)) > 0) { outstream.write(buffer, 0, len); start += len; } Meyou.MeyouPacket packet0 = Meyou.MeyouPacket .parseFrom(outstream.toByteArray()); System.out.println(target + "->" + packet0); if ((len = in.read(buffer, start, 4)) > 0) { packetLength = Util.readPacketLength(buffer); } else { break; } } } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { System.out.println("error code=" + code + "|" + status.getReasonPhrase()); } } public void failed(final Exception ex) { latch.countDown(); System.out.println(target + "->" + ex); } public void cancelled() { latch.countDown(); System.out.println(target + " cancelled"); } }); Thread.sleep((long) (Math.random() * 10000)); } } // latch.await(); // System.out.println("Shutting down I/O reactor"); // ioReactor.shutdown(); // System.out.println("Done"); }
From source file:ZipExploder.java
/** * Main command line entry point./*from w w w. ja va 2s. c om*/ * * @param args */ public static void main(final String[] args) { if (args.length == 0) { printHelp(); System.exit(0); } List zipNames = new ArrayList(); List jarNames = new ArrayList(); String destDir = null; boolean jarActive = false, zipActive = false, destDirActive = false; boolean verbose = false; // process arguments for (int i = 0; i < args.length; i++) { String arg = args[i]; if (arg.charAt(0) == '-') { // switch arg = arg.substring(1); if (arg.equalsIgnoreCase("jar")) { jarActive = true; zipActive = false; destDirActive = false; } else if (arg.equalsIgnoreCase("zip")) { zipActive = true; jarActive = false; destDirActive = false; } else if (arg.equalsIgnoreCase("dir")) { jarActive = false; zipActive = false; destDirActive = true; } else if (arg.equalsIgnoreCase("verbose")) { verbose = true; } else { reportError("Invalid switch - " + arg); } } else { if (jarActive) { jarNames.add(arg); } else if (zipActive) { zipNames.add(arg); } else if (destDirActive) { if (destDir != null) { reportError("duplicate argument - " + "-destDir"); } destDir = arg; } else { reportError("Too many parameters - " + arg); } } } if (destDir == null || (zipNames.size() + jarNames.size()) == 0) { reportError("Missing parameters"); } if (verbose) { System.out.println("Effective command: " + ZipExploder.class.getName() + " " + (jarNames.size() > 0 ? "-jars " + jarNames + " " : "") + (zipNames.size() > 0 ? "-zips " + zipNames + " " : "") + "-dir " + destDir); } try { ZipExploder ze = new ZipExploder(verbose); ze.process((String[]) zipNames.toArray(new String[zipNames.size()]), (String[]) jarNames.toArray(new String[jarNames.size()]), destDir); } catch (IOException ioe) { System.err.println("Exception - " + ioe.getMessage()); ioe.printStackTrace(); // *** debug *** System.exit(2); } }
From source file:com.hzih.sslvpn.servlet.TelnetClientExample.java
/** * Main for the TelnetClientExample./*from w w w . j a v a 2 s . c o m*/ * * */ public static void main(String[] args) throws Exception { FileOutputStream fout = null; if (args.length < 1) { System.err.println("Usage: TelnetClientExample1 <remote-ip> [<remote-port>]"); System.exit(1); } String remoteip = args[0]; int remoteport; if (args.length > 1) { remoteport = (new Integer(args[1])).intValue(); } else { remoteport = 23; } try { fout = new FileOutputStream("spy.log", true); } catch (IOException e) { System.err.println("Exception while opening the spy file: " + e.getMessage()); } tc = new TelnetClient(); TerminalTypeOptionHandler ttopt = new TerminalTypeOptionHandler("VT100", false, false, true, false); EchoOptionHandler echoopt = new EchoOptionHandler(true, false, true, false); SuppressGAOptionHandler gaopt = new SuppressGAOptionHandler(true, true, true, true); try { tc.addOptionHandler(ttopt); tc.addOptionHandler(echoopt); tc.addOptionHandler(gaopt); } catch (InvalidTelnetOptionException e) { System.err.println("Error registering option handlers: " + e.getMessage()); } while (true) { boolean end_loop = false; try { tc.connect(remoteip, remoteport); Thread reader = new Thread(new TelnetClientExample()); tc.registerNotifHandler(new TelnetClientExample()); System.out.println("TelnetClientExample"); System.out.println("Type AYT to send an AYT telnet command"); System.out.println("Type OPT to print a report of status of options (0-24)"); System.out.println("Type REGISTER to register a new SimpleOptionHandler"); System.out.println("Type UNREGISTER to unregister an OptionHandler"); System.out.println("Type SPY to register the spy (connect to port 3333 to spy)"); System.out.println("Type UNSPY to stop spying the connection"); reader.start(); OutputStream outstr = tc.getOutputStream(); byte[] buff = new byte[1024]; int ret_read = 0; do { try { ret_read = System.in.read(buff); if (ret_read > 0) { if ((new String(buff, 0, ret_read)).startsWith("AYT")) { try { System.out.println("Sending AYT"); System.out.println("AYT response:" + tc.sendAYT(5000)); } catch (IOException e) { System.err.println("Exception waiting AYT response: " + e.getMessage()); } } else if ((new String(buff, 0, ret_read)).startsWith("OPT")) { System.out.println("Status of options:"); for (int ii = 0; ii < 25; ii++) { System.out.println("Local Option " + ii + ":" + tc.getLocalOptionState(ii) + " Remote Option " + ii + ":" + tc.getRemoteOptionState(ii)); } } else if ((new String(buff, 0, ret_read)).startsWith("REGISTER")) { StringTokenizer st = new StringTokenizer(new String(buff)); try { st.nextToken(); int opcode = Integer.parseInt(st.nextToken()); boolean initlocal = Boolean.parseBoolean(st.nextToken()); boolean initremote = Boolean.parseBoolean(st.nextToken()); boolean acceptlocal = Boolean.parseBoolean(st.nextToken()); boolean acceptremote = Boolean.parseBoolean(st.nextToken()); SimpleOptionHandler opthand = new SimpleOptionHandler(opcode, initlocal, initremote, acceptlocal, acceptremote); tc.addOptionHandler(opthand); } catch (Exception e) { if (e instanceof InvalidTelnetOptionException) { System.err.println("Error registering option: " + e.getMessage()); } else { System.err.println("Invalid REGISTER command."); System.err.println( "Use REGISTER optcode initlocal initremote acceptlocal acceptremote"); System.err.println("(optcode is an integer.)"); System.err.println( "(initlocal, initremote, acceptlocal, acceptremote are boolean)"); } } } else if ((new String(buff, 0, ret_read)).startsWith("UNREGISTER")) { StringTokenizer st = new StringTokenizer(new String(buff)); try { st.nextToken(); int opcode = (new Integer(st.nextToken())).intValue(); tc.deleteOptionHandler(opcode); } catch (Exception e) { if (e instanceof InvalidTelnetOptionException) { System.err.println("Error unregistering option: " + e.getMessage()); } else { System.err.println("Invalid UNREGISTER command."); System.err.println("Use UNREGISTER optcode"); System.err.println("(optcode is an integer)"); } } } else if ((new String(buff, 0, ret_read)).startsWith("SPY")) { tc.registerSpyStream(fout); } else if ((new String(buff, 0, ret_read)).startsWith("UNSPY")) { tc.stopSpyStream(); } else { try { outstr.write(buff, 0, ret_read); outstr.flush(); } catch (IOException e) { end_loop = true; } } } } catch (IOException e) { System.err.println("Exception while reading keyboard:" + e.getMessage()); end_loop = true; } } while ((ret_read > 0) && (end_loop == false)); try { tc.disconnect(); } catch (IOException e) { System.err.println("Exception while connecting:" + e.getMessage()); } } catch (IOException e) { System.err.println("Exception while connecting:" + e.getMessage()); System.exit(1); } } }
From source file:edu.ucsc.barrel.cdf_gen.CDF_Gen.java
public static void main(String[] args) { int time_cnt = 0; //array to hold payload id, lauch order, and launch site String[] payload = new String[3]; //create a log file log = new Logger("log.txt"); //ensure there is some user input if (args.length == 0) { System.out.println("Usage: java -jar cdf_gen.jar ini=<ini file> date=<date> L=<levels>"); System.exit(0);/* ww w . j a v a 2s . c o m*/ } //read the ini file and command line arguments loadConfig(args); //for each payload, create an object to download the files, // read the list of data files on each server, then download the files for (String payload_i : payloads) { String date = "000000", id = "00", flt = "00", stn = "0", revNum = "00", mag = "0000", dpu = "00"; //break payload apart into id, flight number and launch station String[] payload_parts = payload_i.split(","); if (payload_parts[0] != null) { id = payload_parts[0]; } if (payload_parts[1] != null) { flt = payload_parts[1]; } if (payload_parts[2] != null) { stn = payload_parts[2]; } if (payload_parts[3] != null) { mag = payload_parts[3]; } if (payload_parts[3] != null) { dpu = payload_parts[4]; } //set output paths if (getSetting("outDir") != "") { //check if user specified a place to store the files output_Dir = getSetting("outDir"); } tlm_Dir = output_Dir + "/tlm/" + id + "/" + getSetting("date") + "/"; L0_Dir = output_Dir + "/l0/" + id + "/" + getSetting("date") + "/"; L1_Dir = output_Dir + "/l1/" + id + "/"; L2_Dir = output_Dir + "/l2/" + id + "/"; //set working payload settings.put("currentPayload", payload_i); //create a new storage object data = new DataHolder(payload_i); //Figure out where the input files are coming from if (getSetting("local") == "") { dataPull = new DataCollector(tlm_Dir, servers, id, settings.get("date")); //read each repository and build a list of data file URLs dataPull.getFileList(); //download each file after the URL list is made dataPull.getFiles(); } else { //a telemetry file was provided so instead of creating one we will //just change the tlm directory tlm_Dir = getSetting("local"); } //Create level zero object and convert the data files to a level 0 file try { System.out.println("Creating Level Zero..."); L0 = new LevelZero(data, Integer.parseInt(settings.get("frameLength")), settings.get("syncWord"), tlm_Dir, L0_Dir, id, flt, stn, dpu, getSetting("date")); L0.processRawFiles(); L0.finish(); System.out.println("Completed Level 0 for payload " + getSetting("currentPayload")); //If we didn't get any data, move on to the next payload. if (data.getSize("1Hz") > 0) { //calculate throughput value System.out .println("Payload " + getSetting("currentPayload") + " Throughput: " + (100 * data.getSize("1Hz") - 1) / (data.frame_1Hz[data.getSize("1Hz") - 1] - (data.frame_1Hz[0])) + " %"); //Fill the time variable ExtractTiming barrel_time = new ExtractTiming(getSetting("date")); barrel_time.fixWeekOffset(); barrel_time.getTimeRecs(); barrel_time.fillModels(); barrel_time.fillEpoch(); barrel_time = null; if (getSetting("L").indexOf("1") > -1) { //create Level One LevelOne L1 = new LevelOne(getSetting("date"), id, flt, stn, L1_Dir); L1 = null; } if (getSetting("L").indexOf("2") > -1) { //create a set of linear models that track the location of //the 511 line and store them in the DataHolder object int total_specs = data.getSize("mod32"), start_i = 0, stop_i = 0, max_recs = 20; System.out.println("Starting Level Two..."); System.out.println("Locating 511 line..."); while (start_i < total_specs) { if ((start_i + (2 * max_recs)) > total_specs) { stop_i = total_specs; } else { stop_i = start_i + max_recs; } SpectrumExtract.do511Fits(start_i, stop_i); start_i = stop_i; } fill511Gaps(); //create Level Two LevelTwo L2 = new LevelTwo(getSetting("date"), id, flt, stn, L2_Dir); L2 = null; } } } catch (IOException ex) { System.out.println(ex.getMessage()); } } //close the log file log.close(); }
From source file:fi.uta.infim.usaproxyreportgenerator.App.java
/** * Entry point./*from w ww . ja v a 2s . c o m*/ * @param args command line arguments */ public static void main(String[] args) { printLicense(); System.out.println(); try { // Command line arguments cli = parser.parse(cliOptions, args); } catch (org.apache.commons.cli.ParseException e) { System.err.println(e.getMessage()); printHelp(); return; } File outputDir; // Use CWD if output dir is not supplied outputDir = new File(cli.getOptionValue("outputDir", ".")); // Set up the browsing data provider that mines the log entries for // visualizable data. setupDataProvider(); // Output CLI options, so that the user sees what is happening System.out.println("Output directory: " + outputDir.getAbsolutePath()); System.out.println("Data provider class: " + dataProviderClass.getCanonicalName()); UsaProxyLogParser parser = new UsaProxyLogParser(); UsaProxyLog log; try { String filenames[] = cli.getArgs(); if (filenames.length == 0) { throw new IndexOutOfBoundsException(); } // Interpret remaining cli args as file names System.out.print("Parsing log file... "); log = parser.parseFilesByName(Arrays.asList(filenames)); System.out.println("done."); } catch (IOException ioe) { System.err.println("Error opening log file: " + ioe.getMessage()); printHelp(); return; } catch (ParseException pe) { System.err.println("Error parsing log file."); printHelp(); return; } catch (IndexOutOfBoundsException e) { System.err.println("Please supply a file name."); printHelp(); return; } catch (NoSuchElementException e) { System.err.println("Error opening log file: " + e.getMessage()); printHelp(); return; } setupJsonConfig(); // Set up JSON processors // Iterate over sessions and generate a report for each one. for (UsaProxySession s : log.getSessions()) { System.out.print("Generating report for session " + s.getSessionID() + "... "); try { generateHTMLReport(s, outputDir); System.out.println("done."); } catch (IOException e) { System.err.println( "I/O error generating report for session id " + s.getSessionID() + ": " + e.getMessage()); System.err.println("Skipping."); } catch (TemplateException e) { System.err.println( "Error populating template for session id " + s.getSessionID() + ": " + e.getMessage()); System.err.println("Skipping."); } } }