| @@ -21,9 +21,9 @@ import java.io.BufferedReader; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.io.InputStreamReader; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.net.URL; | |||
| import java.net.URLConnection; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.util.ArrayList; | |||
| import java.util.Collections; | |||
| import java.util.List; | |||
| @@ -148,11 +148,7 @@ public class ArgumentProcessorRegistry { | |||
| throws IOException { | |||
| InputStreamReader isr = null; | |||
| try { | |||
| try { | |||
| isr = new InputStreamReader(is, "UTF-8"); | |||
| } catch (UnsupportedEncodingException e) { | |||
| isr = new InputStreamReader(is); | |||
| } | |||
| isr = new InputStreamReader(is, StandardCharsets.UTF_8); | |||
| BufferedReader rd = new BufferedReader(isr); | |||
| String processorClassName = rd.readLine(); | |||
| if (processorClassName != null && !processorClassName.isEmpty()) { | |||
| @@ -23,6 +23,7 @@ import java.io.InputStreamReader; | |||
| import java.lang.reflect.Constructor; | |||
| import java.net.URL; | |||
| import java.net.URLConnection; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.util.ArrayList; | |||
| import java.util.Collections; | |||
| import java.util.Iterator; | |||
| @@ -181,11 +182,7 @@ public class ProjectHelperRepository { | |||
| // This code is needed by EBCDIC and other strange systems. | |||
| // It's a fix for bugs reported in xerces | |||
| InputStreamReader isr; | |||
| try { | |||
| isr = new InputStreamReader(is, "UTF-8"); | |||
| } catch (java.io.UnsupportedEncodingException e) { | |||
| isr = new InputStreamReader(is); | |||
| } | |||
| isr = new InputStreamReader(is, StandardCharsets.UTF_8); | |||
| BufferedReader rd = new BufferedReader(isr); | |||
| String helperClassName = rd.readLine(); | |||
| @@ -22,6 +22,7 @@ import java.io.OutputStream; | |||
| import java.io.OutputStreamWriter; | |||
| import java.io.PrintStream; | |||
| import java.io.Writer; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.nio.file.Files; | |||
| import java.nio.file.Paths; | |||
| import java.util.Hashtable; | |||
| @@ -180,7 +181,7 @@ public class XmlLogger implements BuildLogger { | |||
| try (OutputStream stream = | |||
| outStream == null ? Files.newOutputStream(Paths.get(outFilename)) : outStream; | |||
| Writer out = new OutputStreamWriter(stream, "UTF8")) { | |||
| Writer out = new OutputStreamWriter(stream, StandardCharsets.UTF_8)) { | |||
| out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); | |||
| if (!xslUri.isEmpty()) { | |||
| out.write("<?xml-stylesheet type=\"text/xsl\" href=\"" + xslUri | |||
| @@ -21,9 +21,9 @@ import java.io.IOException; | |||
| import java.io.Reader; | |||
| import java.lang.reflect.InvocationTargetException; | |||
| import java.lang.reflect.Method; | |||
| import java.nio.charset.StandardCharsets; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.util.ResourceUtils; | |||
| /** | |||
| * Assembles the constants declared in a Java class in | |||
| @@ -97,7 +97,7 @@ public final class ClassConstants | |||
| if (clazz == null || clazz.isEmpty()) { | |||
| ch = -1; | |||
| } else { | |||
| final byte[] bytes = clazz.getBytes(ResourceUtils.ISO_8859_1); | |||
| final byte[] bytes = clazz.getBytes(StandardCharsets.ISO_8859_1); | |||
| try { | |||
| final Class<?> javaClassHelper = Class.forName(JAVA_CLASS_HELPER); | |||
| if (javaClassHelper != null) { | |||
| @@ -25,6 +25,7 @@ import java.io.OutputStream; | |||
| import java.io.OutputStreamWriter; | |||
| import java.io.PrintWriter; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.nio.file.Files; | |||
| import java.util.ArrayList; | |||
| import java.util.Collections; | |||
| @@ -91,7 +92,7 @@ public class AntStructure extends Task { | |||
| OutputStream fos = null; | |||
| try { | |||
| fos = Files.newOutputStream(output.toPath()); | |||
| out = new PrintWriter(new OutputStreamWriter(fos, "UTF8")); | |||
| out = new PrintWriter(new OutputStreamWriter(fos, StandardCharsets.UTF_8)); | |||
| } catch (final UnsupportedEncodingException ue) { | |||
| FileUtils.close(fos); | |||
| /* | |||
| @@ -29,6 +29,7 @@ import java.io.PrintWriter; | |||
| import java.io.Reader; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.nio.charset.Charset; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.nio.file.Files; | |||
| import java.util.ArrayList; | |||
| import java.util.Collections; | |||
| @@ -330,7 +331,8 @@ public class Jar extends Zip { | |||
| if (ze == null) { | |||
| return null; | |||
| } | |||
| try (InputStreamReader isr = new InputStreamReader(zf.getInputStream(ze), "UTF-8")) { | |||
| try (InputStreamReader isr = new InputStreamReader(zf.getInputStream(ze), | |||
| StandardCharsets.UTF_8)) { | |||
| return getManifest(isr); | |||
| } | |||
| } | |||
| @@ -581,8 +583,7 @@ public class Jar extends Zip { | |||
| private void createIndexList(ZipOutputStream zOut) throws IOException { | |||
| ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |||
| // encoding must be UTF8 as specified in the specs. | |||
| PrintWriter writer = new PrintWriter(new OutputStreamWriter(baos, | |||
| "UTF8")); | |||
| PrintWriter writer = new PrintWriter(new OutputStreamWriter(baos, StandardCharsets.UTF_8)); | |||
| // version-info blankline | |||
| writer.println("JarIndex-Version: 1.0"); | |||
| @@ -21,6 +21,7 @@ package org.apache.tools.ant.taskdefs; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import java.io.OutputStream; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.nio.file.Files; | |||
| import java.util.ArrayList; | |||
| import java.util.Collection; | |||
| @@ -1480,7 +1481,7 @@ public class Javac extends MatchingTask { | |||
| log("Creating empty " + pkgInfoClass); | |||
| try (OutputStream os = Files.newOutputStream(pkgInfoClass.toPath())) { | |||
| os.write(PACKAGE_INFO_CLASS_HEADER); | |||
| final byte[] name = pkg.getBytes("UTF-8"); | |||
| final byte[] name = pkg.getBytes(StandardCharsets.UTF_8); | |||
| final int length = name.length + /* "/package-info" */ 13; | |||
| os.write((byte) length / 256); | |||
| os.write((byte) length % 256); | |||
| @@ -29,6 +29,7 @@ import java.io.InputStreamReader; | |||
| import java.io.OutputStreamWriter; | |||
| import java.net.MalformedURLException; | |||
| import java.net.URL; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.nio.file.Files; | |||
| import java.util.ArrayList; | |||
| import java.util.Collections; | |||
| @@ -2411,7 +2412,7 @@ public class Javadoc extends Task { | |||
| try { | |||
| fixData = | |||
| fixLineFeeds(FileUtils | |||
| .readFully(new InputStreamReader(in, "US-ASCII"))) | |||
| .readFully(new InputStreamReader(in, StandardCharsets.US_ASCII))) | |||
| .trim(); | |||
| } finally { | |||
| FileUtils.close(in); | |||
| @@ -23,6 +23,7 @@ import java.io.File; | |||
| import java.io.IOException; | |||
| import java.io.InputStreamReader; | |||
| import java.nio.charset.Charset; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.util.List; | |||
| import java.util.Properties; | |||
| import java.util.Vector; | |||
| @@ -39,7 +40,6 @@ import org.apache.tools.ant.types.Resource; | |||
| import org.apache.tools.ant.types.ResourceCollection; | |||
| import org.apache.tools.ant.types.resources.FileResource; | |||
| import org.apache.tools.ant.types.resources.JavaResource; | |||
| import org.apache.tools.ant.util.ResourceUtils; | |||
| /** | |||
| * Load a file's contents as Ant properties. | |||
| @@ -188,7 +188,7 @@ public class LoadProperties extends Task { | |||
| text += "\n"; | |||
| } | |||
| ByteArrayInputStream tis = new ByteArrayInputStream( | |||
| text.getBytes(ResourceUtils.ISO_8859_1)); | |||
| text.getBytes(StandardCharsets.ISO_8859_1)); | |||
| final Properties props = new Properties(); | |||
| props.load(tis); | |||
| @@ -26,6 +26,7 @@ import java.io.PrintWriter; | |||
| import java.io.Reader; | |||
| import java.io.StringWriter; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.util.Collections; | |||
| import java.util.Enumeration; | |||
| import java.util.LinkedHashMap; | |||
| @@ -759,7 +760,7 @@ public class Manifest { | |||
| defManifest); | |||
| } | |||
| try { | |||
| insr = new InputStreamReader(in, "UTF-8"); | |||
| insr = new InputStreamReader(in, StandardCharsets.UTF_8); | |||
| Manifest defaultManifest = new Manifest(insr); | |||
| String version = System.getProperty("java.runtime.version"); | |||
| if (version == null) { | |||
| @@ -22,6 +22,7 @@ import java.io.IOException; | |||
| import java.io.OutputStreamWriter; | |||
| import java.io.PrintWriter; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.nio.file.Files; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.ArrayList; | |||
| @@ -421,7 +422,7 @@ public class ChangeLogTask extends AbstractCvsTask { | |||
| throws BuildException { | |||
| try (final PrintWriter writer = new PrintWriter( | |||
| new OutputStreamWriter(Files.newOutputStream(destFile.toPath()), "UTF-8"))) { | |||
| new OutputStreamWriter(Files.newOutputStream(destFile.toPath()), StandardCharsets.UTF_8))) { | |||
| new ChangeLogWriter().printChangeLog(writer, entrySet); | |||
| @@ -24,6 +24,7 @@ import java.io.IOException; | |||
| import java.io.OutputStreamWriter; | |||
| import java.io.PrintWriter; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.nio.file.Files; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| @@ -404,7 +405,7 @@ public class CvsTagDiff extends AbstractCvsTask { | |||
| */ | |||
| private void writeTagDiff(CvsTagEntry[] entries) throws BuildException { | |||
| try (PrintWriter writer = new PrintWriter(new OutputStreamWriter( | |||
| Files.newOutputStream(mydestfile.toPath()), "UTF-8"))) { | |||
| Files.newOutputStream(mydestfile.toPath()), StandardCharsets.UTF_8))) { | |||
| writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); | |||
| Document doc = DOMUtils.newDocument(); | |||
| Element root = doc.createElement("tagdiff"); | |||
| @@ -24,6 +24,7 @@ import java.io.InputStream; | |||
| import java.io.OutputStream; | |||
| import java.io.OutputStreamWriter; | |||
| import java.io.Writer; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.nio.file.Files; | |||
| import java.util.ArrayList; | |||
| import java.util.Collections; | |||
| @@ -452,7 +453,7 @@ public class EchoProperties extends Task { | |||
| rootElement.appendChild(propElement); | |||
| } | |||
| try (Writer wri = new OutputStreamWriter(os, "UTF8")) { | |||
| try (Writer wri = new OutputStreamWriter(os, StandardCharsets.UTF_8)) { | |||
| wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); | |||
| new DOMElementWriter().write(rootElement, wri, 0, "\t"); | |||
| wri.flush(); | |||
| @@ -25,6 +25,7 @@ import java.io.OutputStreamWriter; | |||
| import java.io.Writer; | |||
| import java.net.InetAddress; | |||
| import java.net.UnknownHostException; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.util.Date; | |||
| import java.util.Hashtable; | |||
| import java.util.Map; | |||
| @@ -190,7 +191,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
| if (out != null) { | |||
| Writer wri = null; | |||
| try { | |||
| wri = new BufferedWriter(new OutputStreamWriter(out, "UTF8")); | |||
| wri = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8)); | |||
| wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); | |||
| new DOMElementWriter().write(rootElement, wri, 0, " "); | |||
| } catch (final IOException exc) { | |||
| @@ -20,9 +20,9 @@ package org.apache.tools.ant.taskdefs.optional.junit; | |||
| import java.io.BufferedOutputStream; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import java.io.OutputStream; | |||
| import java.io.OutputStreamWriter; | |||
| import java.io.PrintWriter; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.nio.file.Files; | |||
| import java.util.Vector; | |||
| import java.util.stream.Stream; | |||
| @@ -198,8 +198,9 @@ public class XMLResultAggregator extends Task implements XMLConstants { | |||
| * @throws IOException thrown if there is an error while writing the content. | |||
| */ | |||
| protected void writeDOMTree(Document doc, File file) throws IOException { | |||
| try (OutputStream os = Files.newOutputStream(file.toPath()); | |||
| PrintWriter wri = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(os), "UTF8"))) { | |||
| try (PrintWriter wri = new PrintWriter(new OutputStreamWriter( | |||
| new BufferedOutputStream(Files.newOutputStream(file.toPath())), | |||
| StandardCharsets.UTF_8))) { | |||
| wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); | |||
| new DOMElementWriter().write(doc.getDocumentElement(), wri, 0, | |||
| " "); | |||
| @@ -30,7 +30,7 @@ import java.io.OutputStream; | |||
| import java.io.OutputStreamWriter; | |||
| import java.io.PrintWriter; | |||
| import java.io.StringWriter; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.util.Map; | |||
| import java.util.Optional; | |||
| import java.util.concurrent.ConcurrentHashMap; | |||
| @@ -242,11 +242,7 @@ class LegacyPlainResultFormatter extends AbstractJUnitResultFormatter implements | |||
| @Override | |||
| public void setDestination(final OutputStream os) { | |||
| this.outputStream = os; | |||
| try { | |||
| this.writer = new BufferedWriter(new OutputStreamWriter(this.outputStream, "UTF-8")); | |||
| } catch (UnsupportedEncodingException e) { | |||
| throw new RuntimeException("Failed to create a writer", e); | |||
| } | |||
| this.writer = new BufferedWriter(new OutputStreamWriter(this.outputStream, StandardCharsets.UTF_8)); | |||
| } | |||
| protected boolean shouldReportExecutionFinished(final TestIdentifier testIdentifier, final TestExecutionResult testExecutionResult) { | |||
| @@ -21,6 +21,7 @@ import java.io.ByteArrayInputStream; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.lang.reflect.Field; | |||
| import java.nio.charset.StandardCharsets; | |||
| /** | |||
| * A resource that is a java constant. | |||
| @@ -55,7 +56,7 @@ public class JavaConstantResource extends AbstractClasspathResource { | |||
| : Class.forName(classname); | |||
| Field field = clazz.getField(fieldname); | |||
| String value = field.get(null).toString(); | |||
| return new ByteArrayInputStream(value.getBytes("UTF-8")); | |||
| return new ByteArrayInputStream(value.getBytes(StandardCharsets.UTF_8)); | |||
| } catch (ClassNotFoundException e) { | |||
| throw new IOException("Class not found:" + classname); | |||
| } catch (NoSuchFieldException e) { | |||
| @@ -20,6 +20,7 @@ package org.apache.tools.ant.types.spi; | |||
| import java.io.ByteArrayInputStream; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| import java.util.stream.Collectors; | |||
| @@ -83,7 +84,7 @@ public class Service extends ProjectComponent { | |||
| public InputStream getAsStream() throws IOException { | |||
| return new ByteArrayInputStream( | |||
| providerList.stream().map(Provider::getClassName) | |||
| .collect(Collectors.joining("\n")).getBytes("UTF-8")); | |||
| .collect(Collectors.joining("\n")).getBytes(StandardCharsets.UTF_8)); | |||
| } | |||
| /** | |||
| @@ -23,6 +23,7 @@ import java.io.OutputStream; | |||
| import java.io.OutputStreamWriter; | |||
| import java.io.StringWriter; | |||
| import java.io.Writer; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.util.ArrayList; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| @@ -170,7 +171,7 @@ public class DOMElementWriter { | |||
| * @throws IOException if an error happens while writing to the stream. | |||
| */ | |||
| public void write(Element root, OutputStream out) throws IOException { | |||
| Writer wri = new OutputStreamWriter(out, "UTF8"); | |||
| Writer wri = new OutputStreamWriter(out, StandardCharsets.UTF_8); | |||
| writeXMLDeclaration(wri); | |||
| write(root, wri, 0, " "); | |||
| wri.flush(); | |||
| @@ -28,6 +28,7 @@ import java.io.OutputStreamWriter; | |||
| import java.io.PrintStream; | |||
| import java.io.PushbackReader; | |||
| import java.io.Serializable; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.nio.file.Files; | |||
| import java.util.ArrayList; | |||
| import java.util.HashMap; | |||
| @@ -145,7 +146,7 @@ public class LayoutPreservingProperties extends Properties { | |||
| @Override | |||
| public void load(final InputStream inStream) throws IOException { | |||
| final String s = readLines(inStream); | |||
| final byte[] ba = s.getBytes(ResourceUtils.ISO_8859_1); | |||
| final byte[] ba = s.getBytes(StandardCharsets.ISO_8859_1); | |||
| final ByteArrayInputStream bais = new ByteArrayInputStream(ba); | |||
| super.load(bais); | |||
| } | |||
| @@ -260,7 +261,7 @@ public class LayoutPreservingProperties extends Properties { | |||
| @Override | |||
| public void store(final OutputStream out, final String header) throws IOException { | |||
| final OutputStreamWriter osw = new OutputStreamWriter(out, ResourceUtils.ISO_8859_1); | |||
| final OutputStreamWriter osw = new OutputStreamWriter(out, StandardCharsets.ISO_8859_1); | |||
| int skipLines = 0; | |||
| final int totalLines = logicalLines.size(); | |||
| @@ -315,7 +316,7 @@ public class LayoutPreservingProperties extends Properties { | |||
| * @param is the stream from which to read the data | |||
| */ | |||
| private String readLines(final InputStream is) throws IOException { | |||
| final InputStreamReader isr = new InputStreamReader(is, ResourceUtils.ISO_8859_1); | |||
| final InputStreamReader isr = new InputStreamReader(is, StandardCharsets.ISO_8859_1); | |||
| final PushbackReader pbr = new PushbackReader(isr, 1); | |||
| if (!logicalLines.isEmpty()) { | |||
| @@ -69,8 +69,10 @@ public class ResourceUtils { | |||
| /** | |||
| * Name of charset "ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1". | |||
| * | |||
| * @deprecated use StandardCharsets.ISO_8859_1 | |||
| * @since Ant 1.8.1 | |||
| */ | |||
| @Deprecated | |||
| public static final String ISO_8859_1 = "ISO-8859-1"; | |||
| private static final long MAX_IO_CHUNK_SIZE = 16 * 1024 * 1024L; // 16 MB | |||
| @@ -25,7 +25,7 @@ package org.apache.tools.tar; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.util.Date; | |||
| import java.util.Locale; | |||
| @@ -1072,13 +1072,7 @@ public class TarEntry implements TarConstants { | |||
| */ | |||
| private static boolean matchAsciiBuffer(String expected, byte[] buffer, | |||
| int offset, int length) { | |||
| byte[] buffer1; | |||
| try { | |||
| buffer1 = expected.getBytes("ASCII"); | |||
| } catch (UnsupportedEncodingException e) { | |||
| // Should not happen | |||
| throw new RuntimeException(e); //NOSONAR | |||
| } | |||
| byte[] buffer1 = expected.getBytes(StandardCharsets.US_ASCII); | |||
| return isEqual(buffer1, 0, buffer1.length, buffer, offset, length, | |||
| false); | |||
| } | |||
| @@ -28,6 +28,7 @@ import java.io.FilterInputStream; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.io.OutputStream; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| @@ -449,7 +450,7 @@ public class TarInputStream extends FilterInputStream { | |||
| } | |||
| // Drop trailing NL | |||
| String value = new String(rest, 0, | |||
| restLen - 1, "UTF-8"); | |||
| restLen - 1, StandardCharsets.UTF_8); | |||
| headers.put(keyword, value); | |||
| break; | |||
| } | |||
| @@ -28,6 +28,7 @@ import java.io.IOException; | |||
| import java.io.OutputStream; | |||
| import java.io.StringWriter; | |||
| import java.nio.ByteBuffer; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| @@ -500,7 +501,7 @@ public class TarOutputStream extends FilterOutputStream { | |||
| + 3 /* blank, equals and newline */ | |||
| + 2 /* guess 9 < actual length < 100 */; | |||
| String line = len + " " + key + "=" + value + "\n"; | |||
| int actualLength = line.getBytes("UTF-8").length; | |||
| int actualLength = line.getBytes(StandardCharsets.UTF_8).length; | |||
| while (len != actualLength) { | |||
| // Adjust for cases where length < 10 or > 100 | |||
| // or where UTF-8 encoding isn't a single octet | |||
| @@ -509,11 +510,11 @@ public class TarOutputStream extends FilterOutputStream { | |||
| // first pass so we'd need a second. | |||
| len = actualLength; | |||
| line = len + " " + key + "=" + value + "\n"; | |||
| actualLength = line.getBytes("UTF-8").length; | |||
| actualLength = line.getBytes(StandardCharsets.UTF_8).length; | |||
| } | |||
| w.write(line); | |||
| } | |||
| byte[] data = w.toString().getBytes("UTF-8"); | |||
| byte[] data = w.toString().getBytes(StandardCharsets.UTF_8); | |||
| pex.setSize(data.length); | |||
| putNextEntry(pex); | |||
| write(data); | |||
| @@ -18,7 +18,7 @@ | |||
| package org.apache.tools.zip; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.util.zip.CRC32; | |||
| import java.util.zip.ZipException; | |||
| @@ -51,12 +51,7 @@ public abstract class AbstractUnicodeExtraField implements ZipExtraField { | |||
| crc32.update(bytes, off, len); | |||
| nameCRC32 = crc32.getValue(); | |||
| try { | |||
| unicodeName = text.getBytes("UTF-8"); | |||
| } catch (final UnsupportedEncodingException e) { | |||
| throw new RuntimeException("FATAL: UTF-8 encoding not supported.", //NOSONAR | |||
| e); | |||
| } | |||
| unicodeName = text.getBytes(StandardCharsets.UTF_8); | |||
| } | |||
| /** | |||
| @@ -24,6 +24,7 @@ import java.io.FileInputStream; | |||
| import java.io.IOException; | |||
| import java.io.InputStreamReader; | |||
| import java.io.PrintStream; | |||
| import java.nio.charset.StandardCharsets; | |||
| import org.apache.tools.ant.DefaultLogger; | |||
| import org.apache.tools.ant.Project; | |||
| @@ -77,7 +78,7 @@ public class EchoTest { | |||
| echo.setFile(removeThis); | |||
| echo.setEncoding("UTF-8"); | |||
| echo.execute(); | |||
| String x = FileUtils.readFully(new InputStreamReader(new FileInputStream(removeThis), "UTF-8")); | |||
| String x = FileUtils.readFully(new InputStreamReader(new FileInputStream(removeThis), StandardCharsets.UTF_8)); | |||
| assertEquals(x, "\u00e4\u00a9"); | |||
| } | |||
| @@ -24,6 +24,7 @@ import java.io.FileReader; | |||
| import java.io.InputStream; | |||
| import java.io.InputStreamReader; | |||
| import java.io.IOException; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.util.zip.ZipEntry; | |||
| import java.util.zip.ZipFile; | |||
| @@ -251,7 +252,7 @@ public class JarTest { | |||
| try (ZipFile archive = new ZipFile(new File(getOutputDir(), tempJar))) { | |||
| ZipEntry ze = archive.getEntry("META-INF/INDEX.LIST"); | |||
| InputStream is = archive.getInputStream(ze); | |||
| BufferedReader r = new BufferedReader(new InputStreamReader(is, "UTF8")); | |||
| BufferedReader r = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); | |||
| boolean foundSub = false; | |||
| boolean foundSubFoo = false; | |||
| boolean foundFoo = false; | |||
| @@ -22,6 +22,7 @@ import java.io.ByteArrayOutputStream; | |||
| import java.io.InputStream; | |||
| import java.io.OutputStreamWriter; | |||
| import java.io.PrintWriter; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.util.Date; | |||
| import org.apache.tools.ant.util.JAXPUtils; | |||
| @@ -48,7 +49,7 @@ public class ChangeLogWriterTest { | |||
| CVSEntry[] entries = {entry}; | |||
| ByteArrayOutputStream output = new ByteArrayOutputStream(); | |||
| PrintWriter pwriter = new PrintWriter(new OutputStreamWriter(output, "UTF-8")); | |||
| PrintWriter pwriter = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8)); | |||
| writer.printChangeLog(pwriter, entries); | |||
| // make sure that the parsing does not break | |||
| @@ -32,6 +32,7 @@ import java.io.IOException; | |||
| import java.io.OutputStream; | |||
| import java.io.OutputStreamWriter; | |||
| import java.io.Writer; | |||
| import java.nio.charset.StandardCharsets; | |||
| import static org.junit.Assert.assertArrayEquals; | |||
| import static org.junit.Assert.assertEquals; | |||
| @@ -227,7 +228,7 @@ public class PatternSetTest { | |||
| Writer w = null; | |||
| try { | |||
| o = new FileOutputStream(testFile); | |||
| w = new OutputStreamWriter(o, "UTF-16LE"); | |||
| w = new OutputStreamWriter(o, StandardCharsets.UTF_16LE); | |||
| w.write("\u00e4\n"); | |||
| } finally { | |||
| FileUtils.close(w); | |||
| @@ -24,6 +24,7 @@ import java.io.File; | |||
| import java.io.FileInputStream; | |||
| import java.io.InputStreamReader; | |||
| import java.io.StringReader; | |||
| import java.nio.charset.StandardCharsets; | |||
| import static org.junit.Assert.assertEquals; | |||
| @@ -60,9 +61,9 @@ public class ReaderInputStreamTest { | |||
| } | |||
| bytes[pos++] = (byte) res; | |||
| } | |||
| bytes = "abc".getBytes("utf-16"); | |||
| bytes = "abc".getBytes(StandardCharsets.UTF_16); | |||
| // String n = new String(bytes, 0, pos, "utf-16"); | |||
| new String(bytes, 0, bytes.length, "utf-16"); | |||
| new String(bytes, 0, bytes.length, StandardCharsets.UTF_16); | |||
| } | |||
| @SuppressWarnings("resource") | |||
| @@ -81,7 +82,7 @@ public class ReaderInputStreamTest { | |||
| @Test | |||
| public void testPreample() throws Exception { | |||
| byte[] bytes = "".getBytes("utf-16"); | |||
| byte[] bytes = "".getBytes(StandardCharsets.UTF_16); | |||
| System.out.println("Preample len is " + bytes.length); | |||
| } | |||
| @@ -22,6 +22,7 @@ import java.io.File; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.nio.ByteBuffer; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.util.Collections; | |||
| import java.util.zip.CRC32; | |||
| import org.junit.Test; | |||
| @@ -146,7 +147,7 @@ public class UTF8ZipFilesTest { | |||
| } | |||
| zos.putNextEntry(ze); | |||
| zos.write("Hello, world!".getBytes("US-ASCII")); | |||
| zos.write("Hello, world!".getBytes(StandardCharsets.US_ASCII)); | |||
| zos.closeEntry(); | |||
| ze = new ZipEntry(EURO_FOR_DOLLAR_TXT); | |||
| @@ -162,7 +163,7 @@ public class UTF8ZipFilesTest { | |||
| } | |||
| zos.putNextEntry(ze); | |||
| zos.write("Give me your money!".getBytes("US-ASCII")); | |||
| zos.write("Give me your money!".getBytes(StandardCharsets.US_ASCII)); | |||
| zos.closeEntry(); | |||
| ze = new ZipEntry(ASCII_TXT); | |||
| @@ -179,7 +180,7 @@ public class UTF8ZipFilesTest { | |||
| } | |||
| zos.putNextEntry(ze); | |||
| zos.write("ascii".getBytes("US-ASCII")); | |||
| zos.write("ascii".getBytes(StandardCharsets.US_ASCII)); | |||
| zos.closeEntry(); | |||
| } | |||
| } | |||
| @@ -225,8 +226,7 @@ public class UTF8ZipFilesTest { | |||
| crc.update(ne.array(), ne.arrayOffset(), ne.limit()); | |||
| assertEquals(crc.getValue(), ucpf.getNameCRC32()); | |||
| assertEquals(expectedName, new String(ucpf.getUnicodeName(), | |||
| UTF_8)); | |||
| assertEquals(expectedName, new String(ucpf.getUnicodeName(), StandardCharsets.UTF_8)); | |||
| } | |||
| } | |||
| @@ -21,6 +21,7 @@ package org.apache.tools.zip; | |||
| import java.io.IOException; | |||
| import java.nio.ByteBuffer; | |||
| import java.nio.charset.StandardCharsets; | |||
| import org.junit.Test; | |||
| @@ -142,9 +143,9 @@ public class ZipEncodingTest { | |||
| assertByteEquals(testBytes, encoded); | |||
| assertFalse(enc.canEncode(UNENC_STRING)); | |||
| assertByteEquals("%U2016".getBytes("US-ASCII"), enc.encode(UNENC_STRING)); | |||
| assertByteEquals("%U2016".getBytes(StandardCharsets.US_ASCII), enc.encode(UNENC_STRING)); | |||
| assertFalse(enc.canEncode(BAD_STRING)); | |||
| assertByteEquals(BAD_STRING_ENC.getBytes("US-ASCII"), | |||
| assertByteEquals(BAD_STRING_ENC.getBytes(StandardCharsets.US_ASCII), | |||
| enc.encode(BAD_STRING)); | |||
| } | |||