You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by py...@apache.org on 2006/10/24 20:05:31 UTC

svn commit: r467417 - in /incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java: java/util/jar/ org/apache/harmony/archive/internal/pack200/

Author: pyang
Date: Tue Oct 24 11:05:30 2006
New Revision: 467417

URL: http://svn.apache.org/viewvc?view=rev&rev=467417
Log:
Apply patch for HARMONY-1940 ([classlib][[pack200] Implementing adapter for standard factory lookup)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Pack200Adapter.java   (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Pack200PackerAdapter.java   (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Pack200UnpackerAdapter.java   (with props)
Removed:
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/PackFactory.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Pack200.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Pack200.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Pack200.java?view=diff&rev=467417&r1=467416&r2=467417
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Pack200.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Pack200.java Tue Oct 24 11:05:30 2006
@@ -44,26 +44,23 @@
 	 * @return a instance of Packer
 	 */
 	public static Pack200.Packer newPacker() {
-		Packer packer = (Packer) AccessController
+		return (Packer) AccessController
 				.doPrivileged(new PrivilegedAction<Object>() {
 					public Object run() {
 						String className = System
-								.getProperty(SYSTEM_PROPERTY_PACKER);
-						if (null != className) {
-							try {
-								return ClassLoader.getSystemClassLoader()
-										.loadClass(className);
-							} catch (ClassNotFoundException e) {
-								throw new Error();
-							}
+								.getProperty(SYSTEM_PROPERTY_PACKER,
+										"org.apache.harmony.archive.internal.pack200.Pack200PackerAdapter"); //$NON-NLS-1$
+						try {
+							// TODO Not sure if this will cause problems with
+							// loading the packer
+							return ClassLoader.getSystemClassLoader()
+									.loadClass(className).newInstance();
+						} catch (Exception e) {
+							throw new Error("Can't load class " + className, e);
 						}
-						return null;
 					}
 				});
-		if (null != packer) {
-            return packer;
-        }
-		return PackFactory.newPacker();
+
 	}
 
 	/**
@@ -74,26 +71,20 @@
 	 * @return a instance of Unpacker
 	 */
 	public static Pack200.Unpacker newUnpacker() {
-		Unpacker unpacker = (Unpacker) AccessController
+		return (Unpacker) AccessController
 				.doPrivileged(new PrivilegedAction<Object>() {
 					public Object run() {
 						String className = System
-								.getProperty(SYSTEM_PROPERTY_UNPACKER);
-						if (null != className) {
-							try {
-								return ClassLoader.getSystemClassLoader()
-										.loadClass(className);
-							} catch (ClassNotFoundException e) {
-								throw new Error();
-							}
+								.getProperty(SYSTEM_PROPERTY_UNPACKER,
+										"org.apache.harmony.archive.internal.pack200.Pack200UnpackerAdapter");//$NON-NLS-1$
+						try {
+							return ClassLoader.getSystemClassLoader()
+									.loadClass(className).newInstance();
+						} catch (Exception e) {
+							throw new Error("Can't load class " + className, e);
 						}
-						return null;
 					}
 				});
-		if (null != unpacker) {
-            return unpacker;
-        }
-		return PackFactory.newUnpacker();
 	}
 
 	/**

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Pack200Adapter.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Pack200Adapter.java?view=auto&rev=467417
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Pack200Adapter.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Pack200Adapter.java Tue Oct 24 11:05:30 2006
@@ -0,0 +1,63 @@
+/*
+ *  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;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+// 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 ...
+/**
+ * Provides generic JavaBeans support for the Pack/UnpackAdapters
+ */
+public abstract class Pack200Adapter {
+
+	protected static final int DEFAULT_BUFFER_SIZE = 8192;
+
+	private PropertyChangeSupport support = new PropertyChangeSupport(this);
+
+	private SortedMap<String, String> properties = new TreeMap<String, String>();
+
+	public SortedMap<String, String> properties() {
+		return properties;
+	}
+
+	public void addPropertyChangeListener(PropertyChangeListener listener) {
+		support.addPropertyChangeListener(listener);
+	}
+
+	protected void firePropertyChange(String propertyName, Object oldValue,
+			Object newValue) {
+		support.firePropertyChange(propertyName, oldValue, newValue);
+	}
+
+	public void removePropertyChangeListener(PropertyChangeListener listener) {
+		support.removePropertyChangeListener(listener);
+	}
+
+	/** 
+	 * Completion between 0..1
+	 * @param value
+	 */
+	protected void completed(double value) {
+		firePropertyChange("pack.progress", null, String.valueOf((int)(100*value))); //$NON-NLS-1$
+	}
+}

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

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Pack200PackerAdapter.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Pack200PackerAdapter.java?view=auto&rev=467417
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Pack200PackerAdapter.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Pack200PackerAdapter.java Tue Oct 24 11:05:30 2006
@@ -0,0 +1,45 @@
+/*
+ *  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.beans.PropertyChangeListener;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.SortedMap;
+import java.util.jar.JarFile;
+import java.util.jar.JarInputStream;
+import java.util.jar.Pack200.Packer;
+
+/**
+ * This class provides the binding between the standard Pack200 interface and the
+ * internal interface for (un)packing. As this uses generics for the SortedMap,
+ * this class must be compiled and run on a Java 1.5 system. However, Java 1.5
+ * is not necessary to use the internal libraries for unpacking.
+ */
+public class Pack200PackerAdapter extends Pack200Adapter implements Packer {
+
+	public void pack(JarFile arg0, OutputStream arg1) throws IOException {
+		throw new Error("Not yet implemented");
+	}
+
+	public void pack(JarInputStream arg0, OutputStream arg1) throws IOException {
+		throw new Error("Not yet implemented");
+	}
+
+}

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

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Pack200UnpackerAdapter.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Pack200UnpackerAdapter.java?view=auto&rev=467417
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Pack200UnpackerAdapter.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/Pack200UnpackerAdapter.java Tue Oct 24 11:05:30 2006
@@ -0,0 +1,79 @@
+/*
+ *  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.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Pack200.Unpacker;
+
+/**
+ * This class provides the binding between the standard Pack200 interface and
+ * the internal interface for (un)packing. As this uses generics for the
+ * SortedMap, this class must be compiled and run on a Java 1.5 system. However,
+ * Java 1.5 is not necessary to use the internal libraries for unpacking.
+ */
+public class Pack200UnpackerAdapter extends Pack200Adapter implements Unpacker {
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.util.jar.Pack200.Unpacker#unpack(java.io.InputStream,
+	 *      java.util.jar.JarOutputStream)
+	 */
+	public void unpack(InputStream in, JarOutputStream out) throws IOException {
+		if (in == null || out == null)
+			throw new IllegalArgumentException(
+					"Must specify both input and output streams");
+		completed(0);
+		try {
+			while (in.available() > 0) {
+				Segment s = Segment.parse(in);
+				s.writeJar(out, in);
+				out.flush();
+			}
+		} catch (Pack200Exception e) {
+			throw new IOException("Failed to unpack Jar:" + String.valueOf(e));
+		}
+		completed(1);
+		in.close();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.util.jar.Pack200.Unpacker#unpack(java.io.File,
+	 *      java.util.jar.JarOutputStream)
+	 */
+	public void unpack(File file, JarOutputStream out) throws IOException {
+		if (file == null || out == null)
+			throw new IllegalArgumentException(
+					"Must specify both input and output streams");
+		int size = (int) file.length();
+		int bufferSize = (size > 0 && size < DEFAULT_BUFFER_SIZE ? size
+				: DEFAULT_BUFFER_SIZE);
+		InputStream in = new BufferedInputStream(new FileInputStream(file),
+				bufferSize);
+		unpack(in, out);
+	}
+}

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