harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r641928 [2/2] - in /harmony/enhanced/classlib/trunk/modules: archive/src/main/java/java/util/jar/ archive/src/main/java/org/apache/harmony/archive/internal/nls/ archive/src/main/java/org/apache/harmony/archive/util/ archive/src/test/java/or...
Date Thu, 27 Mar 2008 18:02:39 GMT
Modified: harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ManifestTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ManifestTest.java?rev=641928&r1=641927&r2=641928&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ManifestTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ManifestTest.java
Thu Mar 27 11:02:32 2008
@@ -17,6 +17,7 @@
 package org.apache.harmony.archive.tests.java.util.jar;
 
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -27,222 +28,378 @@
 import java.util.jar.Manifest;
 
 import junit.framework.TestCase;
+
 import tests.support.resource.Support_Resources;
 
 public class ManifestTest extends TestCase {
 
-	private final String JAR_NAME = "hyts_patch.jar";
+    private final String JAR_NAME = "hyts_patch.jar";
 
     private final String ATT_JAR_NAME = "hyts_att.jar";
 
-    private final String MANIFEST_NAME = "manifest/hyts_MANIFEST.MF";
+    private final String ATT_ENTRY_NAME = "HasAttributes.txt";
 
-    private Manifest m;
-    
-    private Manifest m2;
+    private final String ATT_ATT_NAME = "MyAttribute";
+
+    private final String MANIFEST_NAME = "manifest/hyts_MANIFEST.MF";
 
     private File resources;
-    
+
     @Override
     protected void setUp() {
         resources = Support_Resources.createTempFolder();
+    }
+
+    private Manifest getManifest(String fileName) {
         try {
-            Support_Resources.copyFile(resources, null, JAR_NAME);
-            JarFile jarFile = new JarFile(new File(resources, JAR_NAME));
-            m = jarFile.getManifest();
-            jarFile.close();
-            Support_Resources.copyFile(resources, null, ATT_JAR_NAME);
-            jarFile = new JarFile(new File(resources, ATT_JAR_NAME));
-            m2 = jarFile.getManifest();
+            Support_Resources.copyFile(resources, null, fileName);
+            JarFile jarFile = new JarFile(new File(resources, fileName));
+            Manifest m = jarFile.getManifest();
             jarFile.close();
+            return m;
         } catch (Exception e) {
             fail("Exception during setup: " + e.toString());
+            return null;
         }
     }
 
-	/**
-	 * @tests java.util.jar.Manifest#Manifest()
-	 */
-	public void test_Constructor() {
-		// Test for method java.util.jar.Manifest()
-		Manifest emptyManifest = new Manifest();
-		assertTrue("Should have no entries", emptyManifest.getEntries()
-				.isEmpty());
-		assertTrue("Should have no main attributes", emptyManifest
-				.getMainAttributes().isEmpty());
-	}
+    /**
+     * @tests java.util.jar.Manifest#Manifest()
+     */
+    public void testConstructor() {
+        // Test for method java.util.jar.Manifest()
+        Manifest emptyManifest = new Manifest();
+        assertTrue("Should have no entries", emptyManifest.getEntries()
+                .isEmpty());
+        assertTrue("Should have no main attributes", emptyManifest
+                .getMainAttributes().isEmpty());
+    }
 
     /**
      * @tests java.util.jar.Manifest#Manifest(java.util.jar.Manifest)
      */
-    public void test_Constructor_Ljava_util_jar_Manifest() throws IOException {
+    public void testCopyingConstructor() throws IOException {
         Manifest firstManifest = new Manifest(new URL(Support_Resources
                 .getURL(MANIFEST_NAME)).openStream());
         Manifest secondManifest = new Manifest(firstManifest);
         assertEquals(firstManifest, secondManifest);
     }
-	
-	/**
-	 * @tests java.util.jar.Manifest#Manifest(java.io.InputStream)
-	 */
-	public void test_ConstructorLjava_io_InputStream() throws IOException {
-		// Test for method java.util.jar.Manifest(java.io.InputStream)
-		/*
-		 * ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		 * m2.write(baos); InputSteam is = new ByteArrayInputStream
-		 * (baos.toByteArray()); Manifest myManifest = new Manifest (is);
-		 * assertTrue("Manifests should be equal", myManifest.equals(m2));
-		 */
+
+    private void assertAttribute(Attributes attr, String name, String value) {
+        assertEquals("Incorrect " + name, value, attr.getValue(name));
+    }
+
+    private void checkManifest(Manifest manifest) {
+        Attributes main = manifest.getMainAttributes();
+        assertAttribute(main, "Bundle-Name", "ClientSupport");
+        assertAttribute(main, "Bundle-Description",
+                "Provides SessionService, AuthenticationService. Extends RegistryService.");
+        assertAttribute(main, "Bundle-Activator",
+                "com.ibm.ive.eccomm.client.support.ClientSupportActivator");
+        assertAttribute(
+                main,
+                "Import-Package",
+                "com.ibm.ive.eccomm.client.services.log,com.ibm.ive.eccomm.client.services.registry,com.ibm.ive.eccomm.service.registry;
specification-version=1.0.0,com.ibm.ive.eccomm.service.session; specification-version=1.0.0,com.ibm.ive.eccomm.service.framework;
specification-version=1.2.0,org.osgi.framework; specification-version=1.0.0,org.osgi.service.log;
specification-version=1.0.0,com.ibm.ive.eccomm.flash; specification-version=1.2.0,com.ibm.ive.eccomm.client.xml,com.ibm.ive.eccomm.client.http.common,com.ibm.ive.eccomm.client.http.client");
+        assertAttribute(
+                main,
+                "Import-Service",
+                "org.osgi.service.log.LogReaderServiceorg.osgi.service.log.LogService,com.ibm.ive.eccomm.service.registry.RegistryService");
+        assertAttribute(
+                main,
+                "Export-Package",
+                "com.ibm.ive.eccomm.client.services.authentication; specification-version=1.0.0,com.ibm.ive.eccomm.service.authentication;
specification-version=1.0.0,com.ibm.ive.eccomm.common; specification-version=1.0.0,com.ibm.ive.eccomm.client.services.registry.store;
specification-version=1.0.0");
+        assertAttribute(
+                main,
+                "Export-Service",
+                "com.ibm.ive.eccomm.service.authentication.AuthenticationService,com.ibm.ive.eccomm.service.session.SessionService");
+        assertAttribute(main, "Bundle-Vendor", "IBM");
+        assertAttribute(main, "Bundle-Version", "1.2.0");
+    }
+
+    /**
+     * @tests java.util.jar.Manifest#Manifest(java.io.InputStream)
+     */
+    public void testStreamConstructor() throws IOException {
+        Manifest m = getManifest(ATT_JAR_NAME);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        m.write(baos);
+        InputStream is = new ByteArrayInputStream(baos.toByteArray());
+        Manifest mCopy = new Manifest(is);
+        assertEquals(m, mCopy);
 
         Manifest manifest = new Manifest(new URL(Support_Resources
                 .getURL(MANIFEST_NAME)).openStream());
+        checkManifest(manifest);
 
-		Attributes main = manifest.getMainAttributes();
-		assertEquals("Bundle-Name not correct", "ClientSupport", main.getValue("Bundle-Name")
-				);
-		assertEquals("Bundle-Description not correct",
-				
-								"Provides SessionService, AuthenticationService. Extends RegistryService.", main
-						.getValue("Bundle-Description")
-						);
-		assertEquals("Bundle-Activator not correct", 
-				"com.ibm.ive.eccomm.client.support.ClientSupportActivator", main.getValue(
-				"Bundle-Activator"));
-		assertEquals("Import-Package not correct",
-				
-								"com.ibm.ive.eccomm.client.services.log,com.ibm.ive.eccomm.client.services.registry,com.ibm.ive.eccomm.service.registry;
specification-version=1.0.0,com.ibm.ive.eccomm.service.session; specification-version=1.0.0,com.ibm.ive.eccomm.service.framework;
specification-version=1.2.0,org.osgi.framework; specification-version=1.0.0,org.osgi.service.log;
specification-version=1.0.0,com.ibm.ive.eccomm.flash; specification-version=1.2.0,com.ibm.ive.eccomm.client.xml,com.ibm.ive.eccomm.client.http.common,com.ibm.ive.eccomm.client.http.client",
main
-						.getValue("Import-Package")
-						);
-		assertEquals("Import-Service not correct",
-				
-								"org.osgi.service.log.LogReaderServiceorg.osgi.service.log.LogService,com.ibm.ive.eccomm.service.registry.RegistryService",
main
-						.getValue("Import-Service")
-						);
-		assertEquals("Export-Package not correct",
-				
-								"com.ibm.ive.eccomm.client.services.authentication; specification-version=1.0.0,com.ibm.ive.eccomm.service.authentication;
specification-version=1.0.0,com.ibm.ive.eccomm.common; specification-version=1.0.0,com.ibm.ive.eccomm.client.services.registry.store;
specification-version=1.0.0", main
-						.getValue("Export-Package")
-						);
-		assertEquals("Export-Service not correct",
-				
-								"com.ibm.ive.eccomm.service.authentication.AuthenticationService,com.ibm.ive.eccomm.service.session.SessionService",
main
-						.getValue("Export-Service")
-						);
-		assertEquals("Bundle-Vendor not correct", "IBM", main.getValue("Bundle-Vendor")
-				);
-		assertEquals("Bundle-Version not correct", "1.2.0", main
-				.getValue("Bundle-Version"));
-
-        // Regression test for HARMONY-5424
+        // regression test for HARMONY-5424
         String manifestContent = "Manifest-Version: 1.0\nCreated-By: Apache\nPackage: \nBuild-Jdk:
1.4.1_01\n\n"
                 + "Name: \nSpecification-Title: foo\nSpecification-Version: 1.0\nSpecification-Vendor:
\n"
                 + "Implementation-Title: \nImplementation-Version: 1.0\nImplementation-Vendor:
\n\n";
         ByteArrayInputStream bis = new ByteArrayInputStream(manifestContent
                 .getBytes());
-        Manifest mf = new Manifest(bis);
 
-        assertEquals("Wrong number of main attributes", 4, mf
-                .getMainAttributes().size());
+        Manifest mf = new Manifest(bis);
+        assertEquals("Should be 4 main attributes", 4, mf.getMainAttributes()
+                .size());
 
         Map<String, Attributes> entries = mf.getEntries();
-        assertEquals("Wrong number of named entries", 1, entries.size());
+        assertEquals("Should be one named entry", 1, entries.size());
 
         Attributes namedEntryAttributes = (Attributes) (entries.get(""));
-        assertEquals("Wrong number of named entry attributes", 6,
+        assertEquals("Should be 6 named entry attributes", 6,
                 namedEntryAttributes.size());
-	}
+    }
 
-	/**
-	 * @tests java.util.jar.Manifest#clear()
-	 */
-	public void test_clear() {
-		// Test for method void java.util.jar.Manifest.clear()
-		m2.clear();
-		assertTrue("Should have no entries", m2.getEntries().isEmpty());
-		assertTrue("Should have no main attributes", m2.getMainAttributes()
-				.isEmpty());
-	}
+    /**
+     * @tests java.util.jar.Manifest#clear()
+     */
+    public void testClear() {
+        Manifest m = getManifest(ATT_JAR_NAME);
+        m.clear();
+        assertTrue("Should have no entries", m.getEntries().isEmpty());
+        assertTrue("Should have no main attributes", m.getMainAttributes()
+                .isEmpty());
+    }
 
     /**
      * @tests java.util.jar.Manifest#clone()
      */
-    public void test_clone() {
-        Manifest newManifest = (Manifest) m.clone();
-        assertEquals(newManifest, m);
+    public void testClone() {
+        Manifest m = getManifest(JAR_NAME);
+        assertEquals(m, m.clone());
     }
 
     /**
      * @tests java.util.jar.Manifest#equals(java.lang.Object)
      */
-    public void test_equalsLjava_lang_Object() throws IOException {
+    public void testEquals() throws IOException {
         Manifest firstManifest = new Manifest(new URL(Support_Resources
                 .getURL(MANIFEST_NAME)).openStream());
         Manifest secondManifest = new Manifest(new URL(Support_Resources
                 .getURL(MANIFEST_NAME)).openStream());
 
-        assertTrue(firstManifest.equals(secondManifest));
+        assertEquals(firstManifest, secondManifest);
     }
 
     /**
      * @tests java.util.jar.Manifest#hashCode()
      */
-    public void test_hashCode() {
-        Manifest newManifest = (Manifest) m.clone();
-        assertEquals(newManifest.hashCode(), m.hashCode());
-    }
-	
-	/**
-	 * @tests java.util.jar.Manifest#getAttributes(java.lang.String)
-	 */
-	public void test_getAttributesLjava_lang_String() {
-		// Test for method java.util.jar.Attributes
-		// java.util.jar.Manifest.getAttributes(java.lang.String)
-		assertNull("Should not exist",
-				m2.getAttributes("Doesn't Exist"));
-		assertEquals("Should exist", "OK", m2.getAttributes("HasAttributes.txt").get(
-				new Attributes.Name("MyAttribute")));
-	}
-
-	/**
-	 * @tests java.util.jar.Manifest#getEntries()
-	 */
-	public void test_getEntries() {
-		// Test for method java.util.Map java.util.jar.Manifest.getEntries()
-		Map<String, Attributes> myMap = m2.getEntries();
-		assertNull("Shouldn't exist", myMap.get("Doesn't exist"));
-		assertEquals("Should exist",
-				"OK", myMap.get("HasAttributes.txt").get(
-						new Attributes.Name("MyAttribute")));
-
-	}
-
-	/**
-	 * @tests java.util.jar.Manifest#getMainAttributes()
-	 */
-	public void test_getMainAttributes() {
-		// Test for method java.util.jar.Attributes
-		// java.util.jar.Manifest.getMainAttributes()
-		Attributes a = m.getMainAttributes();
-		assertEquals("Manifest_Version should return 1.0", "1.0", a.get(
-				Attributes.Name.MANIFEST_VERSION));
-	}
+    public void testHashCode() {
+        Manifest m = getManifest(JAR_NAME);
+        assertEquals(m.hashCode(), m.clone().hashCode());
+    }
+
+    /**
+     * @tests java.util.jar.Manifest#getAttributes(java.lang.String)
+     */
+    public void testGetAttributes() {
+        Manifest m = getManifest(ATT_JAR_NAME);
+        assertNull("Should not exist", m.getAttributes("Doesn't Exist"));
+        assertEquals("Should exist", "OK", m.getAttributes(ATT_ENTRY_NAME).get(
+                new Attributes.Name(ATT_ATT_NAME)));
+    }
+
+    /**
+     * @tests java.util.jar.Manifest#getEntries()
+     */
+    public void testGetEntries() {
+        Manifest m = getManifest(ATT_JAR_NAME);
+        Map<String, Attributes> myMap = m.getEntries();
+        assertNull("Shouldn't exist", myMap.get("Doesn't exist"));
+        assertEquals("Should exist", "OK", myMap.get(ATT_ENTRY_NAME).get(
+                new Attributes.Name(ATT_ATT_NAME)));
+    }
+
+    /**
+     * @tests java.util.jar.Manifest#getMainAttributes()
+     */
+    public void testGetMainAttributes() {
+        Manifest m = getManifest(JAR_NAME);
+        Attributes a = m.getMainAttributes();
+        assertEquals("Manifest_Version should return 1.0", "1.0", a
+                .get(Attributes.Name.MANIFEST_VERSION));
+    }
+
+    /**
+     * @tests {@link java.util.jar.Manifest#write(java.io.OutputStream)
+     */
+    public void testWrite() throws IOException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        Manifest m = getManifest(JAR_NAME);
+        // maximum allowed length is 72 for a header, colon and a following
+        // space
+        StringBuffer headerName = new StringBuffer(71);
+        headerName.append("Manifest-");
+        while (headerName.length() < 70) {
+            headerName.append("0");
+        }
+        m.getMainAttributes().put(new Attributes.Name(headerName.toString()),
+                "Value");
+        m.write(baos); // ok
+    }
+
+    /**
+     * @tests {@link java.util.jar.Manifest#read(java.io.InputStream)
+     */
+    public void testDecoding() throws IOException {
+        Manifest m = getManifest(ATT_JAR_NAME);
+        final byte[] bVendor = new byte[] { (byte) 0xd0, (byte) 0x9C,
+                (byte) 0xd0, (byte) 0xb8, (byte) 0xd0, (byte) 0xbb,
+                (byte) 0xd0, (byte) 0xb0, (byte) 0xd1, (byte) 0x8f, ' ',
+                (byte) 0xd0, (byte) 0xb4, (byte) 0xd0, (byte) 0xbe,
+                (byte) 0xd1, (byte) 0x87, (byte) 0xd1, (byte) 0x83,
+                (byte) 0xd0, (byte) 0xbd, (byte) 0xd1, (byte) 0x8C,
+                (byte) 0xd0, (byte) 0xba, (byte) 0xd0, (byte) 0xb0, ' ',
+                (byte) 0xd0, (byte) 0x9C, (byte) 0xd0, (byte) 0xb0,
+                (byte) 0xd1, (byte) 0x88, (byte) 0xd0, (byte) 0xb0 };
+
+        final byte[] bSpec = new byte[] { (byte) 0xe1, (byte) 0x88,
+                (byte) 0xb0, (byte) 0xe1, (byte) 0x88, (byte) 0x8b,
+                (byte) 0xe1, (byte) 0x88, (byte) 0x9d, ' ', (byte) 0xe1,
+                (byte) 0x9a, (byte) 0xa0, (byte) 0xe1, (byte) 0x9a,
+                (byte) 0xb1, (byte) 0xe1, (byte) 0x9b, (byte) 0x81,
+                (byte) 0xe1, (byte) 0x9a, (byte) 0xa6, ' ', (byte) 0xd8,
+                (byte) 0xb3, (byte) 0xd9, (byte) 0x84, (byte) 0xd8,
+                (byte) 0xa7, (byte) 0xd9, (byte) 0x85, ' ', (byte) 0xd8,
+                (byte) 0xb9, (byte) 0xd8, (byte) 0xb3, (byte) 0xd9,
+                (byte) 0x84, (byte) 0xd8, (byte) 0xa7, (byte) 0xd9,
+                (byte) 0x85, (byte) 0xd8, (byte) 0xa9, ' ', (byte) 0xdc,
+                (byte) 0xab, (byte) 0xdc, (byte) 0xa0, (byte) 0xdc,
+                (byte) 0xa1, (byte) 0xdc, (byte) 0x90, ' ', (byte) 0xe0,
+                (byte) 0xa6, (byte) 0xb6, (byte) 0xe0, (byte) 0xa6,
+                (byte) 0xbe, (byte) 0xe0, (byte) 0xa6, (byte) 0xa8,
+                (byte) 0xe0, (byte) 0xa7, (byte) 0x8d, (byte) 0xe0,
+                (byte) 0xa6, (byte) 0xa4, (byte) 0xe0, (byte) 0xa6,
+                (byte) 0xbf, ' ', (byte) 0xd0, (byte) 0xa0, (byte) 0xd0,
+                (byte) 0xb5, (byte) 0xd0, (byte) 0xba, (byte) 0xd1,
+                (byte) 0x8a, (byte) 0xd0, (byte) 0xb5, (byte) 0xd0,
+                (byte) 0xbb, ' ', (byte) 0xd0, (byte) 0x9c, (byte) 0xd0,
+                (byte) 0xb8, (byte) 0xd1, (byte) 0x80, ' ', (byte) 0xe0,
+                (byte) 0xa6, (byte) 0xb6, (byte) 0xe0, (byte) 0xa6,
+                (byte) 0xbe, (byte) 0xe0, (byte) 0xa6, (byte) 0xa8,
+                (byte) 0xe0, (byte) 0xa7, (byte) 0x8d, (byte) 0xe0,
+                (byte) 0xa6, (byte) 0xa4, (byte) 0xe0, (byte) 0xa6,
+                (byte) 0xbf, ' ', (byte) 0xe0, (byte) 0xbd, (byte) 0x9e,
+                (byte) 0xe0, (byte) 0xbd, (byte) 0xb2, (byte) 0xe0,
+                (byte) 0xbc, (byte) 0x8b, (byte) 0xe0, (byte) 0xbd,
+                (byte) 0x96, (byte) 0xe0, (byte) 0xbd, (byte) 0x91,
+                (byte) 0xe0, (byte) 0xbd, (byte) 0xba, ' ', (byte) 0xd0,
+                (byte) 0x9c, (byte) 0xd0, (byte) 0xb0, (byte) 0xd1,
+                (byte) 0x88, (byte) 0xd0, (byte) 0xb0, (byte) 0xd1,
+                (byte) 0x80, ' ', (byte) 0xe1, (byte) 0x8f, (byte) 0x99,
+                (byte) 0xe1, (byte) 0x8e, (byte) 0xaf, (byte) 0xe1,
+                (byte) 0x8f, (byte) 0xb1, ' ', (byte) 0xcf, (byte) 0xa8,
+                (byte) 0xce, (byte) 0xb9, (byte) 0xcf, (byte) 0x81,
+                (byte) 0xce, (byte) 0xb7, (byte) 0xce, (byte) 0xbd,
+                (byte) 0xce, (byte) 0xb7, ' ', (byte) 0xde, (byte) 0x90,
+                (byte) 0xde, (byte) 0xaa, (byte) 0xde, (byte) 0x85,
+                (byte) 0xde, (byte) 0xa6, ' ', (byte) 0xe0, (byte) 0xbd,
+                (byte) 0x82, (byte) 0xe0, (byte) 0xbd, (byte) 0x9e,
+                (byte) 0xe0, (byte) 0xbd, (byte) 0xb2, (byte) 0xe0,
+                (byte) 0xbc, (byte) 0x8b, (byte) 0xe0, (byte) 0xbd,
+                (byte) 0x96, (byte) 0xe0, (byte) 0xbd, (byte) 0x91,
+                (byte) 0xe0, (byte) 0xbd, (byte) 0xba, ' ', (byte) 0xce,
+                (byte) 0x95, (byte) 0xce, (byte) 0xb9, (byte) 0xcf,
+                (byte) 0x81, (byte) 0xce, (byte) 0xae, (byte) 0xce,
+                (byte) 0xbd, (byte) 0xce, (byte) 0xb7, ' ', (byte) 0xd8,
+                (byte) 0xb5, (byte) 0xd9, (byte) 0x84, (byte) 0xd8,
+                (byte) 0xad, ' ', (byte) 0xe0, (byte) 0xaa, (byte) 0xb6,
+                (byte) 0xe0, (byte) 0xaa, (byte) 0xbe, (byte) 0xe0,
+                (byte) 0xaa, (byte) 0x82, (byte) 0xe0, (byte) 0xaa,
+                (byte) 0xa4, (byte) 0xe0, (byte) 0xaa, (byte) 0xbf, ' ',
+                (byte) 0xe5, (byte) 0xb9, (byte) 0xb3, (byte) 0xe5,
+                (byte) 0x92, (byte) 0x8c, ' ', (byte) 0xd7, (byte) 0xa9,
+                (byte) 0xd7, (byte) 0x9c, (byte) 0xd7, (byte) 0x95,
+                (byte) 0xd7, (byte) 0x9d, ' ', (byte) 0xd7, (byte) 0xa4,
+                (byte) 0xd7, (byte) 0xa8, (byte) 0xd7, (byte) 0x99,
+                (byte) 0xd7, (byte) 0x93, (byte) 0xd7, (byte) 0x9f, ' ',
+                (byte) 0xe5, (byte) 0x92, (byte) 0x8c, (byte) 0xe5,
+                (byte) 0xb9, (byte) 0xb3, ' ', (byte) 0xe5, (byte) 0x92,
+                (byte) 0x8c, (byte) 0xe5, (byte) 0xb9, (byte) 0xb3, ' ',
+                (byte) 0xd8, (byte) 0xaa, (byte) 0xd9, (byte) 0x89,
+                (byte) 0xd9, (byte) 0x86, (byte) 0xda, (byte) 0x86,
+                (byte) 0xd9, (byte) 0x84, (byte) 0xd9, (byte) 0x89,
+                (byte) 0xd9, (byte) 0x82, ' ', (byte) 0xe0, (byte) 0xae,
+                (byte) 0x85, (byte) 0xe0, (byte) 0xae, (byte) 0xae,
+                (byte) 0xe0, (byte) 0xaf, (byte) 0x88, (byte) 0xe0,
+                (byte) 0xae, (byte) 0xa4, (byte) 0xe0, (byte) 0xae,
+                (byte) 0xbf, ' ', (byte) 0xe0, (byte) 0xb0, (byte) 0xb6,
+                (byte) 0xe0, (byte) 0xb0, (byte) 0xbe, (byte) 0xe0,
+                (byte) 0xb0, (byte) 0x82, (byte) 0xe0, (byte) 0xb0,
+                (byte) 0xa4, (byte) 0xe0, (byte) 0xb0, (byte) 0xbf, ' ',
+                (byte) 0xe0, (byte) 0xb8, (byte) 0xaa, (byte) 0xe0,
+                (byte) 0xb8, (byte) 0xb1, (byte) 0xe0, (byte) 0xb8,
+                (byte) 0x99, (byte) 0xe0, (byte) 0xb8, (byte) 0x95,
+                (byte) 0xe0, (byte) 0xb8, (byte) 0xb4, (byte) 0xe0,
+                (byte) 0xb8, (byte) 0xa0, (byte) 0xe0, (byte) 0xb8,
+                (byte) 0xb2, (byte) 0xe0, (byte) 0xb8, (byte) 0x9e, ' ',
+                (byte) 0xe1, (byte) 0x88, (byte) 0xb0, (byte) 0xe1,
+                (byte) 0x88, (byte) 0x8b, (byte) 0xe1, (byte) 0x88,
+                (byte) 0x9d, ' ', (byte) 0xe0, (byte) 0xb7, (byte) 0x83,
+                (byte) 0xe0, (byte) 0xb7, (byte) 0x8f, (byte) 0xe0,
+                (byte) 0xb6, (byte) 0xb8, (byte) 0xe0, (byte) 0xb6,
+                (byte) 0xba, ' ', (byte) 0xe0, (byte) 0xa4, (byte) 0xb6,
+                (byte) 0xe0, (byte) 0xa4, (byte) 0xbe, (byte) 0xe0,
+                (byte) 0xa4, (byte) 0xa8, (byte) 0xe0, (byte) 0xa5,
+                (byte) 0x8d, (byte) 0xe0, (byte) 0xa4, (byte) 0xa4,
+                (byte) 0xe0, (byte) 0xa4, (byte) 0xbf, (byte) 0xe0,
+                (byte) 0xa4, (byte) 0x83, ' ', (byte) 0xe1, (byte) 0x83,
+                (byte) 0x9b, (byte) 0xe1, (byte) 0x83, (byte) 0xa8,
+                (byte) 0xe1, (byte) 0x83, (byte) 0x95, (byte) 0xe1,
+                (byte) 0x83, (byte) 0x98, (byte) 0xe1, (byte) 0x83,
+                (byte) 0x93, (byte) 0xe1, (byte) 0x83, (byte) 0x9d,
+                (byte) 0xe1, (byte) 0x83, (byte) 0x91, (byte) 0xe1,
+                (byte) 0x83, (byte) 0x90 };
+        // TODO Cannot make the following word work, encoder changes needed
+        // (byte) 0xed, (byte) 0xa0, (byte) 0x80,
+        // (byte) 0xed, (byte) 0xbc, (byte) 0xb2, (byte) 0xed,
+        // (byte) 0xa0, (byte) 0x80, (byte) 0xed, (byte) 0xbc,
+        // (byte) 0xb0, (byte) 0xed, (byte) 0xa0, (byte) 0x80,
+        // (byte) 0xed, (byte) 0xbd, (byte) 0x85, (byte) 0xed,
+        // (byte) 0xa0, (byte) 0x80, (byte) 0xed, (byte) 0xbc,
+        // (byte) 0xb0, (byte) 0xed, (byte) 0xa0, (byte) 0x80,
+        // (byte) 0xed, (byte) 0xbc, (byte) 0xb9, (byte) 0xed,
+        // (byte) 0xa0, (byte) 0x80, (byte) 0xed, (byte) 0xbc,
+        // (byte) 0xb8, (byte) 0xed, (byte) 0xa0, (byte) 0x80,
+        // (byte) 0xed, (byte) 0xbc, (byte) 0xb9, ' '
+
+        final String vendor = new String(bVendor, "UTF-8");
+        final String spec = new String(bSpec, "UTF-8");
+        m.getMainAttributes()
+                .put(Attributes.Name.IMPLEMENTATION_VENDOR, vendor);
+        m.getAttributes(ATT_ENTRY_NAME).put(
+                Attributes.Name.IMPLEMENTATION_VENDOR, vendor);
+        m.getEntries().get(ATT_ENTRY_NAME).put(
+                Attributes.Name.SPECIFICATION_TITLE, spec);
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        m.write(baos);
+        m = new Manifest(new ByteArrayInputStream(baos.toByteArray()));
+
+        assertEquals(vendor, m.getMainAttributes().get(
+                Attributes.Name.IMPLEMENTATION_VENDOR));
+        assertEquals(vendor, m.getEntries().get(ATT_ENTRY_NAME).get(
+                Attributes.Name.IMPLEMENTATION_VENDOR));
+        assertEquals(spec, m.getAttributes(ATT_ENTRY_NAME).get(
+                Attributes.Name.SPECIFICATION_TITLE));
+    }
 
     /**
      * @tests {@link java.util.jar.Manifest#read(java.io.InputStream)
      */
-    public void test_readLjava_io_InputStream() {
+    public void testRead() {
         // Regression for HARMONY-89
         InputStream is = new InputStreamImpl();
         try {
             new Manifest().read(is);
-            fail("Assert 0: Should have thrown IOException");
+            fail("IOException expected");
         } catch (IOException e) {
-            // expected
+            // desired
         }
     }
 
     // helper class
-    class InputStreamImpl extends InputStream {
+    private class InputStreamImpl extends InputStream {
         public InputStreamImpl() {
             super();
         }

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/util/UtilTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/util/UtilTest.java?rev=641928&r1=641927&r2=641928&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/util/UtilTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/util/UtilTest.java
Thu Mar 27 11:02:32 2008
@@ -32,8 +32,9 @@
     }
 
     public void testToASCIILowerCase() {
-        assertEquals("abcdefghijklmnopqrstuvwxyz", Util //$NON-NLS-1$
-                .toASCIILowerCase("ABCDEFGHIJKLMNOPQRSTUVWXYZ")); //$NON-NLS-1$
+        assertEquals(
+                "abcdefghijklmnopqrstuvwxyz", org.apache.harmony.luni.util.Util //$NON-NLS-1$
+                        .toASCIILowerCase("ABCDEFGHIJKLMNOPQRSTUVWXYZ")); //$NON-NLS-1$
 
         for (int i = 0; i < 255; i++) {
             if (i >= 'a' && i <= 'z') {
@@ -43,13 +44,15 @@
                 continue;
             }
             String cString = "" + (char) i; //$NON-NLS-1$
-            assertEquals(cString, Util.toASCIILowerCase(cString));
+            assertEquals(cString, org.apache.harmony.luni.util.Util
+                    .toASCIILowerCase(cString));
         }
     }
 
     public void testToASCIIUpperCase() {
-        assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ", Util //$NON-NLS-1$
-                .toASCIIUpperCase("abcdefghijklmnopqrstuvwxyz")); //$NON-NLS-1$
+        assertEquals(
+                "ABCDEFGHIJKLMNOPQRSTUVWXYZ", org.apache.harmony.luni.util.Util //$NON-NLS-1$
+                        .toASCIIUpperCase("abcdefghijklmnopqrstuvwxyz")); //$NON-NLS-1$
 
         for (int i = 0; i < 255; i++) {
             if (i >= 'a' && i <= 'z') {
@@ -59,11 +62,12 @@
                 continue;
             }
             String cString = "" + (char) i; //$NON-NLS-1$
-            assertEquals(cString, Util.toASCIIUpperCase(cString));
+            assertEquals(cString, org.apache.harmony.luni.util.Util
+                    .toASCIIUpperCase(cString));
         }
     }
-    
-    public void testEqualsIgnoreCase(){
+
+    public void testEqualsIgnoreCase() {
         assertTrue(Util.equalsIgnoreCase(s1, s2));
     }
 

Added: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ByteBuffer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ByteBuffer.java?rev=641928&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ByteBuffer.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ByteBuffer.java
Thu Mar 27 11:02:32 2008
@@ -0,0 +1,125 @@
+/*
+ *  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.luni.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * The class contains static {@link java.io.InputStream} utilities.
+ */
+public class ByteBuffer {
+
+    /**
+     * Provides access to a protected underlying buffer of
+     * <code>ByteArrayInputStream</code>.
+     */
+    private static final Field BAIS_BUF;
+
+    /**
+     * Provides access to a protected position in the underlying buffer of
+     * <code>ByteArrayInputStream</code>.
+     */
+    private static final Field BAIS_POS;
+
+    static {
+        final Field[] f = new Field[2];
+        AccessController.doPrivileged(new PrivilegedAction<Object>() {
+            public Object run() {
+                try {
+                    f[0] = ByteArrayInputStream.class.getDeclaredField("buf");
+                    f[0].setAccessible(true);
+                    f[1] = ByteArrayInputStream.class.getDeclaredField("pos");
+                    f[1].setAccessible(true);
+                } catch (NoSuchFieldException nsfe) {
+                    throw new InternalError(nsfe.getLocalizedMessage());
+                }
+                return null;
+            }
+        });
+        BAIS_BUF = f[0];
+        BAIS_POS = f[1];
+    }
+
+    /**
+     * Reads all bytes from {@link java.io.ByteArrayInputStream} using its
+     * underlying buffer directly.
+     * 
+     * @return an underlying buffer, if a current position is at the buffer
+     *         beginning, and an end position is at the buffer end, or a copy of
+     *         the underlying buffer part.
+     */
+    private static byte[] wrap(ByteArrayInputStream bais) {
+        byte[] buffer, buf;
+        int pos;
+        synchronized (bais) {
+            int available = bais.available();
+            try {
+                buf = (byte[]) BAIS_BUF.get(bais);
+                pos = BAIS_POS.getInt(bais);
+            } catch (IllegalAccessException iae) {
+                throw new InternalError(iae.getLocalizedMessage());
+            }
+            if (pos == 0 && available == buf.length) {
+                buffer = buf;
+            } else {
+                buffer = new byte[available];
+                System.arraycopy(buf, pos, buffer, 0, available);
+            }
+            bais.skip(available);
+        }
+        return buffer;
+    }
+
+    /**
+     * The utility method for reading the whole input stream into a snapshot
+     * buffer. To speed up the access it works with an underlying buffer for a
+     * given {@link java.io.ByteArrayInputStream}.
+     * 
+     * @param is
+     *            the stream to be read.
+     * @return the snapshot wrapping the buffer where the bytes are read to.
+     */
+    public static byte[] wrap(InputStream is) throws IOException {
+        if (is instanceof ExposedByteArrayInputStream) {
+            return ((ExposedByteArrayInputStream) is).expose();
+        }
+
+        if (is.getClass().equals(ByteArrayInputStream.class)) {
+            return wrap((ByteArrayInputStream) is);
+        }
+
+        // this may be slow, put optimizations suitable for your stream
+        // before trying this
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        byte[] buffer = new byte[8192];
+
+        while (true) {
+            int count = is.read(buffer);
+            if (count == -1) {
+                return baos.toByteArray();
+            }
+            baos.write(buffer, 0, count);
+        }
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ByteBuffer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExposedByteArrayInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExposedByteArrayInputStream.java?rev=641928&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExposedByteArrayInputStream.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExposedByteArrayInputStream.java
Thu Mar 27 11:02:32 2008
@@ -0,0 +1,57 @@
+/*
+ *  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.luni.util;
+
+import java.io.ByteArrayInputStream;
+
+/**
+ * The extension of <code>ByteArrayInputStream</code> which exposes an
+ * underlying buffer.
+ */
+public class ExposedByteArrayInputStream extends ByteArrayInputStream {
+
+    /**
+     * @see java.io.ByteArrayInputStream(byte[])
+     */
+    public ExposedByteArrayInputStream(byte buf[]) {
+        super(buf);
+    }
+
+    /**
+     * @see java.io.ByteArrayInputStream(byte[], int, int)
+     */
+    public ExposedByteArrayInputStream(byte buf[], int offset, int length) {
+        super(buf, offset, length);
+    }
+
+    /**
+     * Reads the whole stream and returns the stream snapshot.
+     */
+    public synchronized byte[] expose() {
+        if (pos == 0 && count == buf.length) {
+            skip(count);
+            return buf;
+        }
+
+        final int available = available();
+        final byte[] buffer = new byte[available];
+        System.arraycopy(buf, pos, buffer, 0, available);
+        skip(available);
+        return buffer;
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExposedByteArrayInputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ThreadLocalCache.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ThreadLocalCache.java?rev=641928&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ThreadLocalCache.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ThreadLocalCache.java
Thu Mar 27 11:02:32 2008
@@ -0,0 +1,103 @@
+/*
+ *  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.luni.util;
+
+import java.lang.ref.SoftReference;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+
+/**
+ * The class extends the functionality of {@link java.lang.ThreadLocal} with
+ * possibility of discarding the thread local storage content when a heap is
+ * exhausted.
+ */
+public class ThreadLocalCache<T> {
+
+    private SoftReference<ThreadLocal<T>> storage = new SoftReference<ThreadLocal<T>>(
+            null);
+
+    private ThreadLocal<T> getThreadLocal() {
+        ThreadLocal<T> tls = storage.get();
+        if (tls == null) {
+            tls = new ThreadLocal<T>() {
+                public T initialValue() {
+                    return ThreadLocalCache.this.initialValue();
+                }
+            };
+            storage = new SoftReference<ThreadLocal<T>>(tls);
+        }
+        return tls;
+    }
+
+    /**
+     * Returns the initial value for the cache for the current thread.
+     */
+    protected T initialValue() {
+        return null;
+    }
+
+    /**
+     * Returns the thread local value of this object.
+     */
+    public T get() {
+        return getThreadLocal().get();
+    }
+
+    /**
+     * Sets the value of this variable for the current thread. Might be useful
+     * for expanding the thread local cache.
+     */
+    public void set(T value) {
+        getThreadLocal().set(value);
+    }
+
+    /**
+     * Discards the cache for all threads.
+     */
+    public void remove() {
+        storage.clear();
+    }
+
+    public static ThreadLocalCache<CharsetDecoder> utf8Decoder = new ThreadLocalCache<CharsetDecoder>()
{
+        protected CharsetDecoder initialValue() {
+            return Charset.forName("UTF-8").newDecoder();
+        }
+    };
+
+    public static ThreadLocalCache<CharsetEncoder> utf8Encoder = new ThreadLocalCache<CharsetEncoder>()
{
+        protected CharsetEncoder initialValue() {
+            return Charset.forName("UTF-8").newEncoder();
+        }
+    };
+
+    public static ThreadLocalCache<java.nio.ByteBuffer> byteBuffer = new ThreadLocalCache<java.nio.ByteBuffer>()
{
+        protected java.nio.ByteBuffer initialValue() {
+            return java.nio.ByteBuffer.allocate(72); // >=
+            // Manifest.LINE_LENGTH_LIMIT
+        }
+    };
+
+    public static ThreadLocalCache<CharBuffer> charBuffer = new ThreadLocalCache<CharBuffer>()
{
+        protected CharBuffer initialValue() {
+            return CharBuffer.allocate(72); // no specific requirement
+        }
+    };
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ThreadLocalCache.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message