Java 类android.util.StringBuilderPrinter 实例源码
项目:Mobilyzer
文件:MeasurementResult.java
private void getHttpResult(StringBuilderPrinter printer, HashMap<String, String> values) {
HttpDesc desc = (HttpDesc) parameters;
printer.println("[HTTP]");
printer.println("URL: " + desc.url);
printer.println("Timestamp: " + Util.getTimeStringFromMicrosecond(properties.timestamp));
printIPTestResult(printer);
if (taskProgress == TaskProgress.COMPLETED) {
int headerLen = Integer.parseInt(values.get("headers_len"));
int bodyLen = Integer.parseInt(values.get("body_len"));
int time = Integer.parseInt(values.get("time_ms"));
printer.println("");
printer.println("Downloaded " + (headerLen + bodyLen) + " bytes in " + time + " ms");
printer.println("Bandwidth: " + (headerLen + bodyLen) * 8 / time + " Kbps");
} else if (taskProgress == TaskProgress.PAUSED) {
printer.println("Http paused!");
} else {
printer.println("Http download failed, status code " + values.get("code"));
printer.println("Error: " + values.get("error"));
}
}
项目:Mobilyzer
文件:MeasurementResult.java
private void getDnsResult(StringBuilderPrinter printer, HashMap<String, String> values) {
DnsLookupDesc desc = (DnsLookupDesc) parameters;
printer.println("[DNS Lookup]");
printer.println("Target: " + desc.target);
printer.println("Timestamp: " + Util.getTimeStringFromMicrosecond(properties.timestamp));
printIPTestResult(printer);
if (taskProgress == TaskProgress.COMPLETED) {
String ipAddress = removeQuotes(values.get("address"));
if (ipAddress == null) {
ipAddress = "Unknown";
}
printer.println("\nAddress: " + ipAddress);
int time = Integer.parseInt(values.get("time_ms"));
printer.println("Lookup time: " + time + " ms");
} else if (taskProgress == TaskProgress.PAUSED) {
printer.println("DNS look up paused!");
} else {
printer.println("Error: " + values.get("error"));
}
}
项目:Mobiperf-Library
文件:MeasurementResult.java
private void getHttpResult(StringBuilderPrinter printer, HashMap<String, String> values) {
HttpDesc desc = (HttpDesc) measurementDesc;
printer.println("[HTTP]");
printer.println("URL: " + desc.url);
printer.println("Timestamp: " + Util.getTimeStringFromMicrosecond(properties.timestamp));
printIPTestResult(printer);
if (taskProgress == TaskProgress.COMPLETED) {
int headerLen = Integer.parseInt(values.get("headers_len"));
int bodyLen = Integer.parseInt(values.get("body_len"));
int time = Integer.parseInt(values.get("time_ms"));
printer.println("");
printer.println("Downloaded " + (headerLen + bodyLen) + " bytes in " + time + " ms");
printer.println("Bandwidth: " + (headerLen + bodyLen) * 8 / time + " Kbps");
} else if (taskProgress == TaskProgress.PAUSED) {
printer.println("Http paused!");
} else {
printer.println("Http download failed, status code " + values.get("code"));
printer.println("Error: " + values.get("error"));
}
}
项目:Mobiperf-Library
文件:MeasurementResult.java
private void getDnsResult(StringBuilderPrinter printer, HashMap<String, String> values) {
DnsLookupDesc desc = (DnsLookupDesc) measurementDesc;
printer.println("[DNS Lookup]");
printer.println("Target: " + desc.target);
printer.println("Timestamp: " + Util.getTimeStringFromMicrosecond(properties.timestamp));
printIPTestResult(printer);
if (taskProgress == TaskProgress.COMPLETED) {
String ipAddress = removeQuotes(values.get("address"));
if (ipAddress == null) {
ipAddress = "Unknown";
}
printer.println("\nAddress: " + ipAddress);
int time = Integer.parseInt(values.get("time_ms"));
printer.println("Lookup time: " + time + " ms");
} else if (taskProgress == TaskProgress.PAUSED) {
printer.println("DNS look up paused!");
} else {
printer.println("Error: " + values.get("error"));
}
}
项目:android_app_efidroidmanager
文件:IntentServiceEx.java
public int queueSize() {
StringBuilder sb = new StringBuilder();
mServiceLooper.dump(new StringBuilderPrinter(sb), "");
String[] lines = sb.toString().split("\n");
return lines.length - 2;
}
项目:365browser
文件:ImeUtils.java
/**
* @param editorInfo The EditorInfo
* @return Debug string for the given {@EditorInfo}.
*/
static String getEditorInfoDebugString(EditorInfo editorInfo) {
StringBuilder builder = new StringBuilder();
StringBuilderPrinter printer = new StringBuilderPrinter(builder);
editorInfo.dump(printer, "");
return builder.toString();
}
项目:Mobilyzer
文件:MeasurementResult.java
private void getPingResult(StringBuilderPrinter printer, HashMap<String, String> values) {
PingDesc desc = (PingDesc) parameters;
printer.println("[Ping]");
printer.println("Target: " + desc.target);
String ipAddress = removeQuotes(values.get("target_ip"));
// TODO: internationalize 'Unknown'.
if (ipAddress == null) {
ipAddress = "Unknown";
}
printer.println("IP address: " + ipAddress);
printer.println("Timestamp: " + Util.getTimeStringFromMicrosecond(properties.timestamp));
printIPTestResult(printer);
if (taskProgress == TaskProgress.COMPLETED) {
float packetLoss = Float.parseFloat(values.get("packet_loss"));
int count = Integer.parseInt(values.get("packets_sent"));
printer.println("\n" + count + " packets transmitted, " + (int) (count * (1 - packetLoss))
+ " received, " + (packetLoss * 100) + "% packet loss");
float value = Float.parseFloat(values.get("mean_rtt_ms"));
printer.println("Mean RTT: " + String.format("%.1f", value) + " ms");
value = Float.parseFloat(values.get("min_rtt_ms"));
printer.println("Min RTT: " + String.format("%.1f", value) + " ms");
value = Float.parseFloat(values.get("max_rtt_ms"));
printer.println("Max RTT: " + String.format("%.1f", value) + " ms");
value = Float.parseFloat(values.get("stddev_rtt_ms"));
printer.println("Std dev: " + String.format("%.1f", value) + " ms");
} else if (taskProgress == TaskProgress.PAUSED) {
printer.println("Ping paused!");
} else {
printer.println("Error: " + values.get("error"));
}
}
项目:Mobilyzer
文件:MeasurementResult.java
private void getUDPBurstResult(StringBuilderPrinter printer, HashMap<String, String> values) {
UDPBurstDesc desc = (UDPBurstDesc) parameters;
if (desc.dirUp) {
printer.println("[UDPBurstUp]");
} else {
printer.println("[UDPBurstDown]");
}
printer.println("Target: " + desc.target);
printer.println("Timestamp: " + Util.getTimeStringFromMicrosecond(properties.timestamp));
printIPTestResult(printer);
if (taskProgress == TaskProgress.COMPLETED) {
printer.println("IP addr: " + values.get("target_ip"));
printIPTestResult(printer);
// printer.println("Packet size: " + desc.packetSizeByte + "B");
// printer.println("Number of packets to be sent: " + desc.udpBurstCount);
// printer.println("Interval between packets: " + desc.udpInterval + "ms");
String lossRatio = String.format("%.2f", Double.parseDouble(values.get("loss_ratio")) * 100);
String outOfOrderRatio =
String.format("%.2f", Double.parseDouble(values.get("out_of_order_ratio")) * 100);
printer.println("\nLoss ratio: " + lossRatio + "%");
printer.println("Out of order ratio: " + outOfOrderRatio + "%");
printer.println("Jitter: " + values.get("jitter") + "ms");
} else if (taskProgress == TaskProgress.PAUSED) {
printer.println("UDP Burst paused!");
} else {
printer.println("Error: " + values.get("error"));
}
}
项目:Mobilyzer
文件:MeasurementResult.java
private void getRRCResult(StringBuilderPrinter printer, HashMap<String, String> values) {
printer.println("[RRC Inference]");
if (taskProgress == TaskProgress.COMPLETED) {
printer.println("Succeed!");
}
else {
printer.println("Failed!");
}
printer.println("Results uploaded to server");
}
项目:Mobiperf-Library
文件:MeasurementResult.java
private void getPingResult(StringBuilderPrinter printer, HashMap<String, String> values) {
PingDesc desc = (PingDesc) measurementDesc;
printer.println("[Ping]");
printer.println("Target: " + desc.target);
String ipAddress = removeQuotes(values.get("target_ip"));
// TODO: internationalize 'Unknown'.
if (ipAddress == null) {
ipAddress = "Unknown";
}
printer.println("IP address: " + ipAddress);
printer.println("Timestamp: " + Util.getTimeStringFromMicrosecond(properties.timestamp));
printIPTestResult(printer);
if (taskProgress == TaskProgress.COMPLETED) {
float packetLoss = Float.parseFloat(values.get("packet_loss"));
int count = Integer.parseInt(values.get("packets_sent"));
printer.println("\n" + count + " packets transmitted, " + (int) (count * (1 - packetLoss))
+ " received, " + (packetLoss * 100) + "% packet loss");
float value = Float.parseFloat(values.get("mean_rtt_ms"));
printer.println("Mean RTT: " + String.format("%.1f", value) + " ms");
value = Float.parseFloat(values.get("min_rtt_ms"));
printer.println("Min RTT: " + String.format("%.1f", value) + " ms");
value = Float.parseFloat(values.get("max_rtt_ms"));
printer.println("Max RTT: " + String.format("%.1f", value) + " ms");
value = Float.parseFloat(values.get("stddev_rtt_ms"));
printer.println("Std dev: " + String.format("%.1f", value) + " ms");
} else if (taskProgress == TaskProgress.PAUSED) {
printer.println("Ping paused!");
} else {
printer.println("Error: " + values.get("error"));
}
}
项目:Mobiperf-Library
文件:MeasurementResult.java
private void getUDPBurstResult(StringBuilderPrinter printer, HashMap<String, String> values) {
UDPBurstDesc desc = (UDPBurstDesc) measurementDesc;
if (desc.dirUp) {
printer.println("[UDPBurstUp]");
} else {
printer.println("[UDPBurstDown]");
}
printer.println("Target: " + desc.target);
printer.println("Timestamp: " + Util.getTimeStringFromMicrosecond(properties.timestamp));
printIPTestResult(printer);
if (taskProgress == TaskProgress.COMPLETED) {
printer.println("IP addr: " + values.get("target_ip"));
printer.println("Timestamp: " + Util.getTimeStringFromMicrosecond(properties.timestamp));
printIPTestResult(printer);
printer.println("Packet size: " + desc.packetSizeByte + "B");
printer.println("Number of packets to be sent: " + desc.udpBurstCount);
printer.println("Interval between packets: " + desc.udpInterval + "ms");
String lossRatio = String.format("%.2f", Double.parseDouble(values.get("loss_ratio")) * 100);
String outOfOrderRatio =
String.format("%.2f", Double.parseDouble(values.get("out_of_order_ratio")) * 100);
printer.println("\nLoss ratio: " + lossRatio + "%");
printer.println("Out of order ratio: " + outOfOrderRatio + "%");
printer.println("Jitter: " + values.get("jitter") + "ms");
} else if (taskProgress == TaskProgress.PAUSED) {
printer.println("UDP Burst paused!");
} else {
printer.println("Error: " + values.get("error"));
}
}
项目:markdown-to-spanned
文件:SpanTests.java
private void printSpans(Spanned spanned) {
StringBuilder builder = new StringBuilder();
builder.append(spanned.toString());
TextUtils.dumpSpans(spanned, new StringBuilderPrinter(builder), "");
System.out.println(builder.toString());
}
项目:android-test-kit
文件:HumanReadables.java
/**
* Transforms an arbitrary view into a string with (hopefully) enough debug info.
*
* @param v nullable view
* @return a string for human consumption.
*/
public static String describe(View v) {
if (null == v) {
return "null";
}
ToStringHelper helper = Objects.toStringHelper(v).add("id", v.getId());
if (v.getId() != -1 && v.getResources() != null) {
try {
helper.add("res-name", v.getResources().getResourceEntryName(v.getId()));
} catch (Resources.NotFoundException ignore) {
// Do nothing.
}
}
if (null != v.getContentDescription()) {
helper.add("desc", v.getContentDescription());
}
switch (v.getVisibility()) {
case View.GONE:
helper.add("visibility", "GONE");
break;
case View.INVISIBLE:
helper.add("visibility", "INVISIBLE");
break;
case View.VISIBLE:
helper.add("visibility", "VISIBLE");
break;
default:
helper.add("visibility", v.getVisibility());
}
helper.add("width", v.getWidth())
.add("height", v.getHeight())
.add("has-focus", v.hasFocus())
.add("has-focusable", v.hasFocusable())
.add("has-window-focus", v.hasWindowFocus())
.add("is-clickable", v.isClickable())
.add("is-enabled", v.isEnabled())
.add("is-focused", v.isFocused())
.add("is-focusable", v.isFocusable())
.add("is-layout-requested", v.isLayoutRequested())
.add("is-selected", v.isSelected());
if (null != v.getRootView()) {
// pretty much only true in unit-tests.
helper.add("root-is-layout-requested", v.getRootView().isLayoutRequested());
}
EditorInfo ei = new EditorInfo();
InputConnection ic = v.onCreateInputConnection(ei);
boolean hasInputConnection = ic != null;
helper.add("has-input-connection", hasInputConnection);
if (hasInputConnection) {
StringBuilder sb = new StringBuilder();
sb.append("[");
Printer p = new StringBuilderPrinter(sb);
ei.dump(p, "");
sb.append("]");
helper.add("editor-info", sb.toString().replace("\n", " "));
}
if (Build.VERSION.SDK_INT > 10) {
helper.add("x", v.getX()).add("y", v.getY());
}
if (v instanceof TextView) {
innerDescribe((TextView) v, helper);
}
if (v instanceof Checkable) {
innerDescribe((Checkable) v, helper);
}
if (v instanceof ViewGroup) {
innerDescribe((ViewGroup) v, helper);
}
return helper.toString();
}
项目:Mobilyzer
文件:RRCTask.java
public void displayResults(StringBuilderPrinter printer) {
String DEL = "\t", toprint = DEL + DEL;
for (int i = 1; i <= times.length; i++) {
toprint += DEL + " | state" + i;
}
toprint += " |";
int oneLineLen = toprint.length();
toprint += "\n";
// seperator
for (int i = 0; i < oneLineLen; i++) {
toprint += "-";
}
toprint += "\n";
if (HTTP) {
toprint += "HTTP (ms)" + DEL;
for (int i = 0; i < httpTest.length; i++) {
toprint += DEL + " | " + Integer.toString(httpTest[i]);
}
toprint += " |\n";
for (int i = 0; i < oneLineLen; i++) {
toprint += "-";
}
toprint += "\n";
}
if (DNS) {
toprint += "DNS (ms)" + DEL;
for (int i = 0; i < dnsTest.length; i++) {
toprint += DEL + " | " + Integer.toString(dnsTest[i]);
}
toprint += " |\n";
for (int i = 0; i < oneLineLen; i++) {
toprint += "-";
}
toprint += "\n";
}
if (TCP) {
toprint += "TCP (ms)" + DEL;
for (int i = 0; i < tcpTest.length; i++) {
toprint += DEL + " | " + Integer.toString(tcpTest[i]);
}
toprint += " |\n";
for (int i = 0; i < oneLineLen; i++) {
toprint += "-";
}
toprint += "\n";
}
toprint += "Timers (s)";
for (int i = 0; i < times.length; i++) {
double curTime = (double) times[i] * (double) GRANULARITY / 1000.0;
toprint += DEL + " | " + String.format("%.2f", curTime);
}
toprint += " |\n";
printer.println(toprint);
}
项目:Mobilyzer
文件:MeasurementResult.java
private void getTracerouteResult(StringBuilderPrinter printer, HashMap<String, String> values) {
TracerouteDesc desc = (TracerouteDesc) parameters;
printer.println("[Traceroute]");
printer.println("Target: " + desc.target);
printer.println("Timestamp: " + Util.getTimeStringFromMicrosecond(properties.timestamp));
printIPTestResult(printer);
if (taskProgress == TaskProgress.COMPLETED) {
// Manually inject a new line
printer.println(" ");
int hops = Integer.parseInt(values.get("num_hops"));
int hop_str_len = String.valueOf(hops + 1).length();
for (int i = 0; i < hops; i++) {
String key = "hop_" + i + "_addr_1";
String ipAddress = removeQuotes(values.get(key));
if (ipAddress == null) {
ipAddress = "Unknown";
}
String hop_str = String.valueOf(i + 1);
String hopInfo = hop_str;
for (int j = 0; j < hop_str_len + 1 - hop_str.length(); ++j) {
hopInfo += " ";
}
hopInfo += ipAddress;
// Maximum IP address length is 15.
for (int j = 0; j < 16 - ipAddress.length(); ++j) {
hopInfo += " ";
}
key = "hop_" + i + "_rtt_ms";
// The first and last character of this string are double
// quotes.
String timeStr = removeQuotes(values.get(key));
if (timeStr == null) {
timeStr = "Unknown";
}
float time = Float.parseFloat(timeStr);
printer.println(hopInfo + String.format("%6.2f", time) + " ms");
}
} else if (taskProgress == TaskProgress.PAUSED) {
printer.println("Traceroute paused!");
} else {
printer.println("Error: " + values.get("error"));
}
}
项目:Mobilyzer
文件:MeasurementResult.java
private void getTCPThroughputResult(StringBuilderPrinter printer, HashMap<String, String> values) {
TCPThroughputDesc desc = (TCPThroughputDesc) parameters;
if (desc.dir_up) {
printer.println("[TCP Uplink]");
} else {
printer.println("[TCP Downlink]");
}
printer.println("Target: " + desc.target);
printer.println("Timestamp: " + Util.getTimeStringFromMicrosecond(properties.timestamp));
printIPTestResult(printer);
if (taskProgress == TaskProgress.COMPLETED) {
printer.println("");
// Display result with precision up to 2 digit
String speedInJSON = values.get("tcp_speed_results");
String dataLimitExceedInJSON = values.get("data_limit_exceeded");
String displayResult = "";
double tp = desc.calMedianSpeedFromTCPThroughputOutput(speedInJSON);
double KB = Math.pow(2, 10);
if (tp < 0) {
displayResult = "No results available.";
} else if (tp > KB * KB) {
displayResult = "Speed: " + String.format("%.2f", tp / (KB * KB)) + " Gbps";
} else if (tp > KB) {
displayResult = "Speed: " + String.format("%.2f", tp / KB) + " Mbps";
} else {
displayResult = "Speed: " + String.format("%.2f", tp) + " Kbps";
}
// Append notice for exceeding data limit
if (dataLimitExceedInJSON.equals("true")) {
displayResult +=
"\n* Task finishes earlier due to exceeding " + "maximum number of "
+ ((desc.dir_up) ? "transmitted" : "received") + " bytes";
}
printer.println(displayResult);
} else if (taskProgress == TaskProgress.PAUSED) {
printer.println("TCP Throughput paused!");
} else {
printer.println("Error: " + values.get("error"));
}
}
项目:Mobilyzer
文件:MeasurementResult.java
/**
* Print ip connectivity and hostname resolvability result
*/
private void printIPTestResult(StringBuilderPrinter printer) {
// printer.println("IPv4/IPv6 Connectivity: " + properties.ipConnectivity);
// printer.println("IPv4/IPv6 Domain Name Resolvability: " + properties.dnResolvability);
}
项目:Mobiperf-Library
文件:MeasurementResult.java
private void getTracerouteResult(StringBuilderPrinter printer, HashMap<String, String> values) {
TracerouteDesc desc = (TracerouteDesc) measurementDesc;
printer.println("[Traceroute]");
printer.println("Target: " + desc.target);
printer.println("Timestamp: " + Util.getTimeStringFromMicrosecond(properties.timestamp));
printIPTestResult(printer);
if (taskProgress == TaskProgress.COMPLETED) {
// Manually inject a new line
printer.println(" ");
int hops = Integer.parseInt(values.get("num_hops"));
int hop_str_len = String.valueOf(hops + 1).length();
for (int i = 0; i < hops; i++) {
String key = "hop_" + i + "_addr_1";
String ipAddress = removeQuotes(values.get(key));
if (ipAddress == null) {
ipAddress = "Unknown";
}
String hop_str = String.valueOf(i + 1);
String hopInfo = hop_str;
for (int j = 0; j < hop_str_len + 1 - hop_str.length(); ++j) {
hopInfo += " ";
}
hopInfo += ipAddress;
// Maximum IP address length is 15.
for (int j = 0; j < 16 - ipAddress.length(); ++j) {
hopInfo += " ";
}
key = "hop_" + i + "_rtt_ms";
// The first and last character of this string are double
// quotes.
String timeStr = removeQuotes(values.get(key));
if (timeStr == null) {
timeStr = "Unknown";
}
float time = Float.parseFloat(timeStr);
printer.println(hopInfo + String.format("%6.2f", time) + " ms");
}
} else if (taskProgress == TaskProgress.PAUSED) {
printer.println("Traceroute paused!");
} else {
printer.println("Error: " + values.get("error"));
}
}
项目:Mobiperf-Library
文件:MeasurementResult.java
private void getTCPThroughputResult(StringBuilderPrinter printer, HashMap<String, String> values) {
TCPThroughputDesc desc = (TCPThroughputDesc) measurementDesc;
if (desc.dir_up) {
printer.println("[TCP Uplink]");
} else {
printer.println("[TCP Downlink]");
}
printer.println("Target: " + desc.target);
printer.println("Timestamp: " + Util.getTimeStringFromMicrosecond(properties.timestamp));
printIPTestResult(printer);
if (taskProgress == TaskProgress.COMPLETED) {
printer.println("");
// Display result with precision up to 2 digit
String speedInJSON = values.get("tcp_speed_results");
String dataLimitExceedInJSON = values.get("data_limit_exceeded");
String displayResult = "";
double tp = desc.calMedianSpeedFromTCPThroughputOutput(speedInJSON);
double KB = Math.pow(2, 10);
if (tp < 0) {
displayResult = "No results available.";
} else if (tp > KB * KB) {
displayResult = "Speed: " + String.format("%.2f", tp / (KB * KB)) + " Gbps";
} else if (tp > KB) {
displayResult = "Speed: " + String.format("%.2f", tp / KB) + " Mbps";
} else {
displayResult = "Speed: " + String.format("%.2f", tp) + " Kbps";
}
// Append notice for exceeding data limit
if (dataLimitExceedInJSON.equals("true")) {
displayResult +=
"\n* Task finishes earlier due to exceeding " + "maximum number of "
+ ((desc.dir_up) ? "transmitted" : "received") + " bytes";
}
printer.println(displayResult);
} else if (taskProgress == TaskProgress.PAUSED) {
printer.println("TCP Throughput paused!");
} else {
printer.println("Error: " + values.get("error"));
}
}
项目:Mobiperf-Library
文件:MeasurementResult.java
/**
* Print ip connectivity and hostname resolvability result
*/
private void printIPTestResult(StringBuilderPrinter printer) {
printer.println("IPv4/IPv6 Connectivity: " + properties.ipConnectivity);
printer.println("IPv4/IPv6 Domain Name Resolvability: " + properties.dnResolvability);
}