Skip to content

Replaced usage of deprecated methods and constructs #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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