Skip to content

Commit

Permalink
Replaced usage of deprecated methods and constructs
Browse files Browse the repository at this point in the history
  • Loading branch information
dmatej committed Jul 13, 2022
1 parent 76be97b commit 614b0b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 33 deletions.
44 changes: 13 additions & 31 deletions src/main/java/org/codehaus/mojo/native2ascii/Native2Ascii.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* The MIT License
* Copyright (c) 2014-2022 MojoHaus
* Copyright (c) 2007 The Codehaus
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
Expand All @@ -18,7 +19,6 @@

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
Expand All @@ -27,16 +27,17 @@
import java.io.OutputStreamWriter;
import java.nio.CharBuffer;

import org.apache.commons.lang3.text.translate.CodePointTranslator;
import org.apache.commons.text.translate.CharSequenceTranslator;
import org.apache.maven.plugin.logging.Log;

/**
* @author Evgeny Mandrikov
* @author David Matejcek
*/
public final class Native2Ascii {

private final Log log;
private final CodePointTranslator escaper;
private final CharSequenceTranslator escaper;


/**
Expand All @@ -55,13 +56,13 @@ public Native2Ascii(final Log log) {
* @return unicode escaped string
*/
public String nativeToAscii(final String string) {
if (log.isDebugEnabled()) {
log.debug("Converting: " + string);
if (this.log.isDebugEnabled()) {
this.log.debug("Converting: " + string);
}
if (string == null) {
return null;
}
return escaper.translate(string);
return this.escaper.translate(string);
}


Expand All @@ -74,36 +75,17 @@ public String nativeToAscii(final String string) {
* @throws IOException
*/
public void nativeToAscii(final File src, final File dst, final String encoding) throws IOException {
log.info("Converting: '" + src + "' to: '" + dst + "'");
BufferedReader input = null;
BufferedWriter output = null;
try {
if (!dst.getParentFile().exists()) {
dst.getParentFile().mkdirs();
}
input = new BufferedReader(new InputStreamReader(new FileInputStream(src), encoding));
output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dst), "ISO-8859-1"));

this.log.info("Converting: '" + src + "' to: '" + dst + "'");
if (!dst.getParentFile().exists()) {
dst.getParentFile().mkdirs();
}
try (BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(src), encoding));
BufferedWriter output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dst), "ISO-8859-1"))) {
final char[] buffer = new char[4096];
int len;
while ((len = input.read(buffer)) != -1) {
output.write(nativeToAscii(CharBuffer.wrap(buffer, 0, len).toString()));
}
} finally {
closeQuietly(src, input);
closeQuietly(dst, output);
}
}


private void closeQuietly(final File file, final Closeable closeable) {
if (closeable != null) {
try {
closeable.close();
} catch (final IOException e) {
log.warn("Could not close the file: " + file.getAbsolutePath());
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* The MIT License
* Copyright (c) 2014-2022 MojoHaus
* Copyright (c) 2007 The Codehaus
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
Expand All @@ -16,8 +17,7 @@
*/
package org.codehaus.mojo.native2ascii;

import org.apache.commons.lang3.text.translate.UnicodeEscaper;

import org.apache.commons.text.translate.UnicodeEscaper;

/**
* Uses {@link UnicodeEscaper} to translate strings with bytes over \u007F to unicode.
Expand Down

0 comments on commit 614b0b7

Please sign in to comment.