diff --git a/src/main/org/apache/tools/ant/taskdefs/Jar.java b/src/main/org/apache/tools/ant/taskdefs/Jar.java index dfef46af0..0ea0a29bb 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Jar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Jar.java @@ -128,10 +128,10 @@ public class Jar extends Zip { this.manifestFile = manifestFile; - InputStream is = null; + Reader r = null; try { - is = new FileInputStream(manifestFile); - Manifest newManifest = new Manifest(is); + r = new FileReader(manifestFile); + Manifest newManifest = new Manifest(r); if (manifest == null) { manifest = getDefaultManifest(); } @@ -145,9 +145,9 @@ public class Jar extends Zip { throw new BuildException("Unable to read manifest file: " + manifestFile, e); } finally { - if (is != null) { + if (r != null) { try { - is.close(); + r.close(); } catch (IOException e) { // do nothing @@ -259,7 +259,13 @@ public class Jar extends Zip { if (in == null) { throw new BuildException("Could not find default manifest: " + s); } - return new Manifest(in); + try { + return new Manifest(new InputStreamReader(in, "ASCII")); + } catch (UnsupportedEncodingException e) { + // impossible with ASCII encoding + log("ASCII encoding not supported by JVM", Project.MSG_ERR); + return new Manifest(new InputStreamReader(in)); + } } catch (ManifestException e) { throw new BuildException("Default manifest is invalid !!"); @@ -280,10 +286,10 @@ public class Jar extends Zip { private void zipManifestEntry(InputStream is) throws IOException { try { if (execManifest == null) { - execManifest = new Manifest(is); + execManifest = new Manifest(new InputStreamReader(is)); } else if (isAddingNewFiles()) { - execManifest.merge(new Manifest(is)); + execManifest.merge(new Manifest(new InputStreamReader(is))); } } catch (ManifestException e) { @@ -344,7 +350,7 @@ public class Jar extends Zip { log("Updating jar since the current jar has no manifest", Project.MSG_VERBOSE); return false; } - Manifest currentManifest = new Manifest(theZipFile.getInputStream(entry)); + Manifest currentManifest = new Manifest(new InputStreamReader(theZipFile.getInputStream(entry))); if (manifest == null) { manifest = getDefaultManifest(); } diff --git a/src/main/org/apache/tools/ant/taskdefs/Manifest.java b/src/main/org/apache/tools/ant/taskdefs/Manifest.java index d8bcf968c..2ada2e808 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Manifest.java +++ b/src/main/org/apache/tools/ant/taskdefs/Manifest.java @@ -60,8 +60,7 @@ import java.util.Enumeration; import java.io.IOException; import java.io.PrintWriter; import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; +import java.io.Reader; import java.io.StringWriter; import org.apache.tools.ant.BuildException; @@ -504,15 +503,15 @@ public class Manifest { } /** - * Read a manifest file from the given input stream + * Read a manifest file from the given reader * - * @param is the input stream from which the Manifest is read + * @param is the reader from which the Manifest is read * * @throws ManifestException if the manifest is not valid according to the JAR spec * @throws IOException if the manifest cannot be read from the reader. */ - public Manifest(InputStream is) throws ManifestException, IOException { - BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + public Manifest(Reader r) throws ManifestException, IOException { + BufferedReader reader = new BufferedReader(r); // This should be the manifest version String nextSectionName = mainSection.read(reader); String readManifestVersion = mainSection.getAttributeValue(ATTRIBUTE_MANIFEST_VERSION);