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 dalvik.annotation.KnownFailure;
20import dalvik.annotation.TestLevel;
21import dalvik.annotation.TestTargetClass;
22import dalvik.annotation.TestTargetNew;
23
24import java.io.ByteArrayInputStream;
25import java.io.ByteArrayOutputStream;
26import java.io.File;
27import java.io.FileOutputStream;
28import java.io.IOException;
29import java.io.InputStream;
30import java.net.URL;
31import java.net.MalformedURLException;
32import java.util.Map;
33import java.util.jar.Attributes;
34import java.util.jar.JarFile;
35import java.util.jar.Manifest;
36
37import junit.framework.TestCase;
38
39import tests.support.resource.Support_Resources;
40
41@TestTargetClass(Manifest.class)
42public class ManifestTest extends TestCase {
43
44    private final String jarName = "hyts_patch.jar";
45
46    private final String attJarName = "hyts_att.jar";
47
48    private Manifest m;
49
50    private Manifest m2;
51
52    private final String ATT_ENTRY_NAME = "HasAttributes.txt";
53
54    private final String MANIFEST_NAME = "manifest/hyts_MANIFEST.MF";
55
56    private File resources;
57
58    @Override
59    protected void setUp() {
60        resources = Support_Resources.createTempFolder();
61        try {
62            Support_Resources.copyFile(resources, null, jarName);
63            JarFile jarFile = new JarFile(new File(resources, jarName));
64            m = jarFile.getManifest();
65            jarFile.close();
66            Support_Resources.copyFile(resources, null, attJarName);
67            jarFile = new JarFile(new File(resources, attJarName));
68            m2 = jarFile.getManifest();
69            jarFile.close();
70        } catch (Exception e) {
71            fail("Exception during setup: " + e.toString());
72        }
73    }
74
75    private Manifest getManifest(String fileName) {
76        try {
77            Support_Resources.copyFile(resources, null, fileName);
78            JarFile jarFile = new JarFile(new File(resources, fileName));
79            Manifest m = jarFile.getManifest();
80            jarFile.close();
81            return m;
82        } catch (Exception e) {
83            fail("Exception during setup: " + e.toString());
84            return null;
85        }
86    }
87
88    /**
89     * @tests java.util.jar.Manifest#Manifest()
90     */
91    @TestTargetNew(
92        level = TestLevel.COMPLETE,
93        notes = "",
94        method = "Manifest",
95        args = {}
96    )
97    public void test_Constructor() {
98        // Test for method java.util.jar.Manifest()
99        Manifest emptyManifest = new Manifest();
100        assertTrue("Should have no entries", emptyManifest.getEntries()
101                .isEmpty());
102        assertTrue("Should have no main attributes", emptyManifest
103                .getMainAttributes().isEmpty());
104    }
105
106    /**
107     * @tests java.util.jar.Manifest#Manifest(java.util.jar.Manifest)
108     */
109    @TestTargetNew(
110            level = TestLevel.PARTIAL_COMPLETE,
111            notes = "",
112            method = "Manifest",
113            args = {java.util.jar.Manifest.class}
114    )
115    public void testCopyingConstructor() throws IOException {
116        Manifest firstManifest = new Manifest(new URL(Support_Resources
117                .getURL(MANIFEST_NAME)).openStream());
118        Manifest secondManifest = new Manifest(firstManifest);
119        assertEquals(firstManifest, secondManifest);
120    }
121
122    /**
123     * @tests java.util.jar.Manifest#Manifest(Manifest)
124     */
125    @TestTargetNew(
126            level = TestLevel.PARTIAL_COMPLETE,
127            notes = "",
128            method = "Manifest",
129            args = {java.util.jar.Manifest.class}
130    )
131    public void test_ConstructorLjava_util_jar_Manifest() {
132        // Test for method java.util.jar.Manifest()
133        Manifest emptyManifest = new Manifest();
134        Manifest emptyClone = new Manifest(emptyManifest);
135        assertTrue("Should have no entries", emptyClone.getEntries().isEmpty());
136        assertTrue("Should have no main attributes", emptyClone
137                .getMainAttributes().isEmpty());
138        assertEquals(emptyClone, emptyManifest);
139        assertEquals(emptyClone, emptyManifest.clone());
140    }
141
142    private void assertAttribute(Attributes attr, String name, String value) {
143        assertEquals("Incorrect " + name, value, attr.getValue(name));
144    }
145
146    private void checkManifest(Manifest manifest) {
147        Attributes main = manifest.getMainAttributes();
148        assertAttribute(main, "Bundle-Name", "ClientSupport");
149        assertAttribute(main, "Bundle-Description",
150                "Provides SessionService, AuthenticationService. Extends RegistryService.");
151        assertAttribute(main, "Bundle-Activator",
152                "com.ibm.ive.eccomm.client.support.ClientSupportActivator");
153        assertAttribute(
154                main,
155                "Import-Package",
156                "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");
157        assertAttribute(
158                main,
159                "Import-Service",
160                "org.osgi.service.log.LogReaderServiceorg.osgi.service.log.LogService,com.ibm.ive.eccomm.service.registry.RegistryService");
161        assertAttribute(
162                main,
163                "Export-Package",
164                "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");
165        assertAttribute(
166                main,
167                "Export-Service",
168                "com.ibm.ive.eccomm.service.authentication.AuthenticationService,com.ibm.ive.eccomm.service.session.SessionService");
169        assertAttribute(main, "Bundle-Vendor", "IBM");
170        assertAttribute(main, "Bundle-Version", "1.2.0");
171    }
172
173    /**
174     * @tests java.util.jar.Manifest#Manifest(java.io.InputStream)
175     */
176    @TestTargetNew(
177        level = TestLevel.COMPLETE,
178        notes = "IOException checking missed.",
179        method = "Manifest",
180        args = {java.io.InputStream.class}
181    )
182    public void test_ConstructorLjava_io_InputStream() throws IOException {
183        Manifest m = getManifest(attJarName);
184        ByteArrayOutputStream baos = new ByteArrayOutputStream();
185        m.write(baos);
186        InputStream is = new ByteArrayInputStream(baos.toByteArray());
187        Manifest mCopy = new Manifest(is);
188        assertEquals(m, mCopy);
189
190        Manifest manifest = new Manifest(new URL(Support_Resources
191                .getURL(MANIFEST_NAME)).openStream());
192        checkManifest(manifest);
193
194        // regression test for HARMONY-5424
195        String manifestContent = "Manifest-Version: 1.0\nCreated-By: Apache\nPackage: \nBuild-Jdk: 1.4.1_01\n\n"
196                + "Name: \nSpecification-Title: foo\nSpecification-Version: 1.0\nSpecification-Vendor: \n"
197                + "Implementation-Title: \nImplementation-Version: 1.0\nImplementation-Vendor: \n\n";
198        ByteArrayInputStream bis = new ByteArrayInputStream(manifestContent
199                .getBytes("ISO-8859-1"));
200
201
202        Manifest mf = new Manifest(bis);
203        assertEquals("Should be 4 main attributes", 4, mf.getMainAttributes()
204                .size());
205
206        Map<String, Attributes> entries = mf.getEntries();
207        assertEquals("Should be one named entry", 1, entries.size());
208
209        Attributes namedEntryAttributes = (Attributes) (entries.get(""));
210        assertEquals("Should be 6 named entry attributes", 6,
211                namedEntryAttributes.size());
212    }
213
214    /**
215     * @tests java.util.jar.Manifest#clear()
216     */
217    @TestTargetNew(
218            level = TestLevel.COMPLETE,
219            notes = "",
220            method = "clear",
221            args = {}
222    )
223    public void test_clear() {
224        m2.clear();
225        assertTrue("Should have no entries", m2.getEntries().isEmpty());
226        assertTrue("Should have no main attributes", m2.getMainAttributes()
227                .isEmpty());
228    }
229
230    @TestTargetNew(
231            level = TestLevel.COMPLETE,
232            notes = "",
233            method = "clone",
234            args = {}
235    )
236    public void test_clone() throws IOException {
237        Manifest emptyManifest = new Manifest();
238        Manifest emptyClone = (Manifest) emptyManifest.clone();
239        assertTrue("Should have no entries", emptyClone.getEntries().isEmpty());
240        assertTrue("Should have no main attributes", emptyClone
241                .getMainAttributes().isEmpty());
242        assertEquals(emptyClone, emptyManifest);
243        assertEquals(emptyManifest.clone().getClass().getName(),
244                "java.util.jar.Manifest");
245
246        Manifest manifest = new Manifest(new URL(Support_Resources
247                .getURL("manifest/hyts_MANIFEST.MF")).openStream());
248        Manifest manifestClone = (Manifest) manifest.clone();
249        manifestClone.getMainAttributes();
250        checkManifest(manifestClone);
251    }
252
253    @TestTargetNew(
254            level = TestLevel.COMPLETE,
255            notes = "",
256            method = "equals",
257            args = {java.lang.Object.class}
258    )
259    public void test_equals() throws IOException {
260        Manifest manifest1 = new Manifest(new URL(Support_Resources.getURL(
261                "manifest/hyts_MANIFEST.MF")).openStream());
262        Manifest manifest2 = new Manifest(new URL(Support_Resources.getURL(
263                "manifest/hyts_MANIFEST.MF")).openStream());
264        Manifest manifest3 = new Manifest();
265
266        assertTrue(manifest1.equals(manifest1));
267        assertTrue(manifest1.equals(manifest2));
268        assertFalse(manifest1.equals(manifest3));
269        assertFalse(manifest1.equals(this));
270    }
271
272    @TestTargetNew(
273            level = TestLevel.COMPLETE,
274            notes = "",
275            method = "hashCode",
276            args = {}
277    )
278    public void test_hashCode() throws IOException {
279        Manifest manifest1 = new Manifest(new URL(Support_Resources
280                .getURL("manifest/hyts_MANIFEST.MF")).openStream());
281        Manifest manifest2 = new Manifest();
282        assertEquals(manifest1.hashCode(), manifest1.hashCode());
283        assertNotSame(manifest1.hashCode(), manifest2.hashCode());
284    }
285
286	/**
287	 * @tests java.util.jar.Manifest#getAttributes(java.lang.String)
288	 */
289    @TestTargetNew(
290            level = TestLevel.COMPLETE,
291            notes = "",
292            method = "getAttributes",
293            args = {String.class}
294    )
295	public void test_getAttributesLjava_lang_String() {
296		assertNull("Should not exist",
297				m2.getAttributes("Doesn't Exist"));
298		assertEquals("Should exist", "OK", m2.getAttributes("HasAttributes.txt").get(
299				new Attributes.Name("MyAttribute")));
300	}
301
302	/**
303	 * @tests java.util.jar.Manifest#getEntries()
304	 */
305    @TestTargetNew(
306            level = TestLevel.COMPLETE,
307            notes = "",
308            method = "getEntries",
309            args = {}
310    )
311	public void test_getEntries() {
312		Map<String, Attributes> myMap = m2.getEntries();
313		assertNull("Shouldn't exist", myMap.get("Doesn't exist"));
314		assertEquals("Should exist",
315				"OK", myMap.get("HasAttributes.txt").get(
316						new Attributes.Name("MyAttribute")));
317	}
318
319	/**
320	 * @tests java.util.jar.Manifest#getMainAttributes()
321	 */
322    @TestTargetNew(
323            level = TestLevel.COMPLETE,
324            notes = "",
325            method = "getMainAttributes",
326            args = {}
327    )
328	public void test_getMainAttributes() {
329		// Test for method java.util.jar.Attributes
330		// java.util.jar.Manifest.getMainAttributes()
331		Attributes a = m.getMainAttributes();
332		assertEquals("Manifest_Version should return 1.0", "1.0", a.get(
333				Attributes.Name.MANIFEST_VERSION));
334	}
335
336    @TestTargetNew(
337        level = TestLevel.COMPLETE,
338        notes = "",
339        method = "write",
340        args = {java.io.OutputStream.class}
341    )
342    public void test_writeLjava_io_OutputStream() throws IOException {
343        byte b[] = null;
344        Manifest manifest1 = null;
345        Manifest manifest2 = null;
346        InputStream is = null;
347        try {
348            manifest1 = new Manifest(new URL(Support_Resources
349                    .getURL("manifest/hyts_MANIFEST.MF")).openStream());
350        } catch (MalformedURLException e) {
351            fail("Malformed URL");
352        }
353
354        ByteArrayOutputStream baos = new ByteArrayOutputStream();
355
356        manifest1.write(baos);
357
358        b = baos.toByteArray();
359
360        File f = File.createTempFile("111", "111");
361        FileOutputStream fos = new FileOutputStream(f);
362        fos.close();
363        try {
364            manifest1.write(fos);
365            fail("IOException expected");
366        } catch (IOException e) {
367            // expected
368        }
369        f.delete();
370
371        ByteArrayInputStream bais = new ByteArrayInputStream(b);
372
373        try {
374            manifest2 = new Manifest(bais);
375        } catch (MalformedURLException e) {
376            fail("Malformed URL");
377        }
378
379        assertTrue(manifest1.equals(manifest2));
380    }
381
382    /**
383     * Ensures compatibility with manifests produced by gcc.
384     *
385     * @see <a
386     *      href="http://issues.apache.org/jira/browse/HARMONY-5662">HARMONY-5662</a>
387     */
388    @TestTargetNew(
389            level = TestLevel.PARTIAL_COMPLETE,
390            notes = "",
391            method = "Manifest",
392            args = {InputStream.class}
393    )
394    public void testNul() throws IOException {
395        String manifestContent =
396                "Manifest-Version: 1.0\nCreated-By: nasty gcc tool\n\n\0";
397
398        byte[] bytes = manifestContent.getBytes("ISO-8859-1");
399        new Manifest(new ByteArrayInputStream(bytes)); // the last NUL is ok
400
401        bytes[bytes.length - 1] = 26;
402        new Manifest(new ByteArrayInputStream(bytes)); // the last EOF is ok
403
404        bytes[bytes.length - 1] = 'A'; // the last line ignored
405        new Manifest(new ByteArrayInputStream(bytes));
406
407        bytes[2] = 0; // NUL char in Manifest
408        try {
409            new Manifest(new ByteArrayInputStream(bytes));
410            fail("IOException expected");
411        } catch (IOException e) {
412            // desired
413        }
414    }
415
416    @TestTargetNew(
417            level = TestLevel.PARTIAL_COMPLETE,
418            method = "Manifest",
419            args = {InputStream.class}
420    )
421    @KnownFailure("CharsetDecoder fails with an IllegalStateException")
422    public void testDecoding() throws IOException {
423        Manifest m = getManifest(attJarName);
424        final byte[] bVendor = new byte[] { (byte) 0xd0, (byte) 0x9C,
425                (byte) 0xd0, (byte) 0xb8, (byte) 0xd0, (byte) 0xbb,
426                (byte) 0xd0, (byte) 0xb0, (byte) 0xd1, (byte) 0x8f, ' ',
427                (byte) 0xd0, (byte) 0xb4, (byte) 0xd0, (byte) 0xbe,
428                (byte) 0xd1, (byte) 0x87, (byte) 0xd1, (byte) 0x83,
429                (byte) 0xd0, (byte) 0xbd, (byte) 0xd1, (byte) 0x8C,
430                (byte) 0xd0, (byte) 0xba, (byte) 0xd0, (byte) 0xb0, ' ',
431                (byte) 0xd0, (byte) 0x9C, (byte) 0xd0, (byte) 0xb0,
432                (byte) 0xd1, (byte) 0x88, (byte) 0xd0, (byte) 0xb0 };
433
434        final byte[] bSpec = new byte[] { (byte) 0xe1, (byte) 0x88,
435                (byte) 0xb0, (byte) 0xe1, (byte) 0x88, (byte) 0x8b,
436                (byte) 0xe1, (byte) 0x88, (byte) 0x9d, ' ', (byte) 0xe1,
437                (byte) 0x9a, (byte) 0xa0, (byte) 0xe1, (byte) 0x9a,
438                (byte) 0xb1, (byte) 0xe1, (byte) 0x9b, (byte) 0x81,
439                (byte) 0xe1, (byte) 0x9a, (byte) 0xa6, ' ', (byte) 0xd8,
440                (byte) 0xb3, (byte) 0xd9, (byte) 0x84, (byte) 0xd8,
441                (byte) 0xa7, (byte) 0xd9, (byte) 0x85, ' ', (byte) 0xd8,
442                (byte) 0xb9, (byte) 0xd8, (byte) 0xb3, (byte) 0xd9,
443                (byte) 0x84, (byte) 0xd8, (byte) 0xa7, (byte) 0xd9,
444                (byte) 0x85, (byte) 0xd8, (byte) 0xa9, ' ', (byte) 0xdc,
445                (byte) 0xab, (byte) 0xdc, (byte) 0xa0, (byte) 0xdc,
446                (byte) 0xa1, (byte) 0xdc, (byte) 0x90, ' ', (byte) 0xe0,
447                (byte) 0xa6, (byte) 0xb6, (byte) 0xe0, (byte) 0xa6,
448                (byte) 0xbe, (byte) 0xe0, (byte) 0xa6, (byte) 0xa8,
449                (byte) 0xe0, (byte) 0xa7, (byte) 0x8d, (byte) 0xe0,
450                (byte) 0xa6, (byte) 0xa4, (byte) 0xe0, (byte) 0xa6,
451                (byte) 0xbf, ' ', (byte) 0xd0, (byte) 0xa0, (byte) 0xd0,
452                (byte) 0xb5, (byte) 0xd0, (byte) 0xba, (byte) 0xd1,
453                (byte) 0x8a, (byte) 0xd0, (byte) 0xb5, (byte) 0xd0,
454                (byte) 0xbb, ' ', (byte) 0xd0, (byte) 0x9c, (byte) 0xd0,
455                (byte) 0xb8, (byte) 0xd1, (byte) 0x80, ' ', (byte) 0xe0,
456                (byte) 0xa6, (byte) 0xb6, (byte) 0xe0, (byte) 0xa6,
457                (byte) 0xbe, (byte) 0xe0, (byte) 0xa6, (byte) 0xa8,
458                (byte) 0xe0, (byte) 0xa7, (byte) 0x8d, (byte) 0xe0,
459                (byte) 0xa6, (byte) 0xa4, (byte) 0xe0, (byte) 0xa6,
460                (byte) 0xbf, ' ', (byte) 0xe0, (byte) 0xbd, (byte) 0x9e,
461                (byte) 0xe0, (byte) 0xbd, (byte) 0xb2, (byte) 0xe0,
462                (byte) 0xbc, (byte) 0x8b, (byte) 0xe0, (byte) 0xbd,
463                (byte) 0x96, (byte) 0xe0, (byte) 0xbd, (byte) 0x91,
464                (byte) 0xe0, (byte) 0xbd, (byte) 0xba, ' ', (byte) 0xd0,
465                (byte) 0x9c, (byte) 0xd0, (byte) 0xb0, (byte) 0xd1,
466                (byte) 0x88, (byte) 0xd0, (byte) 0xb0, (byte) 0xd1,
467                (byte) 0x80, ' ', (byte) 0xe1, (byte) 0x8f, (byte) 0x99,
468                (byte) 0xe1, (byte) 0x8e, (byte) 0xaf, (byte) 0xe1,
469                (byte) 0x8f, (byte) 0xb1, ' ', (byte) 0xcf, (byte) 0xa8,
470                (byte) 0xce, (byte) 0xb9, (byte) 0xcf, (byte) 0x81,
471                (byte) 0xce, (byte) 0xb7, (byte) 0xce, (byte) 0xbd,
472                (byte) 0xce, (byte) 0xb7, ' ', (byte) 0xde, (byte) 0x90,
473                (byte) 0xde, (byte) 0xaa, (byte) 0xde, (byte) 0x85,
474                (byte) 0xde, (byte) 0xa6, ' ', (byte) 0xe0, (byte) 0xbd,
475                (byte) 0x82, (byte) 0xe0, (byte) 0xbd, (byte) 0x9e,
476                (byte) 0xe0, (byte) 0xbd, (byte) 0xb2, (byte) 0xe0,
477                (byte) 0xbc, (byte) 0x8b, (byte) 0xe0, (byte) 0xbd,
478                (byte) 0x96, (byte) 0xe0, (byte) 0xbd, (byte) 0x91,
479                (byte) 0xe0, (byte) 0xbd, (byte) 0xba, ' ', (byte) 0xce,
480                (byte) 0x95, (byte) 0xce, (byte) 0xb9, (byte) 0xcf,
481                (byte) 0x81, (byte) 0xce, (byte) 0xae, (byte) 0xce,
482                (byte) 0xbd, (byte) 0xce, (byte) 0xb7, ' ', (byte) 0xd8,
483                (byte) 0xb5, (byte) 0xd9, (byte) 0x84, (byte) 0xd8,
484                (byte) 0xad, ' ', (byte) 0xe0, (byte) 0xaa, (byte) 0xb6,
485                (byte) 0xe0, (byte) 0xaa, (byte) 0xbe, (byte) 0xe0,
486                (byte) 0xaa, (byte) 0x82, (byte) 0xe0, (byte) 0xaa,
487                (byte) 0xa4, (byte) 0xe0, (byte) 0xaa, (byte) 0xbf, ' ',
488                (byte) 0xe5, (byte) 0xb9, (byte) 0xb3, (byte) 0xe5,
489                (byte) 0x92, (byte) 0x8c, ' ', (byte) 0xd7, (byte) 0xa9,
490                (byte) 0xd7, (byte) 0x9c, (byte) 0xd7, (byte) 0x95,
491                (byte) 0xd7, (byte) 0x9d, ' ', (byte) 0xd7, (byte) 0xa4,
492                (byte) 0xd7, (byte) 0xa8, (byte) 0xd7, (byte) 0x99,
493                (byte) 0xd7, (byte) 0x93, (byte) 0xd7, (byte) 0x9f, ' ',
494                (byte) 0xe5, (byte) 0x92, (byte) 0x8c, (byte) 0xe5,
495                (byte) 0xb9, (byte) 0xb3, ' ', (byte) 0xe5, (byte) 0x92,
496                (byte) 0x8c, (byte) 0xe5, (byte) 0xb9, (byte) 0xb3, ' ',
497                (byte) 0xd8, (byte) 0xaa, (byte) 0xd9, (byte) 0x89,
498                (byte) 0xd9, (byte) 0x86, (byte) 0xda, (byte) 0x86,
499                (byte) 0xd9, (byte) 0x84, (byte) 0xd9, (byte) 0x89,
500                (byte) 0xd9, (byte) 0x82, ' ', (byte) 0xe0, (byte) 0xae,
501                (byte) 0x85, (byte) 0xe0, (byte) 0xae, (byte) 0xae,
502                (byte) 0xe0, (byte) 0xaf, (byte) 0x88, (byte) 0xe0,
503                (byte) 0xae, (byte) 0xa4, (byte) 0xe0, (byte) 0xae,
504                (byte) 0xbf, ' ', (byte) 0xe0, (byte) 0xb0, (byte) 0xb6,
505                (byte) 0xe0, (byte) 0xb0, (byte) 0xbe, (byte) 0xe0,
506                (byte) 0xb0, (byte) 0x82, (byte) 0xe0, (byte) 0xb0,
507                (byte) 0xa4, (byte) 0xe0, (byte) 0xb0, (byte) 0xbf, ' ',
508                (byte) 0xe0, (byte) 0xb8, (byte) 0xaa, (byte) 0xe0,
509                (byte) 0xb8, (byte) 0xb1, (byte) 0xe0, (byte) 0xb8,
510                (byte) 0x99, (byte) 0xe0, (byte) 0xb8, (byte) 0x95,
511                (byte) 0xe0, (byte) 0xb8, (byte) 0xb4, (byte) 0xe0,
512                (byte) 0xb8, (byte) 0xa0, (byte) 0xe0, (byte) 0xb8,
513                (byte) 0xb2, (byte) 0xe0, (byte) 0xb8, (byte) 0x9e, ' ',
514                (byte) 0xe1, (byte) 0x88, (byte) 0xb0, (byte) 0xe1,
515                (byte) 0x88, (byte) 0x8b, (byte) 0xe1, (byte) 0x88,
516                (byte) 0x9d, ' ', (byte) 0xe0, (byte) 0xb7, (byte) 0x83,
517                (byte) 0xe0, (byte) 0xb7, (byte) 0x8f, (byte) 0xe0,
518                (byte) 0xb6, (byte) 0xb8, (byte) 0xe0, (byte) 0xb6,
519                (byte) 0xba, ' ', (byte) 0xe0, (byte) 0xa4, (byte) 0xb6,
520                (byte) 0xe0, (byte) 0xa4, (byte) 0xbe, (byte) 0xe0,
521                (byte) 0xa4, (byte) 0xa8, (byte) 0xe0, (byte) 0xa5,
522                (byte) 0x8d, (byte) 0xe0, (byte) 0xa4, (byte) 0xa4,
523                (byte) 0xe0, (byte) 0xa4, (byte) 0xbf, (byte) 0xe0,
524                (byte) 0xa4, (byte) 0x83, ' ', (byte) 0xe1, (byte) 0x83,
525                (byte) 0x9b, (byte) 0xe1, (byte) 0x83, (byte) 0xa8,
526                (byte) 0xe1, (byte) 0x83, (byte) 0x95, (byte) 0xe1,
527                (byte) 0x83, (byte) 0x98, (byte) 0xe1, (byte) 0x83,
528                (byte) 0x93, (byte) 0xe1, (byte) 0x83, (byte) 0x9d,
529                (byte) 0xe1, (byte) 0x83, (byte) 0x91, (byte) 0xe1,
530                (byte) 0x83, (byte) 0x90 };
531        // TODO Cannot make the following word work, encoder changes needed
532        // (byte) 0xed, (byte) 0xa0, (byte) 0x80,
533        // (byte) 0xed, (byte) 0xbc, (byte) 0xb2, (byte) 0xed,
534        // (byte) 0xa0, (byte) 0x80, (byte) 0xed, (byte) 0xbc,
535        // (byte) 0xb0, (byte) 0xed, (byte) 0xa0, (byte) 0x80,
536        // (byte) 0xed, (byte) 0xbd, (byte) 0x85, (byte) 0xed,
537        // (byte) 0xa0, (byte) 0x80, (byte) 0xed, (byte) 0xbc,
538        // (byte) 0xb0, (byte) 0xed, (byte) 0xa0, (byte) 0x80,
539        // (byte) 0xed, (byte) 0xbc, (byte) 0xb9, (byte) 0xed,
540        // (byte) 0xa0, (byte) 0x80, (byte) 0xed, (byte) 0xbc,
541        // (byte) 0xb8, (byte) 0xed, (byte) 0xa0, (byte) 0x80,
542        // (byte) 0xed, (byte) 0xbc, (byte) 0xb9, ' '
543
544        final String vendor = new String(bVendor, "UTF-8");
545        final String spec = new String(bSpec, "UTF-8");
546        m.getMainAttributes()
547                .put(Attributes.Name.IMPLEMENTATION_VENDOR, vendor);
548        m.getAttributes(ATT_ENTRY_NAME).put(
549                Attributes.Name.IMPLEMENTATION_VENDOR, vendor);
550        m.getEntries().get(ATT_ENTRY_NAME).put(
551                Attributes.Name.SPECIFICATION_TITLE, spec);
552
553        ByteArrayOutputStream baos = new ByteArrayOutputStream();
554        m.write(baos);
555        m = new Manifest(new ByteArrayInputStream(baos.toByteArray()));
556
557        assertEquals(vendor, m.getMainAttributes().get(
558                Attributes.Name.IMPLEMENTATION_VENDOR));
559        assertEquals(vendor, m.getEntries().get(ATT_ENTRY_NAME).get(
560                Attributes.Name.IMPLEMENTATION_VENDOR));
561        assertEquals(spec, m.getAttributes(ATT_ENTRY_NAME).get(
562                Attributes.Name.SPECIFICATION_TITLE));
563    }
564
565    /**
566     * @tests {@link java.util.jar.Manifest#read(java.io.InputStream)
567     */
568    @TestTargetNew(
569            level = TestLevel.PARTIAL,
570            notes = "",
571            method = "read",
572            args = {InputStream.class}
573    )
574    public void testRead() {
575        // Regression for HARMONY-89
576        InputStream is = new InputStreamImpl();
577        try {
578            new Manifest().read(is);
579            fail("IOException expected");
580        } catch (IOException e) {
581            // desired
582        }
583    }
584
585    // helper class
586    private class InputStreamImpl extends InputStream {
587        public InputStreamImpl() {
588            super();
589        }
590
591        @Override
592        public int read() {
593            return 0;
594        }
595    }
596}
597