From 07e4f416e63a976b8c81322e99408f7d3830ae8d Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Mon, 16 May 2016 15:52:14 +0200 Subject: [PATCH] painless: Small cleanup of Debugger class to use StringWriter --- .../org/elasticsearch/painless/Debugger.java | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/Debugger.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/Debugger.java index f037903f52d..3e973997229 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/Debugger.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/Debugger.java @@ -22,11 +22,8 @@ package org.elasticsearch.painless; import org.objectweb.asm.ClassReader; import org.objectweb.asm.util.TraceClassVisitor; -import java.io.ByteArrayOutputStream; -import java.io.OutputStreamWriter; import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; -import java.nio.charset.StandardCharsets; +import java.io.StringWriter; /** quick and dirty tools for debugging */ final class Debugger { @@ -39,17 +36,13 @@ final class Debugger { /** compiles to bytecode, and returns debugging output */ static String toString(String source, CompilerSettings settings) { final byte[] bytes = Compiler.compile("", source, settings); - final ByteArrayOutputStream output = new ByteArrayOutputStream(); - final PrintWriter outputWriter = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8)); + final StringWriter output = new StringWriter(); + final PrintWriter outputWriter = new PrintWriter(output); final ClassReader reader = new ClassReader(bytes); reader.accept(new TraceClassVisitor(outputWriter), 0); outputWriter.flush(); - - try { - return output.toString("UTF-8"); - } catch (final UnsupportedEncodingException e) { - throw new RuntimeException(e); - } + + return output.toString(); } }