Switch all servlets from PrintWriter to OutputStreamWriter ServletResponse.getWriter() returns a PrintWriter, which has this helpful tidbit in the Javadoc: "Methods in this class never throw I/O exceptions, although some of its constructors may. The client may inquire as to whether any errors have occurred by invoking checkError()." I can count the number of times we call checkError() in the Gitiles codebase on zero hands, nor do I want to start. Use the perfectly good OutputStreamWriter class instead. Change-Id: I7c17c65d6bd657bc8dc41a2ddd7a2bda34a58033
diff --git a/gitiles-servlet/src/main/java/com/google/gitiles/RefServlet.java b/gitiles-servlet/src/main/java/com/google/gitiles/RefServlet.java index 4eaf7f3..bf0f75d 100644 --- a/gitiles-servlet/src/main/java/com/google/gitiles/RefServlet.java +++ b/gitiles-servlet/src/main/java/com/google/gitiles/RefServlet.java
@@ -34,7 +34,7 @@ import org.eclipse.jgit.transport.RefAdvertiser; import java.io.IOException; -import java.io.PrintWriter; +import java.io.Writer; import java.util.Collection; import java.util.List; import java.util.Map; @@ -188,9 +188,9 @@ } private static class TextRefAdvertiser extends RefAdvertiser { - private final PrintWriter writer; + private final Writer writer; - private TextRefAdvertiser(PrintWriter writer) { + private TextRefAdvertiser(Writer writer) { this.writer = writer; } @@ -201,7 +201,7 @@ @Override protected void writeOne(CharSequence line) throws IOException { - writer.print(line); + writer.append(line); } @Override