/**
 * DocumentValidator
 * Copyright (c) 2013-, Takahiko Ito, All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3.0 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.
 */
package org.unigram.docvalidator.util;

import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;

/**
 * An implementation of ResultDistributor which flush the result into
 * given output stream.
 */
public class DefaultResultDistributor implements ResultDistributor {
  /**
   * constructor.
   * @param os output stream
   */
  public DefaultResultDistributor(OutputStream os) {
    super();
    if (os == null) {
      throw new IllegalArgumentException("argument OutputStream is null");
    }
    writer = new PrintWriter(os);
    formatter = new PlainFormatter();
  }

  /**
   * constructor.
   * @param ps output stream
   */
  public DefaultResultDistributor(PrintStream ps) {
    if (ps == null) {
      throw new IllegalArgumentException("argument PrintStream is null");
    }
    writer = new PrintWriter(ps);
  }

  /**
   * output given validation error.
   * @param err validation error
   */
  public int flushResult(ValidationError err) {
    if (err == null) {
      throw new IllegalArgumentException("argument ValidationError is null");
    }
    writer.println(formatter.convertError(err));
    writer.flush();
    return 0;
  }

  @Override
  public void flushHeader() {
    String header = formatter.header();
    if (header != null) {
      writer.println(header);
    }
  }

  @Override
  public void flushFooter() {
    String footer = formatter.footer();
    if (footer != null) {
      writer.println(footer);
      writer.flush();
    }
  }

  @Override
  public void setFormatter(Formatter formatter) {
    if (formatter == null) {
      throw new IllegalArgumentException("arugment formatter is null");
    }
    this.formatter = formatter;
  }

  private Formatter formatter;

  private PrintWriter writer;

}

@@ -820,27 +820,44 @@
 java.io.
-PrintWriter
+UnsupportedEncodingException
 ;%0A%0A/**%0A 
@@ -1242,32 +1242,44 @@
 s null%22);%0A    %7D%0A
+    try %7B%0A  
     writer = new
@@ -1288,19 +1288,193 @@
 rint
-Writer(os);
+Stream(os, true, %22UTF-8%22);%0A    %7D catch (UnsupportedEncodingException e) %7B%0A      throw new IllegalStateException(%22Specified output stream is illegal: %22 +%0A          e.getMessage());%0A    %7D
 %0A   
@@ -1718,32 +1718,44 @@
 s null%22);%0A    %7D%0A
+    try %7B%0A  
     writer = new
@@ -1764,19 +1764,193 @@
 rint
-Writer(ps);
+Stream(ps, true, %22UTF-8%22);%0A    %7D catch (UnsupportedEncodingException e) %7B%0A      throw new IllegalStateException(%22Specified output stream is illegal: %22 +%0A          e.getMessage());%0A    %7D
 %0A  %7D
@@ -2852,14 +2852,14 @@
 rint
-Writer
+Stream
  wri

Remove Findbugs error: Reliance on default encoding