Skip to content

Commit

Permalink
[cleanup] Use try with resources and standard charsets utf-8
Browse files Browse the repository at this point in the history
  • Loading branch information
hazendaz committed Dec 19, 2023
1 parent 3f5da44 commit 177dbbd
Showing 1 changed file with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,22 @@
import java.io.PrintWriter;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import org.apache.commons.codec.digest.DigestUtils;
import org.codehaus.plexus.util.IOUtil;

public class TestIoUtil {

public static void writeFileContent(final String content, final File file) throws FileNotFoundException {
PrintWriter writer = new PrintWriter(file);
try {
try (PrintWriter writer = new PrintWriter(file)) {
writer.write(content);
} finally {
IOUtil.close(writer);
}
}

public static String readFileContent(final File file) throws IOException {
InputStreamReader reader = new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"));
try {
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) {
return IOUtil.toString(reader);
} finally {
IOUtil.close(reader);
}
}

Expand Down

0 comments on commit 177dbbd

Please sign in to comment.