fix for Findbugs violation DM_DEFAULT_ENCODING. Issue #778

This commit is contained in:
Roman Ivanov 2015-04-08 13:17:25 -07:00
parent 95fc97c6d8
commit fb68212a18
2 changed files with 12 additions and 5 deletions

View File

@ -19,10 +19,12 @@
package com.puppycrawl.tools.checkstyle.doclets;
import java.io.File;
import java.io.FileWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Serializable;
import java.io.Writer;
import java.util.Arrays;
import java.util.Comparator;
import com.sun.javadoc.ClassDoc;
@ -165,8 +167,9 @@ public final class CheckDocsDoclet
final File destDir = new File(getDestDir(root.options()));
final File checksIndexFile = new File(destDir, "checks.xml");
final PrintWriter fileWriter = new PrintWriter(
new FileWriter(checksIndexFile));
final Writer writer =
new OutputStreamWriter(new FileOutputStream(checksIndexFile), "UTF-8");
final PrintWriter fileWriter = new PrintWriter(writer);
writeXdocsHeader(fileWriter, "Available Checks");
fileWriter.println("<p>Checkstyle provides many checks that you can"

View File

@ -21,6 +21,7 @@ package com.puppycrawl.tools.checkstyle.doclets;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.DocErrorReporter;
@ -51,15 +52,18 @@ public final class TokenTypesDoclet
* @param root <code>RootDoc</code> given to the doclet
* @exception FileNotFoundException will be thrown if the doclet
* will be unable to write to the specified file.
* @exception UnsupportedEncodingException will be thrown if the doclet
* will be unable to use UTF-8 encoding.
* @return true if the given <code>RootDoc</code> is processed.
*/
public static boolean start(RootDoc root) throws FileNotFoundException
public static boolean start(RootDoc root)
throws FileNotFoundException, UnsupportedEncodingException
{
final String fileName = getDestFileName(root.options());
final FileOutputStream fos = new FileOutputStream(fileName);
PrintStream ps = null;
try {
ps = new PrintStream(fos);
ps = new PrintStream(fos, false, "UTF-8");
final ClassDoc[] classes = root.classes();
if (classes.length != 1
|| !"TokenTypes".equals(classes[0].name()))