List of usage examples for java.io PrintWriter PrintWriter
public PrintWriter(File file, Charset charset) throws IOException
From source file:com.googlecode.dex2jar.test.V3Test.java
public static void doData(byte[] data, final File destDir) throws IOException { final int lineCount = 50; DexFileReader reader = new DexFileReader(data); V3InnerClzGather afa = new V3InnerClzGather(); final List<String> exes = new ArrayList<String>(); reader.accept(afa, DexFileReader.SKIP_CODE | DexFileReader.SKIP_DEBUG); System.out.flush();//from w w w . j a v a 2s .co m String logFileName = "target/v3.log." + System.currentTimeMillis(); final PrintWriter log = new PrintWriter(logFileName, "UTF-8"); System.out.write(String.format("%05d ", 0).getBytes(UTF8)); reader.accept(new V3(afa.getClasses(), null, new ClassVisitorFactory() { int count = 0; @Override public ClassVisitor create(final String name) { return new ClassWriter(ClassWriter.COMPUTE_MAXS) { @Override public void visitEnd() { count++; try { super.visitEnd(); byte[] data = this.toByteArray(); FileUtils.writeByteArrayToFile(new File(destDir, name + ".class"), data); TestUtils.verify(new ClassReader(data), log); System.out.write('.'); } catch (Throwable e) { System.out.write('X'); exes.add(String.format("%05d %s - %s", count - 1, name, e.getMessage())); } if (count % lineCount == 0) { try { System.out.write(String.format("\n%05d ", count).getBytes(UTF8)); } catch (IOException e) { throw new RuntimeException(e); } } System.out.flush(); } }; } }, V3.REUSE_REGISTER | V3.TOPOLOGICAL_SORT | V3.OPTIMIZE_SYNCHRONIZED), DexFileReader.SKIP_DEBUG); System.out.flush(); System.out.println(); log.close(); if (exes.size() > 0) { StringBuilder sb = new StringBuilder("there are ").append(exes.size()) .append(" error(s) while translate\n"); for (String ln : exes) { sb.append(ln).append("\n"); } sb.append("details: ").append(logFileName).append("\n"); throw new RuntimeException(sb.toString()); } }