93 try {
94 // setup the test scenarios
95 try {
96 tlist.add(new PackTestInput((JarFile)null, null));
97 tlist.add(new PackTestInput(new JarFile(testJar), null));
98 tlist.add(new PackTestInput((JarFile)null, new ByteArrayOutputStream()));
99 } catch (Exception e) {
100 throw new Error("Initialization error", e);
101 }
102
103 // test the scenarios
104 for (PackTestInput ti : tlist) {
105 System.out.println(ti);
106 try {
107 Pack200.Packer p = Pack200.newPacker();
108 p.pack(ti.getJarFile(), ti.getOutputStream());
109 } catch (Exception e) {
110 ti.checkException(e);
111 }
112 }
113 } finally { // keep jprt happy
114 for (TestInput ti : tlist) {
115 if (ti != null) {
116 ti.close();
117 }
118 }
119 }
120 }
121
122 // test the Pack200.pack(JarInputStream, OutputStream);
123 static void pack200Test3() {
124 List<PackTestJarInputStream> tlist = new ArrayList<PackTestJarInputStream>();
125 try {
126 // setup the test scenarios
127 try {
128 tlist.add(new PackTestJarInputStream((JarInputStream)null, null));
129 tlist.add(new PackTestJarInputStream((JarInputStream)null,
130 new ByteArrayOutputStream()));
131 tlist.add(new PackTestJarInputStream(
132 new JarInputStream(new FileInputStream(testJar)), null));
133
134 } catch (Exception e) {
135 throw new Error("Initialization error", e);
136 }
137 for (PackTestJarInputStream ti : tlist) {
138 System.out.println(ti);
139 try {
140 Pack200.Packer p = Pack200.newPacker();
141 p.pack(ti.getJarInputStream(), ti.getOutputStream());
142 } catch (Exception e) {
143 ti.checkException(e);
144 }
145 }
146 } finally { // keep jprt happy
147 for (PackTestJarInputStream ti : tlist) {
148 if (ti != null) {
149 ti.close();
150 }
151 }
152 }
153 }
154
155 // test the Pack200.unpack(InputStream, OutputStream);
156 static void unpack200Test1() {
157 List<UnpackTestInput> tlist = new ArrayList<UnpackTestInput>();
158 try {
159 // setup the test scenarios
160 try {
161 tlist.add(new UnpackTestInput((InputStream)null, null));
162 tlist.add(new UnpackTestInput(new FileInputStream(testPackFile),
163 null));
164 tlist.add(new UnpackTestInput((InputStream) null,
165 new JarOutputStream(new ByteArrayOutputStream())));
166 } catch (Exception e) {
167 throw new Error("Initialization error", e);
168 }
169
170 // test the scenarios
171 for (UnpackTestInput ti : tlist) {
172 System.out.println(ti);
173 try {
174 Pack200.Unpacker unpacker = Pack200.newUnpacker();
175 unpacker.unpack(ti.getInputStream(), ti.getJarOutputStream());
176 } catch (Exception e) {
177 ti.checkException(e);
178 }
179 }
180 } finally { // keep jprt happy
181 for (TestInput ti : tlist) {
182 if (ti != null) {
183 ti.close();
184 }
185 }
186 }
187 }
188
189 // test the Pack200.unpack(File, OutputStream);
190 static void unpack200Test2() {
191 List<UnpackTestFileInput> tlist = new ArrayList<UnpackTestFileInput>();
192 try {
193 // setup the test scenarios
194 try {
195 tlist.add(new UnpackTestFileInput((File)null, null));
196 tlist.add(new UnpackTestFileInput(testPackFile, null));
197 tlist.add(new UnpackTestFileInput((File)null,
198 new JarOutputStream(new ByteArrayOutputStream())));
199 } catch (Exception e) {
200 throw new Error("Initialization error", e);
201 }
202
203 // test the scenarios
204 for (UnpackTestFileInput ti : tlist) {
205 System.out.println(ti);
206 try {
207 Pack200.Unpacker unpacker = Pack200.newUnpacker();
208 unpacker.unpack(ti.getInputFile(), ti.getJarOutputStream());
209 } catch (Exception e) {
210 ti.checkException(e);
211 }
212 }
213 } finally { // keep jprt happy
214 for (TestInput ti : tlist) {
215 if (ti != null) {
216 ti.close();
217 }
218 }
219 }
220 }
221
222 public static void main(String... args) throws IOException {
223 init();
224 pack200Test1();
225 pack200Test2();
226 pack200Test3();
227 unpack200Test1();
228 Utils.cleanup();
229 }
230
231 // containers for test inputs and management
232 static abstract class TestInput {
233
|
93 try {
94 // setup the test scenarios
95 try {
96 tlist.add(new PackTestInput((JarFile)null, null));
97 tlist.add(new PackTestInput(new JarFile(testJar), null));
98 tlist.add(new PackTestInput((JarFile)null, new ByteArrayOutputStream()));
99 } catch (Exception e) {
100 throw new Error("Initialization error", e);
101 }
102
103 // test the scenarios
104 for (PackTestInput ti : tlist) {
105 System.out.println(ti);
106 try {
107 Pack200.Packer p = Pack200.newPacker();
108 p.pack(ti.getJarFile(), ti.getOutputStream());
109 } catch (Exception e) {
110 ti.checkException(e);
111 }
112 }
113 } finally { // clean up
114 for (TestInput ti : tlist) {
115 if (ti != null) {
116 ti.close();
117 }
118 }
119 }
120 }
121
122 // test the Pack200.pack(JarInputStream, OutputStream);
123 static void pack200Test3() {
124 List<PackTestJarInputStream> tlist = new ArrayList<PackTestJarInputStream>();
125 try {
126 // setup the test scenarios
127 try {
128 tlist.add(new PackTestJarInputStream((JarInputStream)null, null));
129 tlist.add(new PackTestJarInputStream((JarInputStream)null,
130 new ByteArrayOutputStream()));
131 tlist.add(new PackTestJarInputStream(
132 new JarInputStream(new FileInputStream(testJar)), null));
133
134 } catch (Exception e) {
135 throw new Error("Initialization error", e);
136 }
137 for (PackTestJarInputStream ti : tlist) {
138 System.out.println(ti);
139 try {
140 Pack200.Packer p = Pack200.newPacker();
141 p.pack(ti.getJarInputStream(), ti.getOutputStream());
142 } catch (Exception e) {
143 ti.checkException(e);
144 }
145 }
146 } finally { // clean up
147 for (PackTestJarInputStream ti : tlist) {
148 if (ti != null) {
149 ti.close();
150 }
151 }
152 }
153 }
154
155 // test the Pack200.unpack(InputStream, OutputStream);
156 static void unpack200Test1() {
157 List<UnpackTestInput> tlist = new ArrayList<UnpackTestInput>();
158 try {
159 // setup the test scenarios
160 try {
161 tlist.add(new UnpackTestInput((InputStream)null, null));
162 tlist.add(new UnpackTestInput(new FileInputStream(testPackFile),
163 null));
164 tlist.add(new UnpackTestInput((InputStream) null,
165 new JarOutputStream(new ByteArrayOutputStream())));
166 } catch (Exception e) {
167 throw new Error("Initialization error", e);
168 }
169
170 // test the scenarios
171 for (UnpackTestInput ti : tlist) {
172 System.out.println(ti);
173 try {
174 Pack200.Unpacker unpacker = Pack200.newUnpacker();
175 unpacker.unpack(ti.getInputStream(), ti.getJarOutputStream());
176 } catch (Exception e) {
177 ti.checkException(e);
178 }
179 }
180 } finally { // clean up
181 for (TestInput ti : tlist) {
182 if (ti != null) {
183 ti.close();
184 }
185 }
186 }
187 }
188
189 // test the Pack200.unpack(File, OutputStream);
190 static void unpack200Test2() {
191 List<UnpackTestFileInput> tlist = new ArrayList<UnpackTestFileInput>();
192 try {
193 // setup the test scenarios
194 try {
195 tlist.add(new UnpackTestFileInput((File)null, null));
196 tlist.add(new UnpackTestFileInput(testPackFile, null));
197 tlist.add(new UnpackTestFileInput((File)null,
198 new JarOutputStream(new ByteArrayOutputStream())));
199 } catch (Exception e) {
200 throw new Error("Initialization error", e);
201 }
202
203 // test the scenarios
204 for (UnpackTestFileInput ti : tlist) {
205 System.out.println(ti);
206 try {
207 Pack200.Unpacker unpacker = Pack200.newUnpacker();
208 unpacker.unpack(ti.getInputFile(), ti.getJarOutputStream());
209 } catch (Exception e) {
210 ti.checkException(e);
211 }
212 }
213 } finally { // clean up
214 for (TestInput ti : tlist) {
215 if (ti != null) {
216 ti.close();
217 }
218 }
219 }
220 }
221
222 public static void main(String... args) throws IOException {
223 init();
224 pack200Test1();
225 pack200Test2();
226 pack200Test3();
227 unpack200Test1();
228 Utils.cleanup();
229 }
230
231 // containers for test inputs and management
232 static abstract class TestInput {
233
|