harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r465556 - in /incubator/harmony/enhanced/classlib/trunk/modules/archive/src: main/java/java/util/zip/ main/java/org/apache/harmony/archive/internal/pack200/ test/java/org/apache/harmony/archive/tests/internal/pack200/
Date Thu, 19 Oct 2006 10:27:14 GMT
Author: pyang
Date: Thu Oct 19 03:27:10 2006
New Revision: 465556

URL: http://svn.apache.org/viewvc?view=rev&rev=465556
Log:
Apply patch for HARMONY-1871([classlib][pack200] Ongoing improvements to pack200; work-in-progress)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/AttributeLayout.java   (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/AttributeLayoutMap.java   (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ClassConstantPool.java   (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ClassFile.java   (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ClassFileEntry.java   (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ConstantPoolEntry.java   (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AttributeLayoutMapTest.java   (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AttributeLayoutTest.java   (with props)
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/InflaterInputStream.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/BHSDCodec.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Codec.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/CodecEncoding.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Pack200Exception.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/PopulationCodec.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/RunCodec.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Segment.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/SegmentOptions.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AllTests.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/CodecEncodingTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/CodecTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/HelloWorld.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/PopulationCodecTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/SegmentOptionsTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/SegmentTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/InflaterInputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/InflaterInputStream.java?view=diff&rev=465556&r1=465555&r2=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/InflaterInputStream.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/InflaterInputStream.java Thu Oct 19 03:27:10 2006
@@ -258,8 +258,8 @@
 	 *            of no use
 	 */
 	@Override
-    public void mark(@SuppressWarnings("unused")
-    int readlimit) {
+    @SuppressWarnings("unused")
+    public void mark(int readlimit) {
 		// do nothing
 	}
 

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/AttributeLayout.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/AttributeLayout.java?view=auto&rev=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/AttributeLayout.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/AttributeLayout.java Thu Oct 19 03:27:10 2006
@@ -0,0 +1,198 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.harmony.archive.internal.pack200;
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
+import org.apache.harmony.archive.internal.pack200.Segment.SegmentConstantPool;
+
+public class AttributeLayout {
+	static class Key {
+		public Key(String name, int context) throws Pack200Exception {
+			if (name == null || name.length() == 0)
+				throw new Pack200Exception("Cannot have an unnamed layout");
+			if (context != CONTEXT_CLASS && context != CONTEXT_CODE
+					&& context != CONTEXT_FIELD && context != CONTEXT_METHOD)
+				throw new Pack200Exception("Attribute context out of range: "
+						+ context);
+			this.name = name;
+			this.context = context;
+
+		}
+
+		private int context;
+
+		private String name;
+
+		@Override
+		public int hashCode() {
+			final int PRIME = 31;
+			int result = 1;
+			result = PRIME * result + context;
+			result = PRIME * result + ((name == null) ? 0 : name.hashCode());
+			return result;
+		}
+
+		@Override
+		public boolean equals(Object obj) {
+			if (this == obj)
+				return true;
+			if (obj == null)
+				return false;
+			if (getClass() != obj.getClass())
+				return false;
+			final Key other = (Key) obj;
+			if (context != other.context)
+				return false;
+			if (name == null) {
+				if (other.name != null)
+					return false;
+			} else if (!name.equals(other.name))
+				return false;
+			return true;
+		}
+
+		public String toString() {
+			return contextNames[context] + ": " + name;
+		}
+
+	}
+
+	private String layout;
+
+	Key key;
+
+	private long mask;
+
+	public static final int CONTEXT_CODE = 1 << 4;
+
+	public static final int CONTEXT_CLASS = 1 << 0;
+
+	public static final int CONTEXT_FIELD = 1 << 2;
+
+	public static final int CONTEXT_METHOD = 1 << 3;
+
+	private static final String[] contextNames = { "Class", "Field", "Method",
+			"Code", };
+
+	public Codec getCodec() {
+		if (layout.indexOf("O") >= 0) {
+			return Codec.BRANCH5;
+		} else if (layout.indexOf("P") >= 0) {
+			return Codec.BCI5;
+		} else if (layout.indexOf("S") >= 0 && layout.indexOf("KS") < 0
+				&& layout.indexOf("RS") < 0) {
+			return Codec.SIGNED5;
+		} else if (layout.indexOf("B") >= 0) {
+			return Codec.BYTE1;
+		}
+		/*
+		 * TODO Add this as a test (and don't commit since this is copyright
+		 * text) && ) If the layout contains 'O', use BRANCH5. Otherwise, if the
+		 * layout contains 'P', use BCI5. Otherwise, if the layout contains 'S'
+		 * but not 'KS' or 'RS', use SIGNED5. Otherwise, if the layout contains
+		 * 'B', use BYTE1. For all other layouts use UNSIGNED5.
+		 */
+		else {
+			return Codec.UNSIGNED5;
+		}
+	}
+
+	public Object getValue(long value, Segment segment) throws Pack200Exception {
+		if (layout.startsWith("R")) {
+			// references
+			if (layout.indexOf('N') != -1)
+				value--;
+			SegmentConstantPool pool = segment.getConstantPool();
+			if (layout.startsWith("RU")) {
+				return pool.getValue(SegmentConstantPool.UTF_8, value);
+			} else if (layout.startsWith("RS")) {
+				return pool.getValue(SegmentConstantPool.SIGNATURE, value);
+			}
+		}
+		throw new Pack200Exception("Unknown layout encoding: " + layout);
+	}
+
+	public AttributeLayout(String name, int context, String layout, int index)
+			throws Pack200Exception {
+		super();
+		this.key = new Key(name, context);
+		if (index >= 0) {
+			this.mask = 1L << index;
+		} else {
+			this.mask = 0;
+		}
+		if (layout == null) // || layout.length() == 0)
+			throw new Pack200Exception("Cannot have a null layout");
+		this.layout = layout;
+	}
+
+	public boolean isCode() {
+		return key.context == CONTEXT_CODE;
+	}
+
+	public boolean isClass() {
+		return key.context == CONTEXT_CLASS;
+	}
+
+	public boolean isMethod() {
+		return key.context == CONTEXT_METHOD;
+	}
+
+	public boolean isField() {
+		return key.context == CONTEXT_FIELD;
+	}
+
+	public int hashCode() {
+		return key.hashCode();
+	}
+
+	public boolean matches(long value) {
+		return (value & mask) != 0;
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (this == obj)
+			return true;
+		if (obj == null)
+			return false;
+		if (getClass() != obj.getClass())
+			return false;
+		final AttributeLayout other = (AttributeLayout) obj;
+		if (key == null) {
+			if (other.key != null)
+				return false;
+		} else if (!key.equals(other.key))
+			return false;
+		if (layout == null) {
+			if (other.layout != null)
+				return false;
+		} else if (!layout.equals(other.layout))
+			return false;
+		return true;
+	}
+
+	public String toString() {
+		return key.toString();
+	}
+
+	public String getLayout() {
+		return layout;
+	}
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/AttributeLayout.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/AttributeLayoutMap.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/AttributeLayoutMap.java?view=auto&rev=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/AttributeLayoutMap.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/AttributeLayoutMap.java Thu Oct 19 03:27:10 2006
@@ -0,0 +1,107 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.harmony.archive.internal.pack200;
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Stores a mapping from attribute names to their corresponding layout types.
+ * Note that names of attribute layouts and their formats are <emph>not</emph>
+ * internationalised, and should not be translated.
+ */
+public class AttributeLayoutMap {
+	// private static final String METADATA = "[NH[(1)]][RSHNH[RUH(1)]][TB(66,67,73,83,90)[KIH](68)[KDH](70)[KFH](74)[KJH](99)[RSH](101)[RSHRUH](115)[RUH](91)[NH[(0)]](64)[RSH[RUH(0)]]()[]]";
+
+	// create a whole bunch of AttributeLayouts here
+	private static AttributeLayout[] getDefaultAttributeLayouts()
+			throws Pack200Exception {
+		return new AttributeLayout[] {
+				new AttributeLayout("LineNumberTable",
+						AttributeLayout.CONTEXT_CODE, "NH[PHH]", 1),
+				new AttributeLayout("LocalVariableTable",
+						AttributeLayout.CONTEXT_CODE, "NH[PHOHRUHRSHH]", 2),
+				new AttributeLayout("LocalVariableTypeTable",
+						AttributeLayout.CONTEXT_CODE, "NH[PHOHRUHRSHH]", 3),
+				new AttributeLayout("SourceFile",
+						AttributeLayout.CONTEXT_CLASS, "RUNH", 17),
+				new AttributeLayout("ConstantValue",
+						AttributeLayout.CONTEXT_FIELD, "KQH", 17),
+				new AttributeLayout("Code", AttributeLayout.CONTEXT_METHOD,
+						"*", 17),
+				new AttributeLayout("EnclosingMethod",
+						AttributeLayout.CONTEXT_CLASS, "RCHRDNH", 18),
+				new AttributeLayout("Exceptions",
+						AttributeLayout.CONTEXT_METHOD, "NH[RCH]", 18),
+				new AttributeLayout("Signature", AttributeLayout.CONTEXT_CLASS,
+						"RSH", 19),
+				new AttributeLayout("Signature", AttributeLayout.CONTEXT_FIELD,
+						"RSH", 19),
+				new AttributeLayout("Signature",
+						AttributeLayout.CONTEXT_METHOD, "RSH", 19),
+				new AttributeLayout("Deprecated",
+						AttributeLayout.CONTEXT_CLASS, "", 20),
+				new AttributeLayout("Deprecated",
+						AttributeLayout.CONTEXT_FIELD, "", 20),
+				new AttributeLayout("Deprecated",
+						AttributeLayout.CONTEXT_METHOD, "", 20),
+				new AttributeLayout("RuntimeVisibleAnnotations",
+						AttributeLayout.CONTEXT_CLASS, "*", 21),
+				new AttributeLayout("RuntimeVisibleAnnotations",
+						AttributeLayout.CONTEXT_FIELD, "*", 21),
+				new AttributeLayout("RuntimeVisibleAnnotations",
+						AttributeLayout.CONTEXT_METHOD, "*", 21),
+				new AttributeLayout("RuntimeInvisibleAnnotations",
+						AttributeLayout.CONTEXT_CLASS, "*", 22),
+				new AttributeLayout("RuntimeInvisibleAnnotations",
+						AttributeLayout.CONTEXT_FIELD, "*", 22),
+				new AttributeLayout("RuntimeInvisibleAnnotations",
+						AttributeLayout.CONTEXT_METHOD, "*", 22),
+				new AttributeLayout("InnerClasses",
+						AttributeLayout.CONTEXT_CLASS, "*", 23),
+				new AttributeLayout("RuntimeVisibleParameterAnnotations",
+						AttributeLayout.CONTEXT_METHOD, "*", 23),
+				new AttributeLayout("class-file version",
+						AttributeLayout.CONTEXT_CLASS, "*", 24),
+				new AttributeLayout("RuntimeInvisibleParameterAnnotations",
+						AttributeLayout.CONTEXT_METHOD, "*", 24),
+				new AttributeLayout("AnnotationDefault",
+						AttributeLayout.CONTEXT_METHOD, "*", 25) };
+	}
+
+	private Map layouts;
+
+	public AttributeLayoutMap() throws Pack200Exception {
+		this.layouts = new HashMap();
+		AttributeLayout[] defaultAttributeLayouts = getDefaultAttributeLayouts();
+		for (int i = 0; i < defaultAttributeLayouts.length; i++) {
+			add(defaultAttributeLayouts[i]);
+		}
+	}
+
+	public void add(AttributeLayout layout) {
+		layouts.put(layout.key, layout);
+	}
+
+	public AttributeLayout getAttributeLayout(String name, int context)
+			throws Pack200Exception {
+		return (AttributeLayout) layouts.get(new AttributeLayout.Key(name,
+				context));
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/AttributeLayoutMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/BHSDCodec.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/BHSDCodec.java?view=diff&rev=465556&r1=465555&r2=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/BHSDCodec.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/BHSDCodec.java Thu Oct 19 03:27:10 2006
@@ -15,13 +15,13 @@
  *  limitations under the License.
  */
 package org.apache.harmony.archive.internal.pack200;
-
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
 import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
 
-import org.apache.harmony.archive.internal.nls.Messages;
-
 /**
  * TODO Comment -- quite a lot can be nicked from Codec, since this was created
  * from it
@@ -102,17 +102,17 @@
 	 */
 	public BHSDCodec(int b, int h, int s, int d) {
 		if (b < 1 || b > 5)
-			throw new IllegalArgumentException(Messages.getString("archive.15")); //$NON-NLS-1$
+			throw new IllegalArgumentException("1<=b<=5");
 		if (h < 1 || h > 256)
-			throw new IllegalArgumentException(Messages.getString("archive.16")); //$NON-NLS-1$
+			throw new IllegalArgumentException("1<=h<=256");
 		if (s < 0 || s > 2)
-			throw new IllegalArgumentException(Messages.getString("archive.17")); //$NON-NLS-1$
+			throw new IllegalArgumentException("0<=s<=2");
 		if (d < 0 || d > 1)
-			throw new IllegalArgumentException(Messages.getString("archive.18")); //$NON-NLS-1$
+			throw new IllegalArgumentException("0<=d<=1");
 		if (b == 1 && h != 256)
-			throw new IllegalArgumentException(Messages.getString("archive.19")); //$NON-NLS-1$
+			throw new IllegalArgumentException("b=1 -> h=256");
 		if (h == 256 && b == 5)
-			throw new IllegalArgumentException(Messages.getString("archive.1A")); //$NON-NLS-1$
+			throw new IllegalArgumentException("h=256 -> b!=5");
 		this.b = b;
 		this.h = h;
 		this.s = s;
@@ -129,15 +129,16 @@
 	public long cardinality() {
 		if (h > 1) {
 			return (long) (l * Math.pow(1 - h, b) / (1 - h) + Math.pow(h, b));
+		} else {
+			return (b * 255) + 1;
 		}
-        return (b * 255) + 1;
 	}
 
 	@Override
 	public long decode(InputStream in) throws IOException, Pack200Exception {
 		if (d != 0)
 			throw new Pack200Exception(
-					Messages.getString("archive.1B")); //$NON-NLS-1$
+					"Delta encoding used without passing in last value; this is a coding error");
 		return decode(in, 0);
 	}
 
@@ -150,7 +151,7 @@
 		do {
 			x = in.read();
 			if (x == -1)
-				throw new EOFException(Messages.getString("archive.1C")); //$NON-NLS-1$
+				throw new EOFException("End of stream reached whilst decoding");
 			z += x * Math.pow(h, n);
 		} while (++n < b && x >= l);
 		// This looks more complicated than it is
@@ -215,7 +216,7 @@
 			} else if (s == 2) {
 				result = (3L * cardinality()) / 4 - 1;
 			} else {
-                throw new Error(Messages.getString("archive.1D")); //$NON-NLS-1$
+				throw new Error("Unknown s value");
 			}
 		}
 		return Math.min((s == 0 ? ((long) Integer.MAX_VALUE) << 1
@@ -243,19 +244,18 @@
 	 * Returns the codec in the form (1,256) or (1,64,1,1). Note that trailing
 	 * zero fields are not shown.
 	 */
-	@Override
-    public String toString() {
+	public String toString() {
 		StringBuffer buffer = new StringBuffer(11);
 		buffer.append('(');
 		buffer.append(b);
 		buffer.append(',');
 		buffer.append(h);
 		if (s != 0 || d != 0) {
-			buffer.append(","); //$NON-NLS-1$
+			buffer.append(',');
 			buffer.append(s);
 		}
 		if (d != 0) {
-			buffer.append(","); //$NON-NLS-1$
+			buffer.append(',');
 			buffer.append(d);
 		}
 		buffer.append(')');

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ClassConstantPool.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ClassConstantPool.java?view=auto&rev=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ClassConstantPool.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ClassConstantPool.java Thu Oct 19 03:27:10 2006
@@ -0,0 +1,74 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.harmony.archive.internal.pack200;
+
+// NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+// NOTE: Do not extract strings as messages; this code is still a
+// work-in-progress
+// NOTE: Also, don't get rid of 'else' statements for the hell of it ...
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class ClassConstantPool {
+	private List others = new ArrayList();
+
+	private List entries = new ArrayList();
+
+	public void add(ClassFileEntry entry) {
+		// TODO this should be a set - we don't want duplicates
+		// Only add in constant pools, but resolve all types since they may
+		// introduce new constant pool entries
+		if (entry instanceof ConstantPoolEntry) {
+			if (!entries.contains(entry))
+				entries.add(entry);
+		} else {
+			if (!others.contains(entry))
+				others.add(entry);
+		}
+		ClassFileEntry[] nestedEntries = entry.getNestedClassFileEntries();
+		for (int i = 0; i < nestedEntries.length; i++) {
+			add(nestedEntries[i]);
+		}
+	}
+
+	public int indexOf(ClassFileEntry entry) {
+		return entries.indexOf(entry) + 1;
+	}
+
+	public int size() {
+		return entries.size();
+	}
+
+	public ClassFileEntry get(int i) {
+		return (ClassFileEntry) entries.get(--i);
+	}
+
+	public void resolve() {
+		Iterator it = entries.iterator();
+		while (it.hasNext()) {
+			ClassFileEntry entry = (ClassFileEntry) it.next();
+			entry.resolve(this);
+		}
+		it = others.iterator();
+		while (it.hasNext()) {
+			ClassFileEntry entry = (ClassFileEntry) it.next();
+			entry.resolve(this);
+		}
+	}
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ClassConstantPool.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ClassFile.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ClassFile.java?view=auto&rev=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ClassFile.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ClassFile.java Thu Oct 19 03:27:10 2006
@@ -0,0 +1,72 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.harmony.archive.internal.pack200;
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.harmony.archive.internal.pack200.ClassFileEntry.Attribute;
+
+public class ClassFile {
+	int major;
+	int minor;
+	private int magic = 0xCAFEBABE;
+	ClassConstantPool pool = new ClassConstantPool();
+	int accessFlags;
+	int thisClass;
+	int superClass;
+	int[] interfaces;
+	int[] fields;
+	int[] methods;
+	Attribute[] attributes;
+	public void write(DataOutputStream dos) throws IOException {
+		dos.writeInt(magic);
+		dos.writeShort(minor);
+		dos.writeShort(major);
+		dos.writeShort(pool.size()+1);
+		for(int i=1;i<=pool.size();i++) {
+			ConstantPoolEntry entry;
+			(entry = (ConstantPoolEntry)pool.get(i)).write(dos);
+			// Doubles and longs take up two spaces in the pool, but only one gets written
+			if (entry.getTag() == ConstantPoolEntry.CP_Double || entry.getTag() == ConstantPoolEntry.CP_Long)
+				i++;
+		};
+		dos.writeShort(accessFlags);
+		dos.writeShort(thisClass);
+		dos.writeShort(superClass);
+		dos.writeShort(interfaces.length);
+		for(int i=0;i<interfaces.length;i++) {
+			dos.writeShort(interfaces[i]);
+		}
+		dos.writeShort(fields.length);
+		for(int i=0;i<fields.length;i++) {
+			// dos.write
+			// write field info
+		}
+		dos.writeShort(methods.length);
+		for(int i=0;i<fields.length;i++) {
+			// write method info
+		}
+		dos.writeShort(attributes.length);
+		for(int i=0;i<attributes.length;i++) {
+			Attribute a = attributes[i];
+			a.write(dos);
+		}
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ClassFile.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ClassFileEntry.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ClassFileEntry.java?view=auto&rev=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ClassFileEntry.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ClassFileEntry.java Thu Oct 19 03:27:10 2006
@@ -0,0 +1,87 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.harmony.archive.internal.pack200;
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.harmony.archive.internal.pack200.ConstantPoolEntry.UTF8;
+
+
+public abstract class ClassFileEntry {
+	static abstract class Attribute extends ClassFileEntry {
+		public Attribute(String attributeName) {
+			this.attributeName = new UTF8(attributeName);
+		}
+		private UTF8 attributeName;
+		private int attributeNameIndex;
+		protected UTF8 getAttributeName() {
+			return attributeName;
+		}
+		protected void resolve(ClassConstantPool pool) {
+			super.resolve(pool);
+			attributeNameIndex = pool.indexOf(attributeName);
+		}
+		protected abstract int getLength();
+		public void write(DataOutputStream dos) throws IOException {
+			dos.writeShort(attributeNameIndex);
+			dos.writeInt(getLength());
+			writeBody(dos);
+		}
+		protected abstract void writeBody(DataOutputStream dos) throws IOException;
+		
+	}
+	static class SourceFile extends Attribute {
+		private UTF8 name;
+		public int nameIndex;
+		public SourceFile(String name) {
+			super("SourceFile"); //$NON-NLS-1$
+			this.name = new UTF8(name);
+		}
+
+		protected ClassFileEntry[] getNestedClassFileEntries() {
+			return new ClassFileEntry[] { getAttributeName(), name };
+		}
+		protected void resolve(ClassConstantPool pool) {
+			super.resolve(pool);
+			nameIndex = pool.indexOf(name);
+		}
+		protected void writeBody(DataOutputStream dos) throws IOException {
+			dos.writeShort(nameIndex);			
+		}
+
+		@Override
+		protected int getLength() {
+			return 2;
+		}
+	}
+	private static final ClassFileEntry[] NONE = new ClassFileEntry[0];
+	protected ClassFileEntry[] getNestedClassFileEntries() {
+		return NONE;
+	}
+	/**
+	 * Allows the constant pool entries to resolve their nested entries
+	 * 
+	 * @param pool
+	 */
+	protected void resolve(ClassConstantPool pool) {
+	}
+	public abstract void write(DataOutputStream dos) throws IOException;
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ClassFileEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Codec.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Codec.java?view=diff&rev=465556&r1=465555&r2=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Codec.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Codec.java Thu Oct 19 03:27:10 2006
@@ -15,7 +15,9 @@
  *  limitations under the License.
  */
 package org.apache.harmony.archive.internal.pack200;
-
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
 import java.io.IOException;
 import java.io.InputStream;
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/CodecEncoding.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/CodecEncoding.java?view=diff&rev=465556&r1=465555&r2=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/CodecEncoding.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/CodecEncoding.java Thu Oct 19 03:27:10 2006
@@ -15,13 +15,13 @@
  *  limitations under the License.
  */
 package org.apache.harmony.archive.internal.pack200;
-
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
 import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
 
-import org.apache.harmony.archive.internal.nls.Messages;
-
 public class CodecEncoding {
 	/**
 	 * The canonical encodings are defined to allow a single byte to represent
@@ -103,10 +103,10 @@
 		// Sanity check to make sure that no-one's been buggering with
 		// the canonical codecs, which would really cause havoc
 		if (canonicalCodec.length != 116) 
-			throw new Error(Messages.getString("archive.00")); //$NON-NLS-1$
+			throw new Error("Canonical encodings have been incorrectly modified");
 		if (value < 0) {
 			throw new IllegalArgumentException(
-					Messages.getString("archive.01")); //$NON-NLS-1$
+					"Encoding cannot be less than zero");
 		} else if (value == 0) {
 			return defaultCodec;
 		} else if (value <= 115) {
@@ -114,13 +114,13 @@
 		} else if (value == 116) {
 			int code = in.read();
 			if (code == -1)
-				throw new EOFException(Messages.getString("archive.02")); //$NON-NLS-1$
+				throw new EOFException("End of buffer read whilst trying to decode codec");
 			int d = (code & 0x01);
 			int s = (code >> 1 & 0x03);
 			int b = (code >> 3 & 0x07) + 1; // this might result in an invalid number, but it's checked in the Codec constructor
 			code = in.read();
 			if (code == -1)
-				throw new EOFException(Messages.getString("archive.03")); //$NON-NLS-1$
+				throw new EOFException("End of buffer read whilst trying to decode codec");
 			int h = code + 1;
 			// This handles the special cases for invalid combinations of data.
 			return new BHSDCodec(b,h,s,d);			
@@ -132,7 +132,7 @@
 			boolean bdef = (offset >> 4 & 1) == 1;
 			// If both A and B use the default encoding, what's the point of having a run of default values followed by default values
 			if (adef && bdef)
-				throw new Pack200Exception(Messages.getString("archive.04")); //$NON-NLS-1$
+				throw new Pack200Exception("ADef and BDef should never both be true");
 			int kb = (kbflag ? in.read() : 3);
 			int k = (kb+1) * (int)Math.pow(16, kx);
 			Codec aCodec, bCodec;
@@ -165,13 +165,14 @@
 				// number of items read from the fCodec. So we don't know in advance what
 				// the codec will be.
 				return new PopulationCodec(fCodec,l,uCodec);
+			} else {
+				Codec fCodec = (fdef ? defaultCodec : getCodec(in.read(),in,defaultCodec) );
+				Codec uCodec = (udef ? defaultCodec : getCodec(in.read(),in,defaultCodec) );
+				Codec tCodec = getCodec(in.read(),in,defaultCodec);
+				return new PopulationCodec(fCodec,uCodec,tCodec);
 			}
-            Codec fCodec = (fdef ? defaultCodec : getCodec(in.read(),in,defaultCodec) );
-            Codec uCodec = (udef ? defaultCodec : getCodec(in.read(),in,defaultCodec) );
-            Codec tCodec = getCodec(in.read(),in,defaultCodec);
-            return new PopulationCodec(fCodec,uCodec,tCodec);
 		} else {
-            throw new Pack200Exception(Messages.getString("archive.05", value)); //$NON-NLS-1$
+			throw new Pack200Exception("Invalid codec encoding byte (" + value + ") found" );
 		}
 	}
 }

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ConstantPoolEntry.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ConstantPoolEntry.java?view=auto&rev=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ConstantPoolEntry.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ConstantPoolEntry.java Thu Oct 19 03:27:10 2006
@@ -0,0 +1,192 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.harmony.archive.internal.pack200;
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * @author alex
+ * 
+ */
+abstract class ConstantPoolEntry extends ClassFileEntry {
+	static class Class extends ConstantPoolEntry {
+		private int index;
+
+		public String name;
+
+		private UTF8 utf8;
+
+		Class(String name) {
+			super(CP_Class);
+			this.name = name;
+			this.utf8 = new UTF8(name);
+		}
+
+		@Override
+		public boolean equals(Object obj) {
+			if (this == obj)
+				return true;
+			if (obj == null)
+				return false;
+			if (getClass() != obj.getClass())
+				return false;
+			final Class other = (Class) obj;
+			if (name == null) {
+				if (other.name != null)
+					return false;
+			} else if (!name.equals(other.name))
+				return false;
+			if (utf8 == null) {
+				if (other.utf8 != null)
+					return false;
+			} else if (!utf8.equals(other.utf8))
+				return false;
+			return true;
+		}
+
+		protected ClassFileEntry[] getNestedClassFileEntries() {
+			return new ClassFileEntry[] { utf8, };
+		}
+
+		@Override
+		public int hashCode() {
+			final int PRIME = 31;
+			int result = 1;
+			result = PRIME * result + ((name == null) ? 0 : name.hashCode());
+			result = PRIME * result + ((utf8 == null) ? 0 : utf8.hashCode());
+			return result;
+		}
+
+		protected void resolve(ClassConstantPool pool) {
+			super.resolve(pool);
+			index = pool.indexOf(utf8);
+		}
+
+		void writeBody(DataOutputStream dos) throws IOException {
+			dos.writeShort(index);
+		}
+	}
+	
+	static class UTF8 extends ConstantPoolEntry {
+		private String utf8;
+		
+		UTF8(String utf8) {
+			super(CP_UTF8);
+			this.utf8 = utf8;
+		}
+
+		@Override
+		public boolean equals(Object obj) {
+			if (this == obj)
+				return true;
+			if (obj == null)
+				return false;
+			if (getClass() != obj.getClass())
+				return false;
+			final UTF8 other = (UTF8) obj;
+			if (utf8 == null) {
+				if (other.utf8 != null)
+					return false;
+			} else if (!utf8.equals(other.utf8))
+				return false;
+			return true;
+		}
+
+		@Override
+		public int hashCode() {
+			final int PRIME = 31;
+			int result = 1;
+			result = PRIME * result + ((utf8 == null) ? 0 : utf8.hashCode());
+			return result;
+		}
+
+		void writeBody(DataOutputStream dos) throws IOException {
+			byte[] bytes;
+			try {
+				// TODO Check that this is the right UTF-8 for bytes
+				if (utf8 == null) {
+					bytes = new byte[0];
+				} else {
+					bytes = utf8.getBytes("UTF-8");
+				}
+			} catch (UnsupportedEncodingException e) {
+				throw new RuntimeException("Couldn't convert string " + utf8
+						+ " to UTF-8");
+			}
+			dos.writeShort(bytes.length);
+			dos.write(bytes);
+		}
+
+	}
+
+	public static final byte CP_Class = 7;
+
+	public static final byte CP_Double = 6;
+
+	public static final byte CP_Fieldref = 9;
+
+	public static final byte CP_Float = 4;
+
+	public static final byte CP_Integer = 3;
+
+	/*
+	 * class MemberRef extends ConstantPoolEntry { private int index;
+	 * 
+	 * Class(String name) { super(CP_Class); index = pool.indexOf(name); }
+	 * 
+	 * void writeBody(DataOutputStream dos) throws IOException {
+	 * dos.writeShort(index); }
+	 *  }
+	 */
+
+	public static final byte CP_InterfaceMethodref = 11;
+
+	public static final byte CP_Long = 5;
+
+	public static final byte CP_Methodref = 10;
+
+	public static final byte CP_NameAndType = 12;
+
+	public static final byte CP_String = 8;
+
+	public static final byte CP_UTF8 = 1;
+
+	byte tag;
+
+	ConstantPoolEntry(byte tag) {
+		this.tag = tag;
+	}
+
+	public abstract boolean equals(Object obj);
+
+	public byte getTag() {
+		return tag;
+	}
+
+	public abstract int hashCode();
+
+	public void write(DataOutputStream dos) throws IOException {
+		dos.writeByte(tag);
+		writeBody(dos);
+	}
+
+	abstract void writeBody(DataOutputStream dos) throws IOException;
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/ConstantPoolEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Pack200Exception.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Pack200Exception.java?view=diff&rev=465556&r1=465555&r2=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Pack200Exception.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Pack200Exception.java Thu Oct 19 03:27:10 2006
@@ -15,7 +15,9 @@
  *  limitations under the License.
  */
 package org.apache.harmony.archive.internal.pack200;
-
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
 /**
  * Represents a problem with a Pack200 coding/decoding issue.
  * 
@@ -26,7 +28,7 @@
 
     private static final long serialVersionUID = 5168177401552611803L;
 
-    /**
+	/**
 	 * Create a new Pack200 exception with the given message and cause
 	 * 
 	 * @param message

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/PopulationCodec.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/PopulationCodec.java?view=diff&rev=465556&r1=465555&r2=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/PopulationCodec.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/PopulationCodec.java Thu Oct 19 03:27:10 2006
@@ -14,14 +14,13 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.apache.harmony.archive.internal.pack200;
-
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
 import java.io.IOException;
 import java.io.InputStream;
 
-import org.apache.harmony.archive.internal.nls.Messages;
-
 public class PopulationCodec extends Codec {
 	private Codec favouredCodec;
 	private Codec tokenCodec;
@@ -36,7 +35,7 @@
 
 	public PopulationCodec(Codec favouredCodec, int l, Codec unvafouredCodec) {
 		if (l >= 256 || l <=0)
-			throw new IllegalArgumentException(Messages.getString("archive.0F")); //$NON-NLS-1$
+			throw new IllegalArgumentException("L must be between 1..255");
 		this.favouredCodec = favouredCodec;
 		this.l = l;
 		this.unvafouredCodec = unvafouredCodec;
@@ -44,13 +43,13 @@
 
 	@Override
 	public long decode(InputStream in) throws IOException, Pack200Exception {
-		throw new Pack200Exception(Messages.getString("archive.10")); //$NON-NLS-1$
+		throw new Pack200Exception("Population encoding does not work unless the number of elements are known");
 	}
 
 	@Override
 	public long decode(InputStream in, long last) throws IOException,
 			Pack200Exception {
-		throw new Pack200Exception(Messages.getString("archive.10")); //$NON-NLS-1$
+		throw new Pack200Exception("Population encoding does not work unless the number of elements are known");
 	}
 
 	@Override
@@ -88,7 +87,7 @@
 						tokenCodec = codec;
 				}
 				if (tokenCodec == null)
-					throw new Pack200Exception(Messages.getString("archive.11", new Integer(k), new Integer(l))); //$NON-NLS-1$
+					throw new Pack200Exception("Cannot calculate token codec from " + k + " and " + l);
 			}
 		}
 		// read favourites

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/RunCodec.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/RunCodec.java?view=diff&rev=465556&r1=465555&r2=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/RunCodec.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/RunCodec.java Thu Oct 19 03:27:10 2006
@@ -15,12 +15,12 @@
  *  limitations under the License.
  */
 package org.apache.harmony.archive.internal.pack200;
-
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
 import java.io.IOException;
 import java.io.InputStream;
 
-import org.apache.harmony.archive.internal.nls.Messages;
-
 /**
  * A run codec is a grouping of two nested codecs; K values are decoded from
  * the first codec, and the remaining codes are decoded from the remaining
@@ -38,32 +38,28 @@
 
 	public RunCodec(int k, Codec aCodec, Codec bCodec) throws Pack200Exception {
 		if (k <= 0)
-			throw new Pack200Exception(Messages.getString("archive.12")); //$NON-NLS-1$
+			throw new Pack200Exception("Cannot have a RunCodec for a negative number of numbers");
 		if (aCodec == null || bCodec == null)
-			throw new Pack200Exception(Messages.getString("archive.13")); //$NON-NLS-1$
+			throw new Pack200Exception("Must supply both codecs for a RunCodec");
 		this.k = k;
 		this.aCodec = aCodec;
 		this.bCodec = bCodec;
 	}
-    
-	@Override
-    public long decode(InputStream in) throws IOException, Pack200Exception {
+	public long decode(InputStream in) throws IOException, Pack200Exception {
 		return decode(in,this.last);
 	}
 
-	@Override
-    public long decode(InputStream in, long last) throws IOException, Pack200Exception {
+	public long decode(InputStream in, long last) throws IOException, Pack200Exception {
 		if(--k>=0) {
 			long value = aCodec.decode(in,last);
 			this.last = (k == 0 ? 0 : value);
 			return value;
+		} else {
+			this.last = bCodec.decode(in,last);
+			return this.last;			
 		}
-        this.last = bCodec.decode(in,last);
-        return this.last;
 	}
-    
-	@Override
-    public String toString() {
-        return "RunCodec[k="+k+";aCodec="+aCodec+"bCodec="+bCodec+"]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+	public String toString() {
+		return "RunCodec[k="+k+";aCodec="+aCodec+"bCodec="+bCodec+"]";
 	}
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Segment.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Segment.java?view=diff&rev=465556&r1=465555&r2=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Segment.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Segment.java Thu Oct 19 03:27:10 2006
@@ -15,15 +15,20 @@
  *  limitations under the License.
  */
 package org.apache.harmony.archive.internal.pack200;
-
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
 import java.io.ByteArrayInputStream;
+import java.io.DataOutputStream;
 import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
 import java.util.zip.GZIPInputStream;
 
-import org.apache.harmony.archive.internal.nls.Messages;
+import org.apache.harmony.archive.internal.pack200.ClassFileEntry.SourceFile;
 
 /**
  * A Pack200 archive consists of one (or more) segments. Each segment is
@@ -57,6 +62,29 @@
  * @version $Revision: $
  */
 public class Segment {
+	public class SegmentConstantPool {
+		public static final int ALL = 0;
+
+		public static final int SIGNATURE = 2; // TODO and more to come --
+												// define in archive order
+
+		public static final int UTF_8 = 1;
+
+		public Object getValue(int cp, long value) throws Pack200Exception {
+			int index = (int)value;
+			if (index == -1)
+				return null;
+			if (index < 0)
+				throw new Pack200Exception("Cannot have a negative range");
+			if (cp == UTF_8)
+				return cpUTF8[index];
+			if (cp == SIGNATURE)
+				return cpSignature[index];
+			// etc
+			throw new Error("Get value incomplete");
+		}
+	}
+
 	/**
 	 * The magic header for a Pack200 Segment is 0xCAFED00D. I wonder where they
 	 * get their inspiration from ...
@@ -106,12 +134,12 @@
 			throws IOException, Pack200Exception {
 		int total = in.read(data);
 		if (total == -1)
-			throw new EOFException(Messages.getString("archive.0E")); //$NON-NLS-1$
+			throw new EOFException("Failed to read any data from input stream");
 		while (total < data.length) {
 			int delta = in.read(data, total, data.length - total);
 			if (delta == -1)
 				throw new EOFException(
-						Messages.getString("archive.0D")); //$NON-NLS-1$
+						"Failed to read some data from input stream");
 			total += delta;
 		}
 	}
@@ -126,16 +154,22 @@
 
 	private String[] attributeDefinitionLayout;
 
+	private AttributeLayoutMap attributeDefinitionMap;
+
 	private String[] attributeDefinitionName;
 
 	private InputStream bandHeadersInputStream;
 
 	private int bandHeadersSize;
 
+	private int classAttrCount;
+
 	private int classCount;
 
 	private int[] classFieldCount;
 
+	private long[] classFlags;
+
 	private String[][] classInterfaces;
 
 	private int[] classMethodCount;
@@ -228,7 +262,7 @@
 
 	private int innerClassCount;
 
-	private int major;
+	private int archiveMajor;
 
 	private int methodAttrCount;
 
@@ -236,17 +270,15 @@
 
 	private long[][] methodFlags;
 
-	private int minor;
+	private int archiveMinor;
 
 	private int numberOfFiles;
 
 	private SegmentOptions options;
 
-	private int segmentsRemaining;
-
-	private int classAttrCount;
+	private final SegmentConstantPool pool = new SegmentConstantPool();
 
-	private long[] classFlags;
+	private int segmentsRemaining;
 
 	/**
 	 * This is a local debugging message to aid the developer in writing this
@@ -258,7 +290,7 @@
 	 * @deprecated this should be removed from production code
 	 */
 	@Deprecated
-    private void debug(String message) {
+	private void debug(String message) {
 		if (System.getProperty("debug.pack200") != null) {
 			System.err.println(message);
 		}
@@ -423,9 +455,96 @@
 
 	}
 
+	public SegmentConstantPool getConstantPool() {
+		return pool;
+	}
+
 	public int getNumberOfFiles() {
 		return numberOfFiles;
 	}
+	/**
+	 * Writes the segment to an output stream. The output stream should be pre-buffered for
+	 * efficiency. Also takes the same input stream for reading, since the file bits may
+	 * not be loaded and thus just copied from one stream to another.
+	 * Doesn't close the output stream when finished, in case there are more entries (e.g.
+	 * further segments) to be written.
+	 * @param out the JarOutputStream to write data to
+	 * @param in the same InputStream that was used to parse the segment
+	 * @throws IOException if an error occurs whilst reading or writing to the streams
+	 * @throws Pack200Exception if an error occurs whilst unpacking data
+	 */
+	public void writeJar(JarOutputStream out, InputStream in ) throws IOException, Pack200Exception {
+		processFileBits(in);
+		DataOutputStream dos = new DataOutputStream(out);
+		// out.setLevel(JarEntry.DEFLATED)
+		// now write the files out
+		int classNum = 0;
+		for(int i=0;i<numberOfFiles;i++) {
+			String name = fileName[i];
+			long modtime = archiveModtime + fileModtime[i];
+			boolean deflate = (fileOptions[i] & 1) == 1 || options.shouldDeflate(); 
+			boolean isClass = (fileOptions[i] & 2) == 2  || name == null || name.equals("");
+			if (isClass) {
+				// pull from headers
+				if (name == null || name.equals(""))
+					name = cpClass[classNum] + ".class";				
+			};
+			JarEntry entry = new JarEntry(name);
+			if (deflate)
+				entry.setMethod(JarEntry.DEFLATED);
+			entry.setTime(modtime);
+			out.putNextEntry(entry);
+			
+			if(isClass){
+				// write to dos
+				ClassFile classFile = buildClassFile(classNum);
+				classFile.write(dos);
+				dos.flush();
+				classNum++;
+			} else {
+				long size = fileSize[i];
+				entry.setSize(size);
+				// TODO pull from in
+				byte[] data = fileBits[i];
+				out.write(data);
+			}
+		}
+		dos.flush();
+		out.finish();
+		out.flush();
+	}
+
+	private ClassFile buildClassFile(int classNum) {
+		ClassFile classFile = new ClassFile();
+		classFile.major = defaultClassMajorVersion; // TODO If classVersionMajor[] use that instead
+		classFile.minor = defaultClassMinorVersion; // TODO if classVersionMinor[] use that instead
+		// build constant pool
+		ClassFileEntry cfThis = new ConstantPoolEntry.Class(classThis[classNum]);
+		ClassFileEntry cfSuper = new ConstantPoolEntry.Class(classSuper[classNum]);
+		ClassFileEntry cfInterfaces[] = new ClassFileEntry[classInterfaces[classNum].length];
+		for(int i=0;i<cfInterfaces.length;i++) {
+			cfInterfaces[i] = new ConstantPoolEntry.Class(classInterfaces[classNum][i]);
+		}
+		ClassConstantPool cp = classFile.pool;
+		cp.add(cfThis);
+		cp.add(cfSuper);
+		// build up remainder of file
+		classFile.accessFlags = (int) classFlags[classNum];
+		classFile.thisClass = cp.indexOf(cfThis);
+		classFile.superClass = cp.indexOf(cfSuper);
+		// TODO placate format of file for writing purposes
+		classFile.interfaces = new int[0];
+		classFile.fields = new int[0];
+		classFile.methods = new int[0];
+		SourceFile sf;
+		classFile.attributes = new ClassFileEntry.Attribute[] { sf = new ClassFileEntry.SourceFile(classThis[classNum]  + ".java") };
+		cp.add(sf);
+
+		// sort CP according to cp_All
+		cp.resolve();
+
+		return classFile;
+	}
 
 	private SegmentOptions getOptions() {
 		return options;
@@ -482,7 +601,8 @@
 		attributeDefinitionLayout = parseReferences("attr_definition_layout",
 				in, Codec.UNSIGNED5, attributeDefinitionCount, cpUTF8);
 		if (attributeDefinitionCount > 0)
-            throw new Error(Messages.getString("archive.0C")); //$NON-NLS-1$
+			throw new Error("No idea what the adc is for yet");
+		attributeDefinitionMap = new AttributeLayoutMap();
 	}
 
 	private void parseBcBands(InputStream in) {
@@ -499,10 +619,22 @@
 				classAttrCount++;
 		}
 		if (classAttrCount > 0)
-		    throw new Error(Messages.getString("archive.0A")); //$NON-NLS-1$
+			throw new Error(
+					"There are attribute flags, and I don't know what to do with them");
 		debug("unimplemented class_attr_count");
 		debug("unimplemented class_attr_indexes");
 		debug("unimplemented class_attr_calls");
+		AttributeLayout layout = attributeDefinitionMap.getAttributeLayout(
+				"SourceFile", AttributeLayout.CONTEXT_CLASS);
+		for (int i = 0; i < classCount; i++) {
+			long flag = classFlags[i];
+			if (layout.matches(flag)) {
+				// we've got a value to read
+				long result = layout.getCodec().decode(in);
+				Object value = layout.getValue(result, this);
+				debug("Processed value " + value + " for SourceFile"); 
+			}
+		}
 		debug("unimplemented class_SourceFile_RUN");
 		debug("unimplemented class_EnclosingMethod_RC");
 		debug("unimplemented class_EnclosingMethod_RDN");
@@ -550,18 +682,6 @@
 		setClassCount(decodeScalar("class_count", in, Codec.UNSIGNED5));
 	}
 
-	private void parseCodeBands(InputStream in) {
-		debug("unimplemented code_headers");
-		debug("unimplemented code_max_stack");
-		debug("unimplemented code_max_na_locals");
-		debug("unimplemented code_hander_count");
-		debug("unimplemented code_hander_start_P");
-		debug("unimplemented code_hander_end_PO");
-		debug("unimplemented code_hander_catch_PO");
-		debug("unimplemented code_hander_class_RC");
-		parseCodeAttrBands(in);
-	}
-
 	private void parseCodeAttrBands(InputStream in) {
 		debug("unimplemented code_flags");
 		debug("unimplemented code_attr_count");
@@ -582,6 +702,18 @@
 		}
 	}
 
+	private void parseCodeBands(InputStream in) {
+		debug("unimplemented code_headers");
+		debug("unimplemented code_max_stack");
+		debug("unimplemented code_max_na_locals");
+		debug("unimplemented code_hander_count");
+		debug("unimplemented code_hander_start_P");
+		debug("unimplemented code_hander_end_PO");
+		debug("unimplemented code_hander_catch_PO");
+		debug("unimplemented code_hander_class_RC");
+		parseCodeAttrBands(in);
+	}
+
 	/**
 	 * Parses the constant pool class names, using {@link #cpClassCount} to
 	 * populate {@link #cpClass} from {@link #cpUTF8}.
@@ -779,7 +911,7 @@
 			String form = cpSignatureForm[i];
 			int len = form.length();
 			StringBuffer signature = new StringBuffer(64);
-			ArrayList<String> list = new ArrayList<String>();
+			ArrayList list = new ArrayList();
 			for (int j = 0; j < len; j++) {
 				char c = form.charAt(j);
 				signature.append(c);
@@ -1005,38 +1137,6 @@
 				cpUTF8);
 	}
 
-	private void parseMethodBands(InputStream in) throws IOException,
-			Pack200Exception {
-		methodDescr = new String[classCount][];
-		for (int i = 0; i < classCount; i++) {
-			methodDescr[i] = parseReferences("method_descr", in, Codec.MDELTA5,
-					classMethodCount[i], cpDescriptor);
-		}
-		methodFlags = new long[classCount][];
-		for (int i = 0; i < classCount; i++) {
-			methodFlags[i] = parseFlags("method_flags", in,
-					classMethodCount[i], Codec.UNSIGNED5, options
-							.hasMethodFlagsHi());
-		}
-		for (int i = 0; i < classCount; i++) {
-			for (int j = 0; j < methodFlags[i].length; j++) {
-				long flag = methodFlags[i][j];
-				if ((flag & (1 << 16)) != 0)
-					methodAttrCount++;
-			}
-		}
-		if (methodAttrCount > 0)
-			throw new Error(
-					"There are method attribute flags, and I don't know what to do with them");
-		debug("unimplemented method_attr_count");
-		debug("unimplemented method_attr_indexes");
-		debug("unimplemented method_attr_calls");
-		debug("unimplemented method_Exceptions_N");
-		debug("unimplemented method_Exceptions_RC");
-		debug("unimplemented method_Signature_RS");
-		parseMetadataBands("method");
-	}
-
 	private void parseMetadataBands(String unit) throws Pack200Exception {
 		String[] RxA;
 		if ("method".equals(unit)) {
@@ -1073,6 +1173,38 @@
 		}
 	}
 
+	private void parseMethodBands(InputStream in) throws IOException,
+			Pack200Exception {
+		methodDescr = new String[classCount][];
+		for (int i = 0; i < classCount; i++) {
+			methodDescr[i] = parseReferences("method_descr", in, Codec.MDELTA5,
+					classMethodCount[i], cpDescriptor);
+		}
+		methodFlags = new long[classCount][];
+		for (int i = 0; i < classCount; i++) {
+			methodFlags[i] = parseFlags("method_flags", in,
+					classMethodCount[i], Codec.UNSIGNED5, options
+							.hasMethodFlagsHi());
+		}
+		for (int i = 0; i < classCount; i++) {
+			for (int j = 0; j < methodFlags[i].length; j++) {
+				long flag = methodFlags[i][j];
+				if ((flag & (1 << 16)) != 0)
+					methodAttrCount++;
+			}
+		}
+		if (methodAttrCount > 0)
+			throw new Error(
+					"There are method attribute flags, and I don't know what to do with them");
+		debug("unimplemented method_attr_count");
+		debug("unimplemented method_attr_indexes");
+		debug("unimplemented method_attr_calls");
+		debug("unimplemented method_Exceptions_N");
+		debug("unimplemented method_Exceptions_RC");
+		debug("unimplemented method_Signature_RS");
+		parseMetadataBands("method");
+	}
+
 	/**
 	 * Helper method to parse <i>count</i> references from <code>in</code>,
 	 * using <code>codec</code> to decode the values as indexes into
@@ -1107,7 +1239,7 @@
 			int index = decode[i];
 			if (index < 0 || index >= reference.length)
 				throw new Pack200Exception(
-                        Messages.getString("archive.06")); //$NON-NLS-1$
+						"Something has gone wrong during parsing references");
 			result[i] = reference[index];
 		}
 		return result;
@@ -1130,7 +1262,7 @@
 		debug("-------");
 		parseSegmentHeader(in);
 		if (bandHeadersSize > 0) {
-			byte[] bandHeaders = new byte[bandHeadersSize];
+			byte[] bandHeaders = new byte[(int) bandHeadersSize];
 			readFully(in, bandHeaders);
 			setBandHeadersData(bandHeaders);
 		}
@@ -1151,9 +1283,7 @@
 		parseClassBands(in);
 		parseBcBands(in);
 		// TODO Re-enable these after completing class/bytecode bands
-		// parseFileBands(in);
-		// processFileBits(in); // this just caches them in file_bits; it should
-		// probably start writing here?
+		parseFileBands(in);
 	}
 
 	private void parseSegmentHeader(InputStream in) throws IOException,
@@ -1162,10 +1292,10 @@
 				magic.length);
 		for (int m = 0; m < magic.length; m++)
 			if (word[m] != magic[m])
-                throw new Error(Messages.getString("archive.07")); //$NON-NLS-1$
-		setMinorVersion((int) decodeScalar("archive_minver", in,
+				throw new Error("Bad header");
+		setArchiveMinorVersion((int) decodeScalar("archive_minver", in,
 				Codec.UNSIGNED5));
-		setMajorVersion((int) decodeScalar("archive_majver", in,
+		setArchiveMajorVersion((int) decodeScalar("archive_majver", in,
 				Codec.UNSIGNED5));
 		setOptions(new SegmentOptions((int) decodeScalar("archive_options", in,
 				Codec.UNSIGNED5)));
@@ -1283,10 +1413,10 @@
 	 * @throws Pack200Exception
 	 *             if the major version is not 150
 	 */
-	private void setMajorVersion(int version) throws Pack200Exception {
+	private void setArchiveMajorVersion(int version) throws Pack200Exception {
 		if (version != 150)
-            throw new Pack200Exception(Messages.getString("archive.08")); //$NON-NLS-1$
-		major = version;
+			throw new Pack200Exception("Invalid segment major version");
+		archiveMajor = version;
 	}
 
 	/**
@@ -1297,10 +1427,10 @@
 	 * @throws Pack200Exception
 	 *             if the minor version is not 7
 	 */
-	private void setMinorVersion(int version) throws Pack200Exception {
+	private void setArchiveMinorVersion(int version) throws Pack200Exception {
 		if (version != 7)
-            throw new Pack200Exception(Messages.getString("archive.09")); //$NON-NLS-1$
-		minor = version;
+			throw new Pack200Exception("Invalid segment minor version");
+		archiveMinor = version;
 	}
 
 	public void setNumberOfFiles(long value) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/SegmentOptions.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/SegmentOptions.java?view=diff&rev=465556&r1=465555&r2=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/SegmentOptions.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/SegmentOptions.java Thu Oct 19 03:27:10 2006
@@ -15,9 +15,9 @@
  *  limitations under the License.
  */
 package org.apache.harmony.archive.internal.pack200;
-
-import org.apache.harmony.archive.internal.nls.Messages;
-
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
 /**
  * Stores the combinations of bit flags that can be used in the segment header
  * options. Whilst this could be defined in {@link Segment}, it's cleaner to
@@ -74,7 +74,7 @@
 	 */
 	public SegmentOptions(int options) throws Pack200Exception {
 		if ((options & UNUSED) != 0)
-			throw new Pack200Exception(Messages.getString("archive.14")); //$NON-NLS-1$
+			throw new Pack200Exception("Some unused flags are non-zero");
 		this.options = options;
 	}
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AllTests.java?view=diff&rev=465556&r1=465555&r2=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AllTests.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AllTests.java Thu Oct 19 03:27:10 2006
@@ -1,25 +1,25 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- * 
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
  */
-
 package org.apache.harmony.archive.tests.internal.pack200;
-
+// NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+// NOTE: Do not extract strings as messages; this code is still a work-in-progress
+// NOTE: Also, don't get rid of 'else' statements for the hell of it ...
 import junit.framework.Test;
 import junit.framework.TestSuite;
-
 /**
  * Test suite for org.apache.harmony.archive.internal.pack200 package.
  */
@@ -33,6 +33,8 @@
 		TestSuite suite = new TestSuite(
                 "Suite org.apache.harmony.archive.tests.internal.pack200");
 		// $JUnit-BEGIN$
+		suite.addTestSuite(AttributeLayoutMapTest.class);
+		suite.addTestSuite(AttributeLayoutTest.class);
 		suite.addTestSuite(CodecEncodingTest.class);
 		suite.addTestSuite(CodecTest.class);
 		suite.addTestSuite(PopulationCodecTest.class);

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AttributeLayoutMapTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AttributeLayoutMapTest.java?view=auto&rev=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AttributeLayoutMapTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AttributeLayoutMapTest.java Thu Oct 19 03:27:10 2006
@@ -0,0 +1,50 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.harmony.archive.tests.internal.pack200;
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
+import junit.framework.TestCase;
+
+import org.apache.harmony.archive.internal.pack200.AttributeLayout;
+import org.apache.harmony.archive.internal.pack200.AttributeLayoutMap;
+import org.apache.harmony.archive.internal.pack200.Pack200Exception;
+
+public class AttributeLayoutMapTest extends TestCase {
+	public void testRepeatable() throws Pack200Exception {
+		// Check we can retrieve a default layout
+		AttributeLayoutMap a = new AttributeLayoutMap();
+		AttributeLayout layout = a.getAttributeLayout("SourceFile", AttributeLayout.CONTEXT_CLASS);
+		assertNotNull(layout);
+		assertEquals("RUNH",layout.getLayout());
+		// and that we can change it
+		a.add(new AttributeLayout("SourceFile",AttributeLayout.CONTEXT_CLASS,"FROG",15));
+		layout = a.getAttributeLayout("SourceFile", AttributeLayout.CONTEXT_CLASS);
+		assertNotNull(layout);
+		assertEquals("FROG",layout.getLayout());
+		assertTrue(layout.matches(1<<15));
+		assertFalse(layout.matches(1<<16));
+		assertTrue(layout.matches(-1));
+		assertFalse(layout.matches(0));
+		// and that changes don't affect subsequent defaults
+		AttributeLayoutMap b = new AttributeLayoutMap();
+		layout = b.getAttributeLayout("SourceFile", AttributeLayout.CONTEXT_CLASS);
+		assertNotNull(layout);
+		assertEquals("RUNH",layout.getLayout());
+		
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AttributeLayoutMapTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AttributeLayoutTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AttributeLayoutTest.java?view=auto&rev=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AttributeLayoutTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AttributeLayoutTest.java Thu Oct 19 03:27:10 2006
@@ -0,0 +1,91 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.harmony.archive.tests.internal.pack200;
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
+import junit.framework.TestCase;
+
+import org.apache.harmony.archive.internal.pack200.AttributeLayout;
+import org.apache.harmony.archive.internal.pack200.Pack200Exception;
+import org.apache.harmony.archive.internal.pack200.Segment;
+
+public class AttributeLayoutTest extends TestCase {
+	public class TestSegment extends Segment {
+		public SegmentConstantPool getConstantPool() {
+			final Object[][] data = new Object[][] {
+					{ }, // ALL
+					{ "Zero", "One" }, // UTF-8
+					{ "Ein", "Zwei" }, // Signature
+			};
+			return new SegmentConstantPool() {
+				public Object getValue(int cp, long index) {
+					if (index == -1)
+						return null;
+					return data[cp][(int)index];
+				}
+				
+			};
+		}
+	}
+	public void testBadData() {
+		assertTrue(throwsException(null,AttributeLayout.CONTEXT_CLASS,""));
+		assertTrue(throwsException("",AttributeLayout.CONTEXT_CLASS,""));
+		assertTrue(!throwsException("name",AttributeLayout.CONTEXT_CLASS,""));
+		assertTrue(!throwsException("name",AttributeLayout.CONTEXT_METHOD,""));
+		assertTrue(!throwsException("name",AttributeLayout.CONTEXT_FIELD,""));
+		assertTrue(!throwsException("name",AttributeLayout.CONTEXT_CODE,""));
+		assertTrue(throwsException("name",-1,""));
+		assertTrue(throwsException("name",1234,""));
+	}
+	public void testLayoutRU() throws Pack200Exception {
+		AttributeLayout layout = new AttributeLayout("RU",AttributeLayout.CONTEXT_CLASS,"RU", 1);
+		Segment segment = new TestSegment();
+		assertNull(layout.getValue(-1, segment));
+		assertEquals("Zero",layout.getValue(0, segment));
+		assertEquals("One",layout.getValue(1, segment));
+	}
+	public void testLayoutRUN() throws Pack200Exception {
+		AttributeLayout layout = new AttributeLayout("RUN",AttributeLayout.CONTEXT_CLASS,"RUN", 1);
+		Segment segment = new TestSegment();
+		assertNull(layout.getValue(0, segment));
+		assertEquals("Zero",layout.getValue(1, segment));
+		assertEquals("One",layout.getValue(2, segment));
+	}
+	public void testLayoutRS() throws Pack200Exception {
+		AttributeLayout layout = new AttributeLayout("RS",AttributeLayout.CONTEXT_CLASS,"RS", 1);
+		Segment segment = new TestSegment();
+		assertNull(layout.getValue(-1, segment));
+		assertEquals("Ein",layout.getValue(0, segment));
+		assertEquals("Zwei",layout.getValue(1, segment));
+	}
+	public void testLayoutRSN() throws Pack200Exception {
+		AttributeLayout layout = new AttributeLayout("RSN",AttributeLayout.CONTEXT_CLASS,"RSN", 1);
+		Segment segment = new TestSegment();
+		assertNull(layout.getValue(0, segment));
+		assertEquals("Ein",layout.getValue(1, segment));
+		assertEquals("Zwei",layout.getValue(2, segment));
+	}
+	public boolean throwsException(String name, int context, String layout) {
+		try {
+			new AttributeLayout(name,context,layout,-1);
+			return false;
+		} catch (Pack200Exception e) {
+			return true;
+		}
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/AttributeLayoutTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/CodecEncodingTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/CodecEncodingTest.java?view=diff&rev=465556&r1=465555&r2=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/CodecEncodingTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/CodecEncodingTest.java Thu Oct 19 03:27:10 2006
@@ -15,7 +15,9 @@
  *  limitations under the License.
  */
 package org.apache.harmony.archive.tests.internal.pack200;
-
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.util.HashMap;
@@ -36,7 +38,7 @@
 	public void testCanonicalEncodings() throws IOException, Pack200Exception { 
 		Codec defaultCodec = new BHSDCodec(2,16,0,0);
 		assertEquals(defaultCodec,CodecEncoding.getCodec(0,null, defaultCodec));
-		Map<Integer, String> map = new HashMap<Integer, String>();
+		Map map = new HashMap();
 		// These are the canonical encodings specified by the Pack200 spec
 		map.put(new Integer(1), "(1,256)");
 		map.put(new Integer(2), "(1,256,1)");

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/CodecTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/CodecTest.java?view=diff&rev=465556&r1=465555&r2=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/CodecTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/CodecTest.java Thu Oct 19 03:27:10 2006
@@ -15,7 +15,9 @@
  *  limitations under the License.
  */
 package org.apache.harmony.archive.tests.internal.pack200;
-
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
 import java.io.ByteArrayInputStream;
 import java.io.EOFException;
 import java.io.IOException;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/HelloWorld.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/HelloWorld.java?view=diff&rev=465556&r1=465555&r2=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/HelloWorld.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/HelloWorld.java Thu Oct 19 03:27:10 2006
@@ -15,7 +15,9 @@
  *  limitations under the License.
  */
 package org.apache.harmony.archive.tests.internal.pack200;
-
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
 /**
  * This is intended to be used as a test class for unpacking a packed Jar file.
  * @author Alex Blewitt

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/PopulationCodecTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/PopulationCodecTest.java?view=diff&rev=465556&r1=465555&r2=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/PopulationCodecTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/PopulationCodecTest.java Thu Oct 19 03:27:10 2006
@@ -15,7 +15,9 @@
  *  limitations under the License.
  */
 package org.apache.harmony.archive.tests.internal.pack200;
-
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/SegmentOptionsTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/SegmentOptionsTest.java?view=diff&rev=465556&r1=465555&r2=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/SegmentOptionsTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/SegmentOptionsTest.java Thu Oct 19 03:27:10 2006
@@ -15,7 +15,9 @@
  *  limitations under the License.
  */
 package org.apache.harmony.archive.tests.internal.pack200;
-
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
 import junit.framework.TestCase;
 
 import org.apache.harmony.archive.internal.pack200.Pack200Exception;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/SegmentTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/SegmentTest.java?view=diff&rev=465556&r1=465555&r2=465556
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/SegmentTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/internal/pack200/SegmentTest.java Thu Oct 19 03:27:10 2006
@@ -15,7 +15,9 @@
  *  limitations under the License.
  */
 package org.apache.harmony.archive.tests.internal.pack200;
-
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
 import org.apache.harmony.archive.internal.pack200.Segment;
 
 import junit.framework.TestCase;



Mime
View raw message