This project has retired. For details please refer to its
Attic page.
Any23PluginManagerTest xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.any23.plugin;
19
20 import static org.junit.Assert.assertTrue;
21
22 import java.io.BufferedInputStream;
23 import java.io.BufferedOutputStream;
24 import java.io.File;
25 import java.io.FileInputStream;
26 import java.io.FileOutputStream;
27 import java.io.IOException;
28 import java.util.Iterator;
29 import java.util.zip.ZipEntry;
30 import java.util.zip.ZipInputStream;
31
32 import org.apache.any23.extractor.ExtractorFactory;
33 import org.junit.After;
34 import org.junit.Before;
35 import org.junit.Test;
36
37
38
39
40
41
42 public class Any23PluginManagerTest {
43
44 private Any23PluginManager manager;
45
46 @Before
47 public void before() {
48 manager = Any23PluginManager.getInstance();
49 }
50
51 @After
52 public void after() {
53 manager = null;
54 }
55
56 @Test
57 public void testGetPlugins() throws IOException {
58 Iterator<ExtractorFactory> extractorPlugins = manager.getExtractors();
59 assertTrue(extractorPlugins.hasNext());
60 }
61
62
63 private void decompressJar(File jarFile, File destination) throws IOException {
64 final int BUFFER = 1024 * 1024;
65 BufferedOutputStream dest = null;
66 FileOutputStream fos = null;
67 ZipInputStream zis = null;
68 final byte data[] = new byte[BUFFER];
69 try {
70 FileInputStream fis = new FileInputStream(jarFile);
71 zis = new ZipInputStream(new BufferedInputStream(fis));
72 ZipEntry entry;
73 while ((entry = zis.getNextEntry()) != null) {
74 int count;
75 final File destinationFile = new File(destination, entry.getName());
76 if (entry.getName().endsWith("/")) {
77 destinationFile.mkdirs();
78 } else {
79 fos = new FileOutputStream(destinationFile);
80 dest = new BufferedOutputStream(fos, BUFFER);
81 while ((count = zis.read(data, 0, BUFFER)) != -1) {
82 dest.write(data, 0, count);
83 dest.flush();
84 }
85 dest.close();
86 fos.close();
87 }
88 }
89 } finally {
90 if (zis != null)
91 zis.close();
92 if (dest != null)
93 dest.close();
94 if (fos != null)
95 fos.close();
96 }
97 }
98
99 }