List of usage examples for java.io PrintStream println
public void println(Object x)
From source file:controllers.TNodes.java
/** * telnet//www .ja v a2 s . c o m * * @param ip * @param user * @param password * @param telnet * @return */ public static boolean connect(String ip, String user, String password, TelnetClient telnet) { try { telnet.connect(ip, 23); telnet.setSoTimeout(2 * 1000); PrintStream out = new PrintStream(telnet.getOutputStream()); out.println(user); out.flush(); // TimeUnit.SECONDS.sleep(1); out.println(password); out.flush(); // TimeUnit.SECONDS.sleep(1); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
From source file:edu.umn.cs.spatialHadoop.operations.FileMBR.java
public static Partition fileMBRLocal(Path[] inFiles, final OperationsParams params) throws IOException, InterruptedException { // 1- Split the input path/file to get splits that can be processed independently final SpatialInputFormat3<Rectangle, Shape> inputFormat = new SpatialInputFormat3<Rectangle, Shape>(); Job job = Job.getInstance(params);/* www. j a va2 s . co m*/ SpatialInputFormat3.setInputPaths(job, inFiles); final List<org.apache.hadoop.mapreduce.InputSplit> splits = inputFormat.getSplits(job); int parallelism = params.getInt("parallel", Runtime.getRuntime().availableProcessors()); // 2- Process splits in parallel List<Map<String, Partition>> allMbrs = Parallel.forEach(splits.size(), new RunnableRange<Map<String, Partition>>() { @Override public Map<String, Partition> run(int i1, int i2) { Map<String, Partition> mbrs = new HashMap<String, Partition>(); for (int i = i1; i < i2; i++) { try { org.apache.hadoop.mapreduce.lib.input.FileSplit fsplit = (org.apache.hadoop.mapreduce.lib.input.FileSplit) splits .get(i); final RecordReader<Rectangle, Iterable<Shape>> reader = inputFormat .createRecordReader(fsplit, null); if (reader instanceof SpatialRecordReader3) { ((SpatialRecordReader3) reader).initialize(fsplit, params); } else if (reader instanceof RTreeRecordReader3) { ((RTreeRecordReader3) reader).initialize(fsplit, params); } else if (reader instanceof HDFRecordReader) { ((HDFRecordReader) reader).initialize(fsplit, params); } else { throw new RuntimeException("Unknown record reader"); } Partition p = mbrs.get(fsplit.getPath().getName()); if (p == null) { p = new Partition(); p.filename = fsplit.getPath().getName(); p.cellId = p.filename.hashCode(); p.size = 0; p.recordCount = 0; p.set(Double.MAX_VALUE, Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE); mbrs.put(p.filename, p); } Text temp = new Text2(); while (reader.nextKeyValue()) { Iterable<Shape> shapes = reader.getCurrentValue(); for (Shape s : shapes) { Rectangle mbr = s.getMBR(); if (mbr != null) p.expand(mbr); p.recordCount++; temp.clear(); s.toText(temp); p.size += temp.getLength() + 1; } } } catch (IOException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } } return mbrs; } }, parallelism); Map<String, Partition> mbrs = allMbrs.remove(allMbrs.size() - 1); for (Map<String, Partition> list : allMbrs) { for (Partition p1 : list.values()) { Partition p2 = mbrs.get(p1.filename); if (p2 != null) { p2.expand(p1); } else { mbrs.put(p1.filename, p1); } } } // Cache the final result, if needed for (Path inFile : inFiles) { FileSystem inFs = inFile.getFileSystem(params); if (!inFs.getFileStatus(inFile).isDir()) continue; Path gindex_path = new Path(inFile, "_master.heap"); // Answer has been already cached (may be by another job) if (inFs.exists(gindex_path)) continue; FileStatus[] files = inFs.listStatus(inFile, SpatialSite.NonHiddenFileFilter); PrintStream wktout = new PrintStream(inFs.create(new Path(inFile, "_heap.wkt"), false)); PrintStream gout = new PrintStream(inFs.create(gindex_path, false)); Text text = new Text2(); for (FileStatus file : files) { text.clear(); Partition p = mbrs.get(file.getPath().getName()); gout.println(p.toText(text).toString()); wktout.println(p.toWKT()); } wktout.close(); gout.close(); } // Return the final answer Partition finalResult = new Partition(); finalResult.size = finalResult.recordCount = 0; finalResult.x1 = finalResult.y1 = Double.MAX_VALUE; finalResult.x2 = finalResult.y2 = -Double.MAX_VALUE; for (Partition p2 : mbrs.values()) finalResult.expand(p2); return finalResult; }
From source file:mzmatch.util.Tool.java
/** * Print an informative header about the tool. The application name can be passed, * which will be printed together version information of the libraries used within * the project.//from w w w . ja va 2s .c o m * * @param output The output stream to write to. * @param appname The name of the application printing the information. */ public static void printHeader(PrintStream output, String appname, String version) { String libraries[] = { //"jfreechart " + org.jfree.chart.JFreeChart.INFO.getVersion(), "itext " + com.lowagie.text.Document.getVersion().split(" ")[1], "jama " + "1.0.2", "lma " + "1.4.0", "cmdline " + cmdline.Version.convertToString(), "domsax " + domsax.Version.convertToString(), "peakml " + peakml.Version.convertToString(), "mzmatch " + mzmatch.Version.convertToString(), }; output.println(" ------------------------------------------------------"); output.println("| Copyright 2007-2009"); output.println("| Groningen Bioinformatics Centre"); output.println("| University of Groningen"); output.println("|"); output.println("| " + appname + " " + version + ""); output.println("|"); output.println("| libraries:"); for (String library : libraries) output.println("| - " + library); output.println(" ------------------------------------------------------"); }
From source file:com.bigdata.dastor.tools.SSTableExport.java
/** * Export specific rows from an SSTable and write the resulting JSON to a PrintStream. * /*from w w w.j av a 2 s . co m*/ * @param ssTableFile the SSTable to export the rows from * @param outs PrintStream to write the output to * @param keys the keys corresponding to the rows to export * @throws IOException on failure to read/write input/output */ public static void export(String ssTableFile, PrintStream outs, String[] keys, String[] excludes) throws IOException { SSTableReader reader = SSTableReader.open(ssTableFile); SSTableScanner scanner = reader.getScanner(INPUT_FILE_BUFFER_SIZE); IPartitioner<?> partitioner = DatabaseDescriptor.getPartitioner(); Set<String> excludeSet = new HashSet(); int i = 0; if (excludes != null) excludeSet = new HashSet<String>(Arrays.asList(excludes)); outs.println("{"); for (String key : keys) { if (excludeSet.contains(key)) continue; DecoratedKey<?> dk = partitioner.decorateKey(key); scanner.seekTo(dk); i++; if (scanner.hasNext()) { IteratingRow row = scanner.next(); try { String jsonOut = serializeRow(row); if (i != 1) outs.println(","); outs.print(" " + jsonOut); } catch (IOException ioexc) { System.err.println("WARNING: Corrupt row " + key + " (skipping)."); continue; } catch (OutOfMemoryError oom) { System.err.println("ERROR: Out of memory deserializing row " + key); continue; } } } outs.println("\n}"); outs.flush(); }
From source file:com.dtolabs.rundeck.core.authorization.RuleEvaluator.java
private static Decision authorize(final boolean authorized, final String reason, final Explanation.Code reasonId, final Map<String, String> resource, final Subject subject, final String action, final Set<Attribute> environment, final long evaluationTime) { return createAuthorize(authorized, new Explanation() { public Code getCode() { return reasonId; }//from www. j a v a2 s . c o m public void describe(PrintStream out) { out.println(toString()); } public String toString() { return "\t" + reason + " => " + reasonId; } }, resource, subject, action, environment, evaluationTime); }
From source file:com.google.api.ads.adwords.keywordoptimizer.KeywordOptimizer.java
/** * Outputs the results as a csv file (sorted, best first). * * @param cmdLine the parsed command line parameters * @param bestKeywords the optimized set of keywords * @throws KeywordOptimizerException in case there is a problem writing to the output file *///from www . j a v a2 s .com private static void outputCsv(CommandLine cmdLine, KeywordCollection bestKeywords) throws KeywordOptimizerException { if (!cmdLine.hasOption("of")) { throw new KeywordOptimizerException("No output file (option -of specified)"); } try { PrintStream printer = new PrintStream(cmdLine.getOptionValue("of")); printer.println(CSV_JOINER.join(CSV_HEADERS)); for (KeywordInfo eval : bestKeywords.getListSortedByScore()) { TrafficEstimate estimate = eval.getEstimate(); Object[] rowData = { eval.getKeyword().getText(), eval.getKeyword().getMatchType(), eval.getScore(), KeywordOptimizerUtil.formatCsv(estimate.getMin().getImpressionsPerDay()), KeywordOptimizerUtil.formatCsv(estimate.getMean().getImpressionsPerDay()), KeywordOptimizerUtil.formatCsv(estimate.getMax().getImpressionsPerDay()), KeywordOptimizerUtil.formatCsv(estimate.getMin().getClicksPerDay()), KeywordOptimizerUtil.formatCsv(estimate.getMean().getClicksPerDay()), KeywordOptimizerUtil.formatCsv(estimate.getMax().getClicksPerDay()), KeywordOptimizerUtil.formatCsv(estimate.getMin().getClickThroughRate()), KeywordOptimizerUtil.formatCsv(estimate.getMean().getClickThroughRate()), KeywordOptimizerUtil.formatCsv(estimate.getMax().getClickThroughRate()), KeywordOptimizerUtil.formatCsv(estimate.getMin().getAveragePosition()), KeywordOptimizerUtil.formatCsv(estimate.getMean().getAveragePosition()), KeywordOptimizerUtil.formatCsv(estimate.getMax().getAveragePosition()), KeywordOptimizerUtil.format(estimate.getMin().getAverageCpc()), KeywordOptimizerUtil.format(estimate.getMean().getAverageCpc()), KeywordOptimizerUtil.format(estimate.getMax().getAverageCpc()), KeywordOptimizerUtil.format(estimate.getMin().getTotalCost()), KeywordOptimizerUtil.format(estimate.getMean().getTotalCost()), KeywordOptimizerUtil.format(estimate.getMax().getTotalCost()) }; printer.println(CSV_JOINER.join(rowData)); } printer.close(); } catch (IOException e) { throw new KeywordOptimizerException("Error writing to output file", e); } }
From source file:MailHandlerDemo.java
/** * Used debug problems with the logging.properties. The system property * java.security.debug=access,stack can be used to trace access to the * LogManager reset./*from www.j av a2 s .c o m*/ * * @param prefix a string to prefix the output. * @param err any PrintStream or null for System.out. */ @SuppressWarnings("UseOfSystemOutOrSystemErr") private static void checkConfig(String prefix, PrintStream err) { if (prefix == null || prefix.trim().length() == 0) { prefix = "DEBUG"; } if (err == null) { err = System.out; } try { err.println(prefix + ": java.version=" + System.getProperty("java.version")); err.println(prefix + ": LOGGER=" + LOGGER.getLevel()); err.println(prefix + ": JVM id " + ManagementFactory.getRuntimeMXBean().getName()); err.println(prefix + ": java.security.debug=" + System.getProperty("java.security.debug")); SecurityManager sm = System.getSecurityManager(); if (sm != null) { err.println(prefix + ": SecurityManager.class=" + sm.getClass().getName()); err.println(prefix + ": SecurityManager classLoader=" + toString(sm.getClass().getClassLoader())); err.println(prefix + ": SecurityManager.toString=" + sm); } else { err.println(prefix + ": SecurityManager.class=null"); err.println(prefix + ": SecurityManager.toString=null"); err.println(prefix + ": SecurityManager classLoader=null"); } String policy = System.getProperty("java.security.policy"); if (policy != null) { File f = new File(policy); err.println(prefix + ": AbsolutePath=" + f.getAbsolutePath()); err.println(prefix + ": CanonicalPath=" + f.getCanonicalPath()); err.println(prefix + ": length=" + f.length()); err.println(prefix + ": canRead=" + f.canRead()); err.println(prefix + ": lastModified=" + new java.util.Date(f.lastModified())); } LogManager manager = LogManager.getLogManager(); String key = "java.util.logging.config.file"; String cfg = System.getProperty(key); if (cfg != null) { err.println(prefix + ": " + cfg); File f = new File(cfg); err.println(prefix + ": AbsolutePath=" + f.getAbsolutePath()); err.println(prefix + ": CanonicalPath=" + f.getCanonicalPath()); err.println(prefix + ": length=" + f.length()); err.println(prefix + ": canRead=" + f.canRead()); err.println(prefix + ": lastModified=" + new java.util.Date(f.lastModified())); } else { err.println(prefix + ": " + key + " is not set as a system property."); } err.println(prefix + ": LogManager.class=" + manager.getClass().getName()); err.println(prefix + ": LogManager classLoader=" + toString(manager.getClass().getClassLoader())); err.println(prefix + ": LogManager.toString=" + manager); err.println(prefix + ": MailHandler classLoader=" + toString(MailHandler.class.getClassLoader())); err.println( prefix + ": Context ClassLoader=" + toString(Thread.currentThread().getContextClassLoader())); err.println(prefix + ": Session ClassLoader=" + toString(Session.class.getClassLoader())); err.println(prefix + ": DataHandler ClassLoader=" + toString(DataHandler.class.getClassLoader())); final String p = MailHandler.class.getName(); key = p.concat(".mail.to"); String to = manager.getProperty(key); err.println(prefix + ": TO=" + to); if (to != null) { err.println(prefix + ": TO=" + Arrays.toString(InternetAddress.parse(to, true))); } key = p.concat(".mail.from"); String from = manager.getProperty(key); if (from == null || from.length() == 0) { Session session = Session.getInstance(new Properties()); InternetAddress local = InternetAddress.getLocalAddress(session); err.println(prefix + ": FROM=" + local); } else { err.println(prefix + ": FROM=" + Arrays.asList(InternetAddress.parse(from, false))); err.println(prefix + ": FROM=" + Arrays.asList(InternetAddress.parse(from, true))); } synchronized (manager) { final Enumeration<String> e = manager.getLoggerNames(); while (e.hasMoreElements()) { final Logger l = manager.getLogger(e.nextElement()); if (l != null) { final Handler[] handlers = l.getHandlers(); if (handlers.length > 0) { err.println(prefix + ": " + l.getClass().getName() + ", " + l.getName()); for (Handler h : handlers) { err.println(prefix + ":\t" + toString(prefix, err, h)); } } } } } } catch (Throwable error) { err.print(prefix + ": "); error.printStackTrace(err); } err.flush(); }
From source file:com.alvermont.javascript.tools.shell.ShellMain.java
/** * Evaluate JavaScript source.//from w ww . j a va2 s .c o m * * @param cx the current context * @param filename the name of the file to compile, or null * for interactive mode. */ public static void processSource(Context cx, String filename) { if (filename == null || filename.equals("-")) { final PrintStream ps = GLOBAL.getErr(); if (filename == null) { // print implementation version ps.println(cx.getImplementationVersion()); } // Use the interpreter for interactive input cx.setOptimizationLevel(-1); final BufferedReader in = new BufferedReader(new InputStreamReader(GLOBAL.getIn())); int lineno = 1; boolean hitEOF = false; while (!hitEOF) { final int startline = lineno; if (filename == null) { ps.print("js> "); } ps.flush(); String source = ""; // Collect lines of source to compile. while (true) { String newline; try { newline = in.readLine(); } catch (IOException ioe) { ps.println(ioe.toString()); break; } if (newline == null) { hitEOF = true; break; } source = source + newline + "\n"; ++lineno; if (cx.stringIsCompilableUnit(source)) { break; } } final Script script = loadScriptFromSource(cx, source, "<stdin>", lineno, null); if (script != null) { final Object result = evaluateScript(script, cx, GLOBAL); if (result != Context.getUndefinedValue()) { try { ps.println(Context.toString(result)); } catch (RhinoException rex) { ToolErrorReporter.reportException(cx.getErrorReporter(), rex); } } final NativeArray h = GLOBAL.getHistory(); h.put((int) h.getLength(), h, source); } } ps.println(); } else { processFile(cx, GLOBAL, filename); } System.gc(); }
From source file:com.yahoo.ycsb.bulk.hbase.BulkDataGeneratorJob.java
/** * This function computes the split points for a range * [start, end]./* w w w . j a v a 2 s . c o m*/ * @param start starting point for the range to split. * @param end ending point for the range to split. * @param numsplits number of splits to create for the range. * @return a list of split points in text format. */ public static void writeRanges(long start, long end, int partitionCount, PrintStream out) { long rangeSize = (end - start + 1) / partitionCount; long rangeStart = start; long rangeEnd = start - 1 + rangeSize; while (rangeStart <= end) { if (rangeEnd > end) { rangeEnd = end; } out.print(rangeStart); out.print(' '); out.println(rangeEnd); rangeStart += rangeSize; rangeEnd = rangeStart + rangeSize - 1; } }
From source file:nl.minbzk.dwr.zoeken.enricher.settings.EnricherSettings.java
/** * Print the processor usage information. */// ww w . j av a 2 s. c om private static void usage() { PrintStream out = System.err; out.println("usage: content-fetch [option] [file]"); out.println(); out.println("Options:"); out.println(" -? or --help Print this usage message"); out.println(" -v or --verbose Print debug level messages"); out.println(" -jX or --job=X Override with job X"); out.println(" -eX or --encoding=X Use output encoding X"); out.println(); out.println("Description:"); out.println(" The file(s) specified on the command line will be"); out.println(" parsed and will output the extracted text content"); out.println(" and metadata to the configured output folder."); out.println(); out.println(" Instead of a file name you can also specify the URL"); out.println(" of a document to be parsed."); }