1 26 27 package com.opensugar.cube.java2; 28 29 import java.util.Hashtable ; 30 import java.util.zip.ZipFile ; 31 import java.io.IOException ; 32 import java.io.BufferedReader ; 33 import java.io.InputStreamReader ; 34 35 public class ManifestHelper { 41 42 private static final String MANIFEST_FILE = "META-INF/MANIFEST.MF"; 43 44 private Hashtable mainAttributes = new Hashtable (); 46 47 public ManifestHelper( ZipFile archive ) throws IOException { 48 60 parseManifest( archive ); 61 } 62 63 private void parseManifest( ZipFile archive ) throws IOException { 70 BufferedReader br = new BufferedReader ( new InputStreamReader ( archive.getInputStream( archive.getEntry( MANIFEST_FILE ) ), "ISO-8859-1" ) ); 72 String attributeName = null; 73 String attributeValue = null; 74 boolean done = false; 75 int lineNumber = 0; 76 77 while ( !done ) { 81 String line = br.readLine(); 82 lineNumber++; 83 if ( line == null || line.trim().length() == 0 ) { 84 87 if ( attributeName != null ) { 89 mainAttributes.put( attributeName, attributeValue ); 90 } 91 92 done = true; 94 } 95 else if ( !line.startsWith( " " ) ) { 96 98 if ( attributeName != null ) { 100 mainAttributes.put( attributeName, attributeValue ); 101 } 102 103 int n = line.indexOf( ": " ); 105 if ( n == -1 || n + 2 >= line.length() ) { 106 throw new IOException ( "Invalid line in bundle manifest (line " + lineNumber + "): " + line ); 107 } 108 else { 109 attributeName = line.substring( 0, n ); 110 attributeValue = line.substring( n + 2, line.length() ); 111 } 112 } 113 else { 114 if ( attributeValue == null ) { 116 throw new IOException ( "Misplaced continuation line in bundle manifest (line " + lineNumber + "): " + line ); 117 } 118 else { 119 attributeValue = attributeValue + line.substring( 1 ); 120 } 121 } 122 } 123 } 124 125 public Hashtable getMainAttributes() { 126 return mainAttributes; 127 } 128 129 } 130 | Popular Tags |