Use PrintWriter rather than PrintStream in dex analysis tools.
Writers make it easier to create strings, useful when these
tools are used as building blocks for other tools.
Change-Id: I8eac49719b130551df216f42eaafb942203da0d0
diff --git a/dx/src/com/android/dx/command/findusages/FindUsages.java b/dx/src/com/android/dx/command/findusages/FindUsages.java
index e31f9bb..0fb6aa4 100644
--- a/dx/src/com/android/dx/command/findusages/FindUsages.java
+++ b/dx/src/com/android/dx/command/findusages/FindUsages.java
@@ -25,6 +25,7 @@
import com.android.dx.io.OpcodeInfo;
import com.android.dx.io.instructions.DecodedInstruction;
import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -34,12 +35,12 @@
private final Set<Integer> methodIds;
private final Set<Integer> fieldIds;
private final CodeReader codeReader = new CodeReader();
- private final PrintStream out;
+ private final PrintWriter out;
private ClassDef currentClass;
private ClassData.Method currentMethod;
- public FindUsages(DexBuffer dex, String declaredBy, String memberName, final PrintStream out) {
+ public FindUsages(DexBuffer dex, String declaredBy, String memberName, final PrintWriter out) {
this.dex = dex;
this.out = out;
diff --git a/dx/src/com/android/dx/command/findusages/Main.java b/dx/src/com/android/dx/command/findusages/Main.java
index 1d77fcb..8203890 100644
--- a/dx/src/com/android/dx/command/findusages/Main.java
+++ b/dx/src/com/android/dx/command/findusages/Main.java
@@ -19,6 +19,7 @@
import com.android.dx.io.DexBuffer;
import java.io.File;
import java.io.IOException;
+import java.io.PrintWriter;
public final class Main {
public static void main(String[] args) throws IOException {
@@ -27,6 +28,6 @@
String memberName = args[2];
DexBuffer dex = new DexBuffer(new File(dexFile));
- new FindUsages(dex, declaredBy, memberName, System.out).findUsages();
+ new FindUsages(dex, declaredBy, memberName, new PrintWriter(System.out)).findUsages();
}
}
diff --git a/dx/src/com/android/dx/command/grep/Grep.java b/dx/src/com/android/dx/command/grep/Grep.java
index 025aa65..741de97 100644
--- a/dx/src/com/android/dx/command/grep/Grep.java
+++ b/dx/src/com/android/dx/command/grep/Grep.java
@@ -23,7 +23,7 @@
import com.android.dx.io.EncodedValueReader;
import com.android.dx.io.MethodId;
import com.android.dx.io.instructions.DecodedInstruction;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
@@ -33,13 +33,13 @@
private final CodeReader codeReader = new CodeReader();
private final Set<Integer> stringIds;
- private final PrintStream out;
+ private final PrintWriter out;
private int count = 0;
private ClassDef currentClass;
private ClassData.Method currentMethod;
- public Grep(final DexBuffer dex, Pattern pattern, final PrintStream out) {
+ public Grep(final DexBuffer dex, Pattern pattern, final PrintWriter out) {
this.dex = dex;
this.out = out;
diff --git a/dx/src/com/android/dx/command/grep/Main.java b/dx/src/com/android/dx/command/grep/Main.java
index 2a9a481..e3b119a 100644
--- a/dx/src/com/android/dx/command/grep/Main.java
+++ b/dx/src/com/android/dx/command/grep/Main.java
@@ -19,6 +19,7 @@
import com.android.dx.io.DexBuffer;
import java.io.File;
import java.io.IOException;
+import java.io.PrintWriter;
import java.util.regex.Pattern;
public final class Main {
@@ -27,7 +28,7 @@
String pattern = args[1];
DexBuffer dex = new DexBuffer(new File(dexFile));
- int count = new Grep(dex, Pattern.compile(pattern), System.out).grep();
+ int count = new Grep(dex, Pattern.compile(pattern), new PrintWriter(System.out)).grep();
System.exit((count > 0) ? 0 : 1);
}
}