This source file includes following definitions.
- close
- skipped
- failed
- succeeded
- simulateNmOutput
- println
- print
- printSkip
- printFail
- closeAll
package org.chromium.tools.binary_size;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
class NmDumper {
private final String mOutPath;
private final String mSkipPath;
private final String mFailPath;
private final Output mOutput;
NmDumper(final String outPath, final String failPath, final String skipPath) {
mOutPath = outPath;
mFailPath = failPath;
mSkipPath = skipPath;
mOutput = new Output();
}
void close() {
mOutput.closeAll();
}
void skipped(String line) {
mOutput.printSkip(line);
}
void failed(Record record) {
mOutput.printFail(simulateNmOutput(record));
}
void succeeded(Record record) {
mOutput.print(simulateNmOutput(record));
}
private static final String simulateNmOutput(final Record record) {
StringBuilder builder = new StringBuilder(record.address);
builder.append(' ');
builder.append(record.size);
builder.append(' ');
builder.append(record.symbolType);
builder.append(' ');
builder.append(record.symbolName != null ? record.symbolName : "unknown");
if (record.location != null) {
builder.append('\t');
builder.append(record.location);
}
return builder.toString();
}
private class Output {
private final PrintWriter skipWriter;
private final PrintWriter failWriter;
private final PrintWriter outWriter;
private Output() {
try {
new File(mOutPath).getParentFile().mkdirs();
outWriter = new PrintWriter(mOutPath);
} catch (FileNotFoundException e) {
throw new RuntimeException("Can't open output file: " + mOutPath, e);
}
if (mFailPath != null) {
try {
new File(mFailPath).getParentFile().mkdirs();
failWriter = new PrintWriter(mFailPath);
} catch (FileNotFoundException e) {
throw new RuntimeException("Can't open fail file: " + mFailPath, e);
}
} else {
failWriter = null;
}
if (mSkipPath != null) {
try {
new File(mSkipPath).getParentFile().mkdirs();
skipWriter = new PrintWriter(mSkipPath);
} catch (IOException e) {
throw new RuntimeException("Can't open skip file: " + mSkipPath, e);
}
} else {
skipWriter = null;
}
}
private synchronized void println(PrintWriter writer, String string) {
if (writer != null) {
writer.println(string);
writer.flush();
}
}
synchronized void print(String string) {
println(outWriter, string);
}
synchronized void printSkip(String string) {
println(skipWriter, string);
println(outWriter, string);
}
synchronized void printFail(String string) {
println(failWriter, string);
println(outWriter, string);
}
private void closeAll() {
for (PrintWriter writer : new PrintWriter[]{outWriter, failWriter, skipWriter}) {
if (writer != null) {
try {
writer.flush(); }
catch (Exception ignored) {
}
try {
writer.close(); }
catch (Exception ignored) {
}
}
}
}
}