List of usage examples for java.io PrintStream println
public void println(Object x)
From source file:Main.java
/** * Sends Gps data to emulator, and the start value has an offset. * /*from w w w .j av a 2s . com*/ * @param number send times * @param offset is used to compute the start latitude and longitude * @param pause pause interval between each sending */ public static void sendGps(int number, int offset, int pause) { if (number < 1) { return; } int pauseInterval = TINY_WAIT_TIME; if (pause != -1) { pauseInterval = pause; } // If it's a real device, does not send simulated GPS signal. if (!isEmulator) { return; } PrintStream out = null; Socket socket = null; try { socket = new Socket(ANDROID_LOCAL_IP, emulatorPort); out = new PrintStream(socket.getOutputStream()); double longitude = START_LONGITUDE + offset * DELTA_LONGITUDE; double latitude = START_LATITUDE + offset * DELTA_LADITUDE; for (int i = 0; i < number; i++) { out.println("geo fix " + longitude + " " + latitude); longitude += DELTA_LONGITUDE; latitude += DELTA_LADITUDE; Thread.sleep(pauseInterval); } // Wait the GPS signal can be obtained by MyTracks. Thread.sleep(SHORT_WAIT_TIME); } catch (UnknownHostException e) { System.exit(-1); } catch (IOException e) { System.exit(-1); } catch (InterruptedException e) { System.exit(-1); } finally { if (out != null) { out.close(); } } }
From source file:Main.java
/** * Sends Gps data to emulator, and the start value has an offset. * /* w ww . j av a 2s. com*/ * @param number send times * @param offset is used to compute the start latitude and longitude * @param pause pause interval between each sending */ public static void sendGps(int number, int offset, int pause) { if (number < 1) { return; } int pauseInterval = PAUSE_DEFAULT; if (pause != -1) { pauseInterval = pause; } // If it's a real device, does not send simulated GPS signal. if (!isEmulator) { return; } PrintStream out = null; Socket socket = null; try { socket = new Socket(ANDROID_LOCAL_IP, emulatorPort); out = new PrintStream(socket.getOutputStream()); double longitude = START_LONGITUDE + offset * DELTA_LONGITUDE; double latitude = START_LATITUDE + offset * DELTA_LADITUDE; for (int i = 0; i < number; i++) { out.println("geo fix " + longitude + " " + latitude); longitude += DELTA_LONGITUDE; latitude += DELTA_LADITUDE; Thread.sleep(pauseInterval); } // Wait the GPS signal can be obtained by MyTracks. Thread.sleep(SHORT_WAIT_TIME); } catch (UnknownHostException e) { System.exit(-1); } catch (IOException e) { System.exit(-1); } catch (InterruptedException e) { System.exit(-1); } finally { if (out != null) { out.close(); } } }
From source file:edu.usc.ir.geo.gazetteer.GeoNameResolver.java
/** * Writes the result as formatted json to given PrintStream * @param resolvedEntities map of resolved entities * @param out the print stream for writing output *///from w w w . j a va2 s .co m public static void writeResultJson(Map<String, List<Location>> resolvedEntities, PrintStream out) { out.println(new Gson().toJson(resolvedEntities)); }
From source file:com.buaa.cfs.utils.ReflectionUtils.java
/** * Print all of the thread's information and stack traces. * * @param stream the stream to//from ww w .j a v a2s.co m * @param title a string title for the stack trace */ public synchronized static void printThreadInfo(PrintStream stream, String title) { final int STACK_DEPTH = 20; boolean contention = threadBean.isThreadContentionMonitoringEnabled(); long[] threadIds = threadBean.getAllThreadIds(); stream.println("Process Thread Dump: " + title); stream.println(threadIds.length + " active threads"); for (long tid : threadIds) { ThreadInfo info = threadBean.getThreadInfo(tid, STACK_DEPTH); if (info == null) { stream.println(" Inactive"); continue; } stream.println("Thread " + getTaskName(info.getThreadId(), info.getThreadName()) + ":"); Thread.State state = info.getThreadState(); stream.println(" State: " + state); stream.println(" Blocked count: " + info.getBlockedCount()); stream.println(" Waited count: " + info.getWaitedCount()); if (contention) { stream.println(" Blocked time: " + info.getBlockedTime()); stream.println(" Waited time: " + info.getWaitedTime()); } if (state == Thread.State.WAITING) { stream.println(" Waiting on " + info.getLockName()); } else if (state == Thread.State.BLOCKED) { stream.println(" Blocked on " + info.getLockName()); stream.println(" Blocked by " + getTaskName(info.getLockOwnerId(), info.getLockOwnerName())); } stream.println(" Stack:"); for (StackTraceElement frame : info.getStackTrace()) { stream.println(" " + frame.toString()); } } stream.flush(); }
From source file:edu.umn.cs.spatialHadoop.indexing.Indexer.java
private static void indexLocal(Path inPath, final Path outPath, OperationsParams params) throws IOException, InterruptedException { Job job = Job.getInstance(params);/*from w ww . ja va 2 s .c o m*/ final Configuration conf = job.getConfiguration(); final String sindex = conf.get("sindex"); // Start reading input file List<InputSplit> splits = new ArrayList<InputSplit>(); final SpatialInputFormat3<Rectangle, Shape> inputFormat = new SpatialInputFormat3<Rectangle, Shape>(); FileSystem inFs = inPath.getFileSystem(conf); FileStatus inFStatus = inFs.getFileStatus(inPath); if (inFStatus != null && !inFStatus.isDir()) { // One file, retrieve it immediately. // This is useful if the input is a hidden file which is automatically // skipped by FileInputFormat. We need to plot a hidden file for the case // of plotting partition boundaries of a spatial index splits.add(new FileSplit(inPath, 0, inFStatus.getLen(), new String[0])); } else { SpatialInputFormat3.setInputPaths(job, inPath); for (InputSplit s : inputFormat.getSplits(job)) splits.add(s); } // Copy splits to a final array to be used in parallel final FileSplit[] fsplits = splits.toArray(new FileSplit[splits.size()]); boolean replicate = PartitionerReplicate.get(sindex); // Set input file MBR if not already set Rectangle inputMBR = (Rectangle) OperationsParams.getShape(conf, "mbr"); if (inputMBR == null) { inputMBR = FileMBR.fileMBR(inPath, new OperationsParams(conf)); OperationsParams.setShape(conf, "mbr", inputMBR); } setLocalIndexer(conf, sindex); final Partitioner partitioner = createPartitioner(inPath, outPath, conf, sindex); final IndexRecordWriter<Shape> recordWriter = new IndexRecordWriter<Shape>(partitioner, replicate, sindex, outPath, conf); for (FileSplit fsplit : fsplits) { RecordReader<Rectangle, Iterable<Shape>> reader = inputFormat.createRecordReader(fsplit, null); if (reader instanceof SpatialRecordReader3) { ((SpatialRecordReader3) reader).initialize(fsplit, conf); } else if (reader instanceof RTreeRecordReader3) { ((RTreeRecordReader3) reader).initialize(fsplit, conf); } else if (reader instanceof HDFRecordReader) { ((HDFRecordReader) reader).initialize(fsplit, conf); } else { throw new RuntimeException("Unknown record reader"); } final IntWritable partitionID = new IntWritable(); while (reader.nextKeyValue()) { Iterable<Shape> shapes = reader.getCurrentValue(); if (replicate) { for (final Shape s : shapes) { partitioner.overlapPartitions(s, new ResultCollector<Integer>() { @Override public void collect(Integer id) { partitionID.set(id); try { recordWriter.write(partitionID, s); } catch (IOException e) { throw new RuntimeException(e); } } }); } } else { for (final Shape s : shapes) { int pid = partitioner.overlapPartition(s); if (pid != -1) { partitionID.set(pid); recordWriter.write(partitionID, s); } } } } reader.close(); } recordWriter.close(null); // Write the WKT formatted master file Path masterPath = new Path(outPath, "_master." + sindex); FileSystem outFs = outPath.getFileSystem(params); Path wktPath = new Path(outPath, "_" + sindex + ".wkt"); PrintStream wktOut = new PrintStream(outFs.create(wktPath)); wktOut.println("ID\tBoundaries\tRecord Count\tSize\tFile name"); Text tempLine = new Text2(); Partition tempPartition = new Partition(); LineReader in = new LineReader(outFs.open(masterPath)); while (in.readLine(tempLine) > 0) { tempPartition.fromText(tempLine); wktOut.println(tempPartition.toWKT()); } in.close(); wktOut.close(); }
From source file:org.apache.archiva.redback.rbac.jdo.JdoTool.java
public static void dumpObjectState(PrintStream out, Object o) { final String STATE = "[STATE] "; final String INDENT = " "; if (o == null) { out.println(STATE + "Object is null."); return;//from w w w. j a v a 2 s . co m } out.println(STATE + "Object " + o.getClass().getName()); if (!(o instanceof PersistenceCapable)) { out.println(INDENT + "is NOT PersistenceCapable (not a jdo object?)"); return; } out.println(INDENT + "is PersistenceCapable."); if (o instanceof Detachable) { out.println(INDENT + "is Detachable"); } out.println(INDENT + "is new : " + Boolean.toString(JDOHelper.isNew(o))); out.println(INDENT + "is transactional : " + Boolean.toString(JDOHelper.isTransactional(o))); out.println(INDENT + "is deleted : " + Boolean.toString(JDOHelper.isDeleted(o))); out.println(INDENT + "is detached : " + Boolean.toString(JDOHelper.isDetached(o))); out.println(INDENT + "is dirty : " + Boolean.toString(JDOHelper.isDirty(o))); out.println(INDENT + "is persistent : " + Boolean.toString(JDOHelper.isPersistent(o))); out.println(INDENT + "object id : " + JDOHelper.getObjectId(o)); }
From source file:edu.usc.ir.geo.gazetteer.GeoNameResolver.java
/** * Writes the result to given PrintStream * @deprecated Use writeResultJson instead * @param resolvedEntities map of resolved entities * @param out the print stream for writing output *//*from w w w . j ava 2 s . c o m*/ @Deprecated public static void writeResult(Map<String, List<Location>> resolvedEntities, PrintStream out) { out.println("["); List<String> keys = (List<String>) (List<?>) Arrays.asList(resolvedEntities.keySet().toArray()); //TODO: use org.json.JSONArray and remove this custom formatting code for (int j = 0; j < keys.size(); j++) { String n = keys.get(j); out.println("{\"" + n + "\" : ["); List<Location> terms = resolvedEntities.get(n); for (int i = 0; i < terms.size(); i++) { Location res = terms.get(i); if (i < terms.size() - 1) { out.println(res + ","); } else { out.println(res); } } if (j < keys.size() - 1) { out.println("]},"); } else { out.println("]}"); } } out.println("]"); }
From source file:com.l2jfree.util.concurrent.RunnableStatsManager.java
public static void dumpClassStats(final SortBy sortBy) { final List<MethodStat> methodStats = new ArrayList<MethodStat>(); synchronized (RunnableStatsManager.class) { for (ClassStat classStat : _classStats.values()) for (MethodStat methodStat : classStat._methodStats) if (methodStat._count > 0) methodStats.add(methodStat); }// w w w . j a va 2s . c om if (sortBy != null) Collections.sort(methodStats, sortBy._comparator); final List<String> lines = new ArrayList<String>(); lines.add("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"); lines.add("<entries>"); lines.add("\t<!-- This XML contains statistics about execution times. -->"); lines.add("\t<!-- Submitted results will help the developers to optimize the server. -->"); final String[][] values = new String[SortBy.VALUES.length][methodStats.size()]; final int[] maxLength = new int[SortBy.VALUES.length]; for (int i = 0; i < SortBy.VALUES.length; i++) { final SortBy sort = SortBy.VALUES[i]; for (int k = 0; k < methodStats.size(); k++) { final Comparable c = sort.getComparableValueOf(methodStats.get(k)); final String value; if (c instanceof Number) value = NumberFormat.getInstance(Locale.ENGLISH).format(((Number) c).longValue()); else value = String.valueOf(c); values[i][k] = value; maxLength[i] = Math.max(maxLength[i], value.length()); } } for (int k = 0; k < methodStats.size(); k++) { StringBuilder sb = new StringBuilder(); sb.append("\t<entry "); EnumSet<SortBy> set = EnumSet.allOf(SortBy.class); if (sortBy != null) { switch (sortBy) { case NAME: case METHOD: appendAttribute(sb, SortBy.NAME, values[SortBy.NAME.ordinal()][k], maxLength[SortBy.NAME.ordinal()]); set.remove(SortBy.NAME); appendAttribute(sb, SortBy.METHOD, values[SortBy.METHOD.ordinal()][k], maxLength[SortBy.METHOD.ordinal()]); set.remove(SortBy.METHOD); break; default: appendAttribute(sb, sortBy, values[sortBy.ordinal()][k], maxLength[sortBy.ordinal()]); set.remove(sortBy); break; } } for (SortBy sort : SortBy.VALUES) if (set.contains(sort)) appendAttribute(sb, sort, values[sort.ordinal()][k], maxLength[sort.ordinal()]); sb.append("/>"); lines.add(sb.toString()); } lines.add("</entries>"); PrintStream ps = null; try { ps = new PrintStream("MethodStats-" + System.currentTimeMillis() + ".log"); for (String line : lines) ps.println(line); } catch (Exception e) { _log.warn("", e); } finally { IOUtils.closeQuietly(ps); } }
From source file:com.aionemu.commons.utils.concurrent.RunnableStatsManager.java
@SuppressWarnings("rawtypes") public static void dumpClassStats(final SortBy sortBy) { final List<MethodStat> methodStats = new ArrayList<MethodStat>(); synchronized (RunnableStatsManager.class) { for (ClassStat classStat : classStats.values()) for (MethodStat methodStat : classStat.methodStats) if (methodStat.count > 0) methodStats.add(methodStat); }/*from www . j a va 2s . co m*/ if (sortBy != null) Collections.sort(methodStats, sortBy.comparator); final List<String> lines = new ArrayList<String>(); lines.add("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"); lines.add("<entries>"); lines.add("\t<!-- This XML contains statistics about execution times. -->"); lines.add("\t<!-- Submitted results will help the developers to optimize the server. -->"); final String[][] values = new String[SortBy.VALUES.length][methodStats.size()]; final int[] maxLength = new int[SortBy.VALUES.length]; for (int i = 0; i < SortBy.VALUES.length; i++) { final SortBy sort = SortBy.VALUES[i]; for (int k = 0; k < methodStats.size(); k++) { final Comparable c = sort.getComparableValueOf(methodStats.get(k)); final String value; if (c instanceof Number) value = NumberFormat.getInstance(Locale.ENGLISH).format(((Number) c).longValue()); else value = String.valueOf(c); values[i][k] = value; maxLength[i] = Math.max(maxLength[i], value.length()); } } for (int k = 0; k < methodStats.size(); k++) { StringBuilder sb = new StringBuilder(); sb.append("\t<entry "); EnumSet<SortBy> set = EnumSet.allOf(SortBy.class); if (sortBy != null) { switch (sortBy) { case NAME: case METHOD: appendAttribute(sb, SortBy.NAME, values[SortBy.NAME.ordinal()][k], maxLength[SortBy.NAME.ordinal()]); set.remove(SortBy.NAME); appendAttribute(sb, SortBy.METHOD, values[SortBy.METHOD.ordinal()][k], maxLength[SortBy.METHOD.ordinal()]); set.remove(SortBy.METHOD); break; default: appendAttribute(sb, sortBy, values[sortBy.ordinal()][k], maxLength[sortBy.ordinal()]); set.remove(sortBy); break; } } for (SortBy sort : SortBy.VALUES) if (set.contains(sort)) appendAttribute(sb, sort, values[sort.ordinal()][k], maxLength[sort.ordinal()]); sb.append("/>"); lines.add(sb.toString()); } lines.add("</entries>"); PrintStream ps = null; try { ps = new PrintStream("MethodStats-" + System.currentTimeMillis() + ".log"); for (String line : lines) ps.println(line); } catch (Exception e) { log.warn("", e); } finally { IOUtils.closeQuietly(ps); } }
From source file:com.aionlightning.commons.utils.concurrent.RunnableStatsManager.java
public static void dumpClassStats(final SortBy sortBy) { final List<MethodStat> methodStats = new ArrayList<MethodStat>(); synchronized (RunnableStatsManager.class) { for (ClassStat classStat : classStats.values()) for (MethodStat methodStat : classStat.methodStats) if (methodStat.count > 0) methodStats.add(methodStat); }//from www . j a v a 2 s. com if (sortBy != null) Collections.sort(methodStats, sortBy.comparator); final List<String> lines = new ArrayList<String>(); lines.add("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"); lines.add("<entries>"); lines.add("\t<!-- This XML contains statistics about execution times. -->"); lines.add("\t<!-- Submitted results will help the developers to optimize the server. -->"); final String[][] values = new String[SortBy.VALUES.length][methodStats.size()]; final int[] maxLength = new int[SortBy.VALUES.length]; for (int i = 0; i < SortBy.VALUES.length; i++) { final SortBy sort = SortBy.VALUES[i]; for (int k = 0; k < methodStats.size(); k++) { @SuppressWarnings("rawtypes") final Comparable c = sort.getComparableValueOf(methodStats.get(k)); final String value; if (c instanceof Number) value = NumberFormat.getInstance(Locale.ENGLISH).format(((Number) c).longValue()); else value = String.valueOf(c); values[i][k] = value; maxLength[i] = Math.max(maxLength[i], value.length()); } } for (int k = 0; k < methodStats.size(); k++) { StringBuilder sb = new StringBuilder(); sb.append("\t<entry "); EnumSet<SortBy> set = EnumSet.allOf(SortBy.class); if (sortBy != null) { switch (sortBy) { case NAME: case METHOD: appendAttribute(sb, SortBy.NAME, values[SortBy.NAME.ordinal()][k], maxLength[SortBy.NAME.ordinal()]); set.remove(SortBy.NAME); appendAttribute(sb, SortBy.METHOD, values[SortBy.METHOD.ordinal()][k], maxLength[SortBy.METHOD.ordinal()]); set.remove(SortBy.METHOD); break; default: appendAttribute(sb, sortBy, values[sortBy.ordinal()][k], maxLength[sortBy.ordinal()]); set.remove(sortBy); break; } } for (SortBy sort : SortBy.VALUES) if (set.contains(sort)) appendAttribute(sb, sort, values[sort.ordinal()][k], maxLength[sort.ordinal()]); sb.append("/>"); lines.add(sb.toString()); } lines.add("</entries>"); PrintStream ps = null; try { ps = new PrintStream("MethodStats-" + System.currentTimeMillis() + ".log"); for (String line : lines) ps.println(line); } catch (Exception e) { log.warn("", e); } finally { IOUtils.closeQuietly(ps); } }