OSDN Git Service

StateMachine.dump produces no output sometimes.
authorWink Saville <wink@google.com>
Mon, 12 Jan 2015 19:34:20 +0000 (11:34 -0800)
committerJohn Huang <jsh@google.com>
Tue, 13 Jan 2015 22:35:25 +0000 (22:35 +0000)
If the content to dump is large no output is produced by dump. Change
back to using a loop and flush.

Bug: 18965342
Change-Id: Ibc33da8bfffd5f998a78df0e2d70ed8e8a0aa137

core/java/com/android/internal/util/StateMachine.java

index 7ad3470..916f19d 100644 (file)
@@ -25,6 +25,7 @@ import android.util.Log;
 
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collection;
@@ -1940,19 +1941,25 @@ public class StateMachine {
      * @param args
      */
     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        pw.println(this.toString());
+        // Cannot just invoke pw.println(this.toString()) because if the
+        // resulting string is to long it won't be displayed.
+        pw.println(getName() + ":");
+        pw.println(" total records=" + getLogRecCount());
+        for (int i = 0; i < getLogRecSize(); i++) {
+            pw.println(" rec[" + i + "]: " + getLogRec(i).toString());
+            pw.flush();
+        }
+        pw.println("curState=" + getCurrentState().getName());
     }
 
     @Override
     public String toString() {
-        StringBuilder sb = new StringBuilder();
-        sb.append(getName() + ":\n");
-        sb.append(" total records=" + getLogRecCount() + "\n");
-        for (int i = 0; i < getLogRecSize(); i++) {
-            sb.append(" rec[" + i + "]: " + getLogRec(i).toString() + "\n");
-        }
-        sb.append("curState=" + getCurrentState().getName());
-        return sb.toString();
+        StringWriter sr = new StringWriter();
+        PrintWriter pr = new PrintWriter(sr);
+        dump(null, pr, null);
+        pr.flush();
+        pr.close();
+        return sr.toString();
     }
 
     /**