Skip to content

Commit

Permalink
fix IDEA warnings "Standard 'Charset' object can be used"
Browse files Browse the repository at this point in the history
  • Loading branch information
asolntsev committed Sep 17, 2023
1 parent 5e3e11c commit 8ef765d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private void storeFailed(File failedDirectory, File refFile, String suffix, Stri

OutputStreamWriter fw = null;
try {
fw = new OutputStreamWriter(new FileOutputStream(new File(failedDirectory, refFile.getName() + ".err" + suffix)), "UTF-8");
fw = new OutputStreamWriter(new FileOutputStream(new File(failedDirectory, refFile.getName() + ".err" + suffix)), UTF_8);
BufferedWriter bw = new BufferedWriter(fw);
try {
bw.write(compareTo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
import org.xhtmlrenderer.swing.BoxRenderer;
import org.xhtmlrenderer.swing.Java2DRenderer;
import org.xhtmlrenderer.util.FSImageWriter;
import org.xhtmlrenderer.util.IOUtil;
import org.xhtmlrenderer.util.Zipper;

import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import static java.nio.charset.StandardCharsets.UTF_8;


/**
* Creates a directory containing output from the renderer as text, given a set of input files (XHTML, XML).
Expand Down Expand Up @@ -189,7 +189,7 @@ private void writeToFile(File outputDir, String fileName, String output) throws
}
FileOutputStream fos = new FileOutputStream(outputFile);
try {
OutputStreamWriter fw = new OutputStreamWriter(fos, "UTF-8");
OutputStreamWriter fw = new OutputStreamWriter(fos, UTF_8);
PrintWriter pw = new PrintWriter(new BufferedWriter(fw));
try {
pw.print(output);
Expand All @@ -202,8 +202,6 @@ private void writeToFile(File outputDir, String fileName, String output) throws
// swallow
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fos.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
* @author Lukas Zaruba, lukas.zaruba@gmail.com
*/
Expand All @@ -50,8 +51,8 @@ private List<String> loadForKey(String lang) {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
if (is == null) return null;
try {
BufferedReader r = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
List<String> result = new ArrayList<String>();
BufferedReader r = new BufferedReader(new InputStreamReader(is, UTF_8));
List<String> result = new ArrayList<>();
String line;
while ((line = r.readLine()) != null) {
if (line.isEmpty() || line.startsWith("#")) continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,8 @@
*/
package org.xhtmlrenderer.pdf;

import java.awt.*;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.util.List;
import java.util.regex.Pattern;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfWriter;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
Expand All @@ -61,8 +42,15 @@
import org.xhtmlrenderer.util.Configuration;
import org.xml.sax.InputSource;

import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfWriter;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.awt.*;
import java.io.*;
import java.util.List;
import java.util.regex.Pattern;

import static java.nio.charset.StandardCharsets.UTF_8;

public class ITextRenderer {
// These two defaults combine to produce an effective resolution of 96 px to
Expand Down Expand Up @@ -441,14 +429,9 @@ private void paintPage(RenderingContext c, PdfWriter writer, PageBox page) throw
private void provideMetadataToPage(PdfWriter writer, PageBox page) throws IOException {
byte[] metadata = null;
if (page.getMetadata() != null) {
try {
String metadataBody = stringfyMetadata(page.getMetadata());
if (metadataBody != null) {
metadata = createXPacket(stringfyMetadata(page.getMetadata())).getBytes("UTF-8");
}
} catch (UnsupportedEncodingException e) {
// Can't happen
throw new RuntimeException(e);
String metadataBody = stringfyMetadata(page.getMetadata());
if (metadataBody != null) {
metadata = createXPacket(stringfyMetadata(page.getMetadata())).getBytes(UTF_8);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,8 @@
*/
package org.xhtmlrenderer.pdf;

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Shape;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.util.List;
import java.util.regex.Pattern;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfWriter;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
Expand All @@ -61,8 +41,15 @@
import org.xhtmlrenderer.util.Configuration;
import org.xml.sax.InputSource;

import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfWriter;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.awt.*;
import java.io.*;
import java.util.List;
import java.util.regex.Pattern;

import static java.nio.charset.StandardCharsets.UTF_8;

public class ITextRenderer {
// These two defaults combine to produce an effective resolution of 96 px to
Expand Down Expand Up @@ -438,14 +425,9 @@ private void paintPage(RenderingContext c, PdfWriter writer, PageBox page) {
private void provideMetadataToPage(PdfWriter writer, PageBox page) {
byte[] metadata = null;
if (page.getMetadata() != null) {
try {
String metadataBody = stringfyMetadata(page.getMetadata());
if (metadataBody != null) {
metadata = createXPacket(stringfyMetadata(page.getMetadata())).getBytes("UTF-8");
}
} catch (UnsupportedEncodingException e) {
// Can't happen
throw new RuntimeException(e);
String metadataBody = stringfyMetadata(page.getMetadata());
if (metadataBody != null) {
metadata = createXPacket(stringfyMetadata(page.getMetadata())).getBytes(UTF_8);
}
}

Expand Down

0 comments on commit 8ef765d

Please sign in to comment.