You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2008/03/13 14:22:34 UTC
svn commit: r636757 - in
/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar:
InitManifest.java Manifest.java
Author: tellison
Date: Thu Mar 13 06:22:33 2008
New Revision: 636757
URL: http://svn.apache.org/viewvc?rev=636757&view=rev
Log:
Apply slightly modified patch for
HARMONY-5517 ([classlib][archive] simplifying archive code by fixing manifest encoding to UTF-8)
Modified:
harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Manifest.java
Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java?rev=636757&r1=636756&r2=636757&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java Thu Mar 13 06:22:33 2008
@@ -21,7 +21,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UTFDataFormatException;
-import java.security.AccessController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -29,7 +28,6 @@
import java.util.Map;
import org.apache.harmony.archive.internal.nls.Messages;
-import org.apache.harmony.luni.util.PriviAction;
import org.apache.harmony.luni.util.Util;
class InitManifest {
@@ -43,10 +41,6 @@
private final ByteArrayOutputStream out = new ByteArrayOutputStream(256);
- private String encoding;
-
- private boolean usingUTF8 = true;
-
private final Map<String, Attributes.Name> attributeNames = new HashMap<String, Attributes.Name>();
private final byte[] mainAttributesChunk;
@@ -54,12 +48,6 @@
InitManifest(InputStream is, Attributes main,
Map<String, Attributes> entries, Map<String, byte[]> chunks,
String verString) throws IOException {
- encoding = AccessController.doPrivileged(new PriviAction<String>(
- "manifest.read.encoding")); //$NON-NLS-1$
- if ("".equals(encoding)) { //$NON-NLS-1$
- encoding = null;
- }
-
Attributes current = main;
ArrayList<String> list = new ArrayList<String>();
@@ -67,7 +55,7 @@
mainAttributesChunk = nextChunk(is, list);
Iterator<String> it = list.iterator();
- while (it.hasNext()) {
+ while (it.hasNext()) {
addAttribute(it.next(), current);
}
@@ -109,36 +97,16 @@
return mainAttributesChunk;
}
- private void addLine(int length, List<String> lines) throws IOException {
- if (encoding != null) {
- lines.add(new String(buffer, 0, length, encoding));
- } else {
- if (usingUTF8) {
- try {
- if (charbuf.length < length) {
- charbuf = new char[length];
- }
- int start = skipFirstEmptyLines(0, buffer);
- lines.add(Util.convertUTF8WithBuf(buffer, charbuf, Math.min(Math.max(length - 1, 0), start),
- length));
- } catch (UTFDataFormatException e) {
- usingUTF8 = false;
- }
- }
- if (!usingUTF8) {
- if (charbuf.length < length) {
- charbuf = new char[length];
- }
- // If invalid UTF8, convert bytes to chars setting the upper
- // bytes to zeros
- int charOffset = 0;
- int offset = 0;
- for (int i = length; --i >= 0;) {
- charbuf[charOffset++] = (char) (buffer[offset++] & 0xff);
- }
- int start = skipFirstEmptyLines(0, buffer);
- lines.add(new String(charbuf, Math.min(Math.max(length - 1, 0), start), length));
- }
+ private void addLine(int length, List<String> lines) throws IOException {
+ try {
+ if (charbuf.length < length) {
+ charbuf = new char[length];
+ }
+ int start = skipFirstEmptyLines(0, buffer);
+ lines.add(Util.convertUTF8WithBuf(buffer, charbuf, Math.min(Math
+ .max(length - 1, 0), start), length));
+ } catch (UTFDataFormatException e) {
+ throw new IOException(e.getLocalizedMessage());
}
}
Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Manifest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Manifest.java?rev=636757&r1=636756&r2=636757&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Manifest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Manifest.java Thu Mar 13 06:22:33 2008
@@ -22,17 +22,13 @@
import java.io.OutputStream;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
-import java.security.AccessController;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-import org.apache.harmony.luni.util.PriviAction;
-
/**
* The Manifest class is used to obtain attribute information for a JarFile and
* its entries.
- *
*/
public class Manifest implements Cloneable {
private static final int LINE_LENGTH_LIMIT = 70;
@@ -235,14 +231,6 @@
*/
static void write(Manifest manifest, OutputStream out) throws IOException {
Charset charset = null;
- String encoding = AccessController
- .doPrivileged(new PriviAction<String>("manifest.write.encoding")); //$NON-NLS-1$
- if (encoding != null) {
- if (encoding.length() == 0) {
- encoding = "UTF8"; //$NON-NLS-1$
- }
- charset = Charset.forName(encoding);
- }
String version = manifest.mainAttributes
.getValue(Attributes.Name.MANIFEST_VERSION);
if (version != null) {
@@ -275,7 +263,7 @@
Attributes.Name name, String value) throws IOException {
int offset = 0;
int limit = LINE_LENGTH_LIMIT;
- byte[] out = (name.toString() + ": ").getBytes("ISO8859_1"); //$NON-NLS-1$ //$NON-NLS-2$
+ byte[] out = (name.toString() + ": ").getBytes("UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
if (out.length > limit) {
while (out.length - offset >= limit) {
int len = out.length - offset;