1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17package org.apache.harmony.archive.tests.java.util.jar;
18
19import java.io.ByteArrayInputStream;
20import java.io.ByteArrayOutputStream;
21import java.io.File;
22import java.io.IOException;
23import java.io.InputStream;
24import java.net.URL;
25import java.util.Map;
26import java.util.jar.Attributes;
27import java.util.jar.JarFile;
28import java.util.jar.Manifest;
29
30import junit.framework.TestCase;
31
32import tests.support.resource.Support_Resources;
33
34public class ManifestTest extends TestCase {
35
36    private final String JAR_NAME = "hyts_patch.jar";
37
38    private final String ATT_JAR_NAME = "hyts_att.jar";
39
40    private final String ATT_ENTRY_NAME = "HasAttributes.txt";
41
42    private final String ATT_ATT_NAME = "MyAttribute";
43
44    private final String MANIFEST_NAME = "manifest/hyts_MANIFEST.MF";
45
46    private static final String MANIFEST_CONTENTS = "Manifest-Version: 1.0\nBundle-Name: ClientSupport\nBundle-Description: Provides SessionService, AuthenticationService. Extends RegistryService.\nBundle-Activator: com.ibm.ive.eccomm.client.support.ClientSupportActivator\nImport-Package: com.ibm.ive.eccomm.client.services.log,\n com.ibm.ive.eccomm.client.services.registry,\n com.ibm.ive.eccomm.service.registry; specification-version=1.0.0,\n com.ibm.ive.eccomm.service.session; specification-version=1.0.0,\n com.ibm.ive.eccomm.service.framework; specification-version=1.2.0,\n org.osgi.framework; specification-version=1.0.0,\n org.osgi.service.log; specification-version=1.0.0,\n com.ibm.ive.eccomm.flash; specification-version=1.2.0,\n com.ibm.ive.eccomm.client.xml,\n com.ibm.ive.eccomm.client.http.common,\n com.ibm.ive.eccomm.client.http.client\nImport-Service: org.osgi.service.log.LogReaderService\n org.osgi.service.log.LogService,\n com.ibm.ive.eccomm.service.registry.RegistryService\nExport-Package: com.ibm.ive.eccomm.client.services.authentication; specification-version=1.0.0,\n com.ibm.ive.eccomm.service.authentication; specification-version=1.0.0,\n com.ibm.ive.eccomm.common; specification-version=1.0.0,\n com.ibm.ive.eccomm.client.services.registry.store; specification-version=1.0.0\nExport-Service: com.ibm.ive.eccomm.service.authentication.AuthenticationService,\n com.ibm.ive.eccomm.service.session.SessionService\nBundle-Vendor: IBM\nBundle-Version: 1.2.0\n";
47
48    private static final String MANIFEST_CONTENTS_1 = "Manifest-Version: 2.0\nBundle-Name: ClientSupport\nBundle-Description: Provides SessionService, AuthenticationService. Extends RegistryService.\nBundle-Activator: com.ibm.ive.eccomm.client.support.ClientSupportActivator\nImport-Package: com.ibm.ive.eccomm.client.services.log,\n com.ibm.ive.eccomm.client.services.registry,\n com.ibm.ive.eccomm.service.registry; specification-version=2.0.0,\n com.ibm.ive.eccomm.service.session; specification-version=2.0.0,\n com.ibm.ive.eccomm.service.framework; specification-version=2.1.0,\n org.osgi.framework; specification-version=2.0.0,\n org.osgi.service.log; specification-version=2.0.0,\n com.ibm.ive.eccomm.flash; specification-version=2.2.0,\n com.ibm.ive.eccomm.client.xml,\n com.ibm.ive.eccomm.client.http.common,\n com.ibm.ive.eccomm.client.http.client\nImport-Service: org.osgi.service.log.LogReaderService\n org.osgi.service.log.LogService,\n com.ibm.ive.eccomm.service.registry.RegistryService\nExport-Package: com.ibm.ive.eccomm.client.services.authentication; specification-version=1.0.0,\n com.ibm.ive.eccomm.service.authentication; specification-version=1.0.0,\n com.ibm.ive.eccomm.common; specification-version=1.0.0,\n com.ibm.ive.eccomm.client.services.registry.store; specification-version=1.0.0\nExport-Service: com.ibm.ive.eccomm.service.authentication.AuthenticationService,\n com.ibm.ive.eccomm.service.session.SessionService\nBundle-Vendor: IBM\nBundle-Version: 1.2.0\n";
49
50    private static final String MANIFEST_CONTENTS_2 = "Manifest-Version: 1.0\nName: value\n \n"; // Note penultimate line is single space
51
52    private File resources;
53
54    @Override
55    protected void setUp() {
56        resources = Support_Resources.createTempFolder();
57    }
58
59    private Manifest getManifest(String fileName) {
60        try {
61            Support_Resources.copyFile(resources, null, fileName);
62            JarFile jarFile = new JarFile(new File(resources, fileName));
63            Manifest m = jarFile.getManifest();
64            jarFile.close();
65            return m;
66        } catch (Exception e) {
67            fail("Exception during setup: " + e.toString());
68            return null;
69        }
70    }
71
72    /**
73     * @tests java.util.jar.Manifest#Manifest()
74     */
75    public void testConstructor() {
76        // Test for method java.util.jar.Manifest()
77        Manifest emptyManifest = new Manifest();
78        assertTrue("Should have no entries", emptyManifest.getEntries()
79                .isEmpty());
80        assertTrue("Should have no main attributes", emptyManifest
81                .getMainAttributes().isEmpty());
82    }
83
84    /**
85     * @tests java.util.jar.Manifest#Manifest(java.util.jar.Manifest)
86     */
87    public void testCopyingConstructor() throws IOException {
88        Manifest firstManifest = new Manifest(new ByteArrayInputStream(
89                MANIFEST_CONTENTS.getBytes("ISO-8859-1")));
90        Manifest secondManifest = new Manifest(firstManifest);
91        assertEquals(firstManifest, secondManifest);
92    }
93
94    private void assertAttribute(Attributes attr, String name, String value) {
95        assertEquals("Incorrect " + name, value, attr.getValue(name));
96    }
97
98    private void checkManifest(Manifest manifest) {
99        Attributes main = manifest.getMainAttributes();
100        assertAttribute(main, "Bundle-Name", "ClientSupport");
101        assertAttribute(main, "Bundle-Description",
102                "Provides SessionService, AuthenticationService. Extends RegistryService.");
103        assertAttribute(main, "Bundle-Activator",
104                "com.ibm.ive.eccomm.client.support.ClientSupportActivator");
105        assertAttribute(
106                main,
107                "Import-Package",
108                "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");
109        assertAttribute(
110                main,
111                "Import-Service",
112                "org.osgi.service.log.LogReaderServiceorg.osgi.service.log.LogService,com.ibm.ive.eccomm.service.registry.RegistryService");
113        assertAttribute(
114                main,
115                "Export-Package",
116                "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");
117        assertAttribute(
118                main,
119                "Export-Service",
120                "com.ibm.ive.eccomm.service.authentication.AuthenticationService,com.ibm.ive.eccomm.service.session.SessionService");
121        assertAttribute(main, "Bundle-Vendor", "IBM");
122        assertAttribute(main, "Bundle-Version", "1.2.0");
123    }
124
125    /**
126     * @tests java.util.jar.Manifest#Manifest(java.io.InputStream)
127     */
128    public void testStreamConstructor() throws IOException {
129        Manifest m = getManifest(ATT_JAR_NAME);
130        ByteArrayOutputStream baos = new ByteArrayOutputStream();
131        m.write(baos);
132        InputStream is = new ByteArrayInputStream(baos.toByteArray());
133        Manifest mCopy = new Manifest(is);
134        assertEquals(m, mCopy);
135
136        Manifest manifest = new Manifest(new ByteArrayInputStream(
137                MANIFEST_CONTENTS.getBytes("ISO-8859-1")));
138        checkManifest(manifest);
139
140        // regression test for HARMONY-5424
141        String manifestContent = "Manifest-Version: 1.0\nCreated-By: Apache\nPackage: \nBuild-Jdk: 1.4.1_01\n\n"
142                + "Name: \nSpecification-Title: foo\nSpecification-Version: 1.0\nSpecification-Vendor: \n"
143                + "Implementation-Title: \nImplementation-Version: 1.0\nImplementation-Vendor: \n\n";
144        ByteArrayInputStream bis = new ByteArrayInputStream(manifestContent
145                .getBytes("ISO-8859-1"));
146
147
148        Manifest mf = new Manifest(bis);
149        assertEquals("Should be 4 main attributes", 4, mf.getMainAttributes()
150                .size());
151
152        Map<String, Attributes> entries = mf.getEntries();
153        assertEquals("Should be one named entry", 1, entries.size());
154
155        Attributes namedEntryAttributes = (Attributes) (entries.get(""));
156        assertEquals("Should be 6 named entry attributes", 6,
157                namedEntryAttributes.size());
158
159        // Regression test for HARMONY-6669
160        new Manifest(new ByteArrayInputStream(
161            MANIFEST_CONTENTS_2.getBytes("ISO-8859-1")));
162    }
163
164    /**
165     * @tests java.util.jar.Manifest#clear()
166     */
167    public void testClear() {
168        Manifest m = getManifest(ATT_JAR_NAME);
169        m.clear();
170        assertTrue("Should have no entries", m.getEntries().isEmpty());
171        assertTrue("Should have no main attributes", m.getMainAttributes()
172                .isEmpty());
173    }
174
175    /**
176     * @tests java.util.jar.Manifest#clone()
177     */
178    public void testClone() {
179        Manifest m = getManifest(JAR_NAME);
180        assertEquals(m, m.clone());
181    }
182
183    /**
184     * @tests java.util.jar.Manifest#equals(java.lang.Object)
185     */
186    public void testEquals() throws IOException {
187        Manifest firstManifest = new Manifest(new ByteArrayInputStream(
188                MANIFEST_CONTENTS.getBytes("ISO-8859-1")));
189        Manifest secondManifest = new Manifest(new ByteArrayInputStream(
190                MANIFEST_CONTENTS.getBytes("ISO-8859-1")));
191
192        assertEquals(firstManifest, secondManifest);
193
194        Manifest thirdManifest = new Manifest(new ByteArrayInputStream(
195                MANIFEST_CONTENTS_1.getBytes("ISO-8859-1")));
196        assertNotSame(firstManifest, thirdManifest);
197
198        firstManifest=null;
199        assertFalse(secondManifest.equals(firstManifest));
200        assertFalse(secondManifest.equals(new String("abc"))); //non Manifest Object
201    }
202
203    /**
204     * @tests java.util.jar.Manifest#hashCode()
205     */
206    public void testHashCode() {
207        Manifest m = getManifest(JAR_NAME);
208        assertEquals(m.hashCode(), m.clone().hashCode());
209    }
210
211    /**
212     * @tests java.util.jar.Manifest#getAttributes(java.lang.String)
213     */
214    public void testGetAttributes() {
215        Manifest m = getManifest(ATT_JAR_NAME);
216        assertNull("Should not exist", m.getAttributes("Doesn't Exist"));
217        assertEquals("Should exist", "OK", m.getAttributes(ATT_ENTRY_NAME).get(
218                new Attributes.Name(ATT_ATT_NAME)));
219    }
220
221    /**
222     * @tests java.util.jar.Manifest#getEntries()
223     */
224    public void testGetEntries() {
225        Manifest m = getManifest(ATT_JAR_NAME);
226        Map<String, Attributes> myMap = m.getEntries();
227        assertNull("Shouldn't exist", myMap.get("Doesn't exist"));
228        assertEquals("Should exist", "OK", myMap.get(ATT_ENTRY_NAME).get(
229                new Attributes.Name(ATT_ATT_NAME)));
230    }
231
232    /**
233     * @tests java.util.jar.Manifest#getMainAttributes()
234     */
235    public void testGetMainAttributes() {
236        Manifest m = getManifest(JAR_NAME);
237        Attributes a = m.getMainAttributes();
238        assertEquals("Manifest_Version should return 1.0", "1.0", a
239                .get(Attributes.Name.MANIFEST_VERSION));
240    }
241
242    /**
243     * @tests {@link java.util.jar.Manifest#write(java.io.OutputStream)
244     */
245    public void testWrite() throws IOException {
246        ByteArrayOutputStream baos = new ByteArrayOutputStream();
247        Manifest m = getManifest(JAR_NAME);
248        // maximum allowed length is 72 for a header, colon and a following
249        // space
250        StringBuffer headerName = new StringBuffer(71);
251        headerName.append("Manifest-");
252        while (headerName.length() < 70) {
253            headerName.append("0");
254        }
255        m.getMainAttributes().put(new Attributes.Name(headerName.toString()),
256                "Value");
257        m.write(baos); // ok
258    }
259
260    /**
261     * Ensures compatibility with manifests produced by gcc.
262     *
263     * @see <a
264     *      href="http://issues.apache.org/jira/browse/HARMONY-5662">HARMONY-5662</a>
265     */
266    public void testNul() throws IOException {
267        String manifestContent =
268                "Manifest-Version: 1.0\nCreated-By: nasty gcc tool\n\n\0";
269
270        byte[] bytes = manifestContent.getBytes("ISO-8859-1");
271        new Manifest(new ByteArrayInputStream(bytes)); // the last NUL is ok
272
273        bytes[bytes.length - 1] = 26;
274        new Manifest(new ByteArrayInputStream(bytes)); // the last EOF is ok
275
276        bytes[bytes.length - 1] = 'A'; // the last line ignored
277        new Manifest(new ByteArrayInputStream(bytes));
278
279        bytes[2] = 0; // NUL char in Manifest
280        try {
281            new Manifest(new ByteArrayInputStream(bytes));
282            fail("IOException expected");
283        } catch (IOException e) {
284            // desired
285        }
286    }
287
288    public void testDecoding() throws IOException {
289        Manifest m = getManifest(ATT_JAR_NAME);
290        final byte[] bVendor = new byte[] { (byte) 0xd0, (byte) 0x9C,
291                (byte) 0xd0, (byte) 0xb8, (byte) 0xd0, (byte) 0xbb,
292                (byte) 0xd0, (byte) 0xb0, (byte) 0xd1, (byte) 0x8f, ' ',
293                (byte) 0xd0, (byte) 0xb4, (byte) 0xd0, (byte) 0xbe,
294                (byte) 0xd1, (byte) 0x87, (byte) 0xd1, (byte) 0x83,
295                (byte) 0xd0, (byte) 0xbd, (byte) 0xd1, (byte) 0x8C,
296                (byte) 0xd0, (byte) 0xba, (byte) 0xd0, (byte) 0xb0, ' ',
297                (byte) 0xd0, (byte) 0x9C, (byte) 0xd0, (byte) 0xb0,
298                (byte) 0xd1, (byte) 0x88, (byte) 0xd0, (byte) 0xb0 };
299
300        final byte[] bSpec = new byte[] { (byte) 0xe1, (byte) 0x88,
301                (byte) 0xb0, (byte) 0xe1, (byte) 0x88, (byte) 0x8b,
302                (byte) 0xe1, (byte) 0x88, (byte) 0x9d, ' ', (byte) 0xe1,
303                (byte) 0x9a, (byte) 0xa0, (byte) 0xe1, (byte) 0x9a,
304                (byte) 0xb1, (byte) 0xe1, (byte) 0x9b, (byte) 0x81,
305                (byte) 0xe1, (byte) 0x9a, (byte) 0xa6, ' ', (byte) 0xd8,
306                (byte) 0xb3, (byte) 0xd9, (byte) 0x84, (byte) 0xd8,
307                (byte) 0xa7, (byte) 0xd9, (byte) 0x85, ' ', (byte) 0xd8,
308                (byte) 0xb9, (byte) 0xd8, (byte) 0xb3, (byte) 0xd9,
309                (byte) 0x84, (byte) 0xd8, (byte) 0xa7, (byte) 0xd9,
310                (byte) 0x85, (byte) 0xd8, (byte) 0xa9, ' ', (byte) 0xdc,
311                (byte) 0xab, (byte) 0xdc, (byte) 0xa0, (byte) 0xdc,
312                (byte) 0xa1, (byte) 0xdc, (byte) 0x90, ' ', (byte) 0xe0,
313                (byte) 0xa6, (byte) 0xb6, (byte) 0xe0, (byte) 0xa6,
314                (byte) 0xbe, (byte) 0xe0, (byte) 0xa6, (byte) 0xa8,
315                (byte) 0xe0, (byte) 0xa7, (byte) 0x8d, (byte) 0xe0,
316                (byte) 0xa6, (byte) 0xa4, (byte) 0xe0, (byte) 0xa6,
317                (byte) 0xbf, ' ', (byte) 0xd0, (byte) 0xa0, (byte) 0xd0,
318                (byte) 0xb5, (byte) 0xd0, (byte) 0xba, (byte) 0xd1,
319                (byte) 0x8a, (byte) 0xd0, (byte) 0xb5, (byte) 0xd0,
320                (byte) 0xbb, ' ', (byte) 0xd0, (byte) 0x9c, (byte) 0xd0,
321                (byte) 0xb8, (byte) 0xd1, (byte) 0x80, ' ', (byte) 0xe0,
322                (byte) 0xa6, (byte) 0xb6, (byte) 0xe0, (byte) 0xa6,
323                (byte) 0xbe, (byte) 0xe0, (byte) 0xa6, (byte) 0xa8,
324                (byte) 0xe0, (byte) 0xa7, (byte) 0x8d, (byte) 0xe0,
325                (byte) 0xa6, (byte) 0xa4, (byte) 0xe0, (byte) 0xa6,
326                (byte) 0xbf, ' ', (byte) 0xe0, (byte) 0xbd, (byte) 0x9e,
327                (byte) 0xe0, (byte) 0xbd, (byte) 0xb2, (byte) 0xe0,
328                (byte) 0xbc, (byte) 0x8b, (byte) 0xe0, (byte) 0xbd,
329                (byte) 0x96, (byte) 0xe0, (byte) 0xbd, (byte) 0x91,
330                (byte) 0xe0, (byte) 0xbd, (byte) 0xba, ' ', (byte) 0xd0,
331                (byte) 0x9c, (byte) 0xd0, (byte) 0xb0, (byte) 0xd1,
332                (byte) 0x88, (byte) 0xd0, (byte) 0xb0, (byte) 0xd1,
333                (byte) 0x80, ' ', (byte) 0xe1, (byte) 0x8f, (byte) 0x99,
334                (byte) 0xe1, (byte) 0x8e, (byte) 0xaf, (byte) 0xe1,
335                (byte) 0x8f, (byte) 0xb1, ' ', (byte) 0xcf, (byte) 0xa8,
336                (byte) 0xce, (byte) 0xb9, (byte) 0xcf, (byte) 0x81,
337                (byte) 0xce, (byte) 0xb7, (byte) 0xce, (byte) 0xbd,
338                (byte) 0xce, (byte) 0xb7, ' ', (byte) 0xde, (byte) 0x90,
339                (byte) 0xde, (byte) 0xaa, (byte) 0xde, (byte) 0x85,
340                (byte) 0xde, (byte) 0xa6, ' ', (byte) 0xe0, (byte) 0xbd,
341                (byte) 0x82, (byte) 0xe0, (byte) 0xbd, (byte) 0x9e,
342                (byte) 0xe0, (byte) 0xbd, (byte) 0xb2, (byte) 0xe0,
343                (byte) 0xbc, (byte) 0x8b, (byte) 0xe0, (byte) 0xbd,
344                (byte) 0x96, (byte) 0xe0, (byte) 0xbd, (byte) 0x91,
345                (byte) 0xe0, (byte) 0xbd, (byte) 0xba, ' ', (byte) 0xce,
346                (byte) 0x95, (byte) 0xce, (byte) 0xb9, (byte) 0xcf,
347                (byte) 0x81, (byte) 0xce, (byte) 0xae, (byte) 0xce,
348                (byte) 0xbd, (byte) 0xce, (byte) 0xb7, ' ', (byte) 0xd8,
349                (byte) 0xb5, (byte) 0xd9, (byte) 0x84, (byte) 0xd8,
350                (byte) 0xad, ' ', (byte) 0xe0, (byte) 0xaa, (byte) 0xb6,
351                (byte) 0xe0, (byte) 0xaa, (byte) 0xbe, (byte) 0xe0,
352                (byte) 0xaa, (byte) 0x82, (byte) 0xe0, (byte) 0xaa,
353                (byte) 0xa4, (byte) 0xe0, (byte) 0xaa, (byte) 0xbf, ' ',
354                (byte) 0xe5, (byte) 0xb9, (byte) 0xb3, (byte) 0xe5,
355                (byte) 0x92, (byte) 0x8c, ' ', (byte) 0xd7, (byte) 0xa9,
356                (byte) 0xd7, (byte) 0x9c, (byte) 0xd7, (byte) 0x95,
357                (byte) 0xd7, (byte) 0x9d, ' ', (byte) 0xd7, (byte) 0xa4,
358                (byte) 0xd7, (byte) 0xa8, (byte) 0xd7, (byte) 0x99,
359                (byte) 0xd7, (byte) 0x93, (byte) 0xd7, (byte) 0x9f, ' ',
360                (byte) 0xe5, (byte) 0x92, (byte) 0x8c, (byte) 0xe5,
361                (byte) 0xb9, (byte) 0xb3, ' ', (byte) 0xe5, (byte) 0x92,
362                (byte) 0x8c, (byte) 0xe5, (byte) 0xb9, (byte) 0xb3, ' ',
363                (byte) 0xd8, (byte) 0xaa, (byte) 0xd9, (byte) 0x89,
364                (byte) 0xd9, (byte) 0x86, (byte) 0xda, (byte) 0x86,
365                (byte) 0xd9, (byte) 0x84, (byte) 0xd9, (byte) 0x89,
366                (byte) 0xd9, (byte) 0x82, ' ', (byte) 0xe0, (byte) 0xae,
367                (byte) 0x85, (byte) 0xe0, (byte) 0xae, (byte) 0xae,
368                (byte) 0xe0, (byte) 0xaf, (byte) 0x88, (byte) 0xe0,
369                (byte) 0xae, (byte) 0xa4, (byte) 0xe0, (byte) 0xae,
370                (byte) 0xbf, ' ', (byte) 0xe0, (byte) 0xb0, (byte) 0xb6,
371                (byte) 0xe0, (byte) 0xb0, (byte) 0xbe, (byte) 0xe0,
372                (byte) 0xb0, (byte) 0x82, (byte) 0xe0, (byte) 0xb0,
373                (byte) 0xa4, (byte) 0xe0, (byte) 0xb0, (byte) 0xbf, ' ',
374                (byte) 0xe0, (byte) 0xb8, (byte) 0xaa, (byte) 0xe0,
375                (byte) 0xb8, (byte) 0xb1, (byte) 0xe0, (byte) 0xb8,
376                (byte) 0x99, (byte) 0xe0, (byte) 0xb8, (byte) 0x95,
377                (byte) 0xe0, (byte) 0xb8, (byte) 0xb4, (byte) 0xe0,
378                (byte) 0xb8, (byte) 0xa0, (byte) 0xe0, (byte) 0xb8,
379                (byte) 0xb2, (byte) 0xe0, (byte) 0xb8, (byte) 0x9e, ' ',
380                (byte) 0xe1, (byte) 0x88, (byte) 0xb0, (byte) 0xe1,
381                (byte) 0x88, (byte) 0x8b, (byte) 0xe1, (byte) 0x88,
382                (byte) 0x9d, ' ', (byte) 0xe0, (byte) 0xb7, (byte) 0x83,
383                (byte) 0xe0, (byte) 0xb7, (byte) 0x8f, (byte) 0xe0,
384                (byte) 0xb6, (byte) 0xb8, (byte) 0xe0, (byte) 0xb6,
385                (byte) 0xba, ' ', (byte) 0xe0, (byte) 0xa4, (byte) 0xb6,
386                (byte) 0xe0, (byte) 0xa4, (byte) 0xbe, (byte) 0xe0,
387                (byte) 0xa4, (byte) 0xa8, (byte) 0xe0, (byte) 0xa5,
388                (byte) 0x8d, (byte) 0xe0, (byte) 0xa4, (byte) 0xa4,
389                (byte) 0xe0, (byte) 0xa4, (byte) 0xbf, (byte) 0xe0,
390                (byte) 0xa4, (byte) 0x83, ' ', (byte) 0xe1, (byte) 0x83,
391                (byte) 0x9b, (byte) 0xe1, (byte) 0x83, (byte) 0xa8,
392                (byte) 0xe1, (byte) 0x83, (byte) 0x95, (byte) 0xe1,
393                (byte) 0x83, (byte) 0x98, (byte) 0xe1, (byte) 0x83,
394                (byte) 0x93, (byte) 0xe1, (byte) 0x83, (byte) 0x9d,
395                (byte) 0xe1, (byte) 0x83, (byte) 0x91, (byte) 0xe1,
396                (byte) 0x83, (byte) 0x90 };
397        // TODO Cannot make the following word work, encoder changes needed
398        // (byte) 0xed, (byte) 0xa0, (byte) 0x80,
399        // (byte) 0xed, (byte) 0xbc, (byte) 0xb2, (byte) 0xed,
400        // (byte) 0xa0, (byte) 0x80, (byte) 0xed, (byte) 0xbc,
401        // (byte) 0xb0, (byte) 0xed, (byte) 0xa0, (byte) 0x80,
402        // (byte) 0xed, (byte) 0xbd, (byte) 0x85, (byte) 0xed,
403        // (byte) 0xa0, (byte) 0x80, (byte) 0xed, (byte) 0xbc,
404        // (byte) 0xb0, (byte) 0xed, (byte) 0xa0, (byte) 0x80,
405        // (byte) 0xed, (byte) 0xbc, (byte) 0xb9, (byte) 0xed,
406        // (byte) 0xa0, (byte) 0x80, (byte) 0xed, (byte) 0xbc,
407        // (byte) 0xb8, (byte) 0xed, (byte) 0xa0, (byte) 0x80,
408        // (byte) 0xed, (byte) 0xbc, (byte) 0xb9, ' '
409
410        final String vendor = new String(bVendor, "UTF-8");
411        final String spec = new String(bSpec, "UTF-8");
412        m.getMainAttributes()
413                .put(Attributes.Name.IMPLEMENTATION_VENDOR, vendor);
414        m.getAttributes(ATT_ENTRY_NAME).put(
415                Attributes.Name.IMPLEMENTATION_VENDOR, vendor);
416        m.getEntries().get(ATT_ENTRY_NAME).put(
417                Attributes.Name.SPECIFICATION_TITLE, spec);
418
419        ByteArrayOutputStream baos = new ByteArrayOutputStream();
420        m.write(baos);
421        m = new Manifest(new ByteArrayInputStream(baos.toByteArray()));
422
423        assertEquals(vendor, m.getMainAttributes().get(
424                Attributes.Name.IMPLEMENTATION_VENDOR));
425        assertEquals(vendor, m.getEntries().get(ATT_ENTRY_NAME).get(
426                Attributes.Name.IMPLEMENTATION_VENDOR));
427        assertEquals(spec, m.getAttributes(ATT_ENTRY_NAME).get(
428                Attributes.Name.SPECIFICATION_TITLE));
429    }
430
431    /**
432     * @tests {@link java.util.jar.Manifest#read(java.io.InputStream)
433     */
434    public void testRead() {
435        // Regression for HARMONY-89
436        InputStream is = new InputStreamImpl();
437        try {
438            new Manifest().read(is);
439            fail("IOException expected");
440        } catch (IOException e) {
441            // desired
442        }
443    }
444
445    // helper class
446    private class InputStreamImpl extends InputStream {
447        public InputStreamImpl() {
448            super();
449        }
450
451        @Override
452        public int read() {
453            return 0;
454        }
455    }
456}
457