本文整理汇总了Java中org.lemurproject.galago.utility.ZipUtil类的典型用法代码示例。如果您正苦于以下问题:Java ZipUtil类的具体用法?Java ZipUtil怎么用?Java ZipUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZipUtil类属于org.lemurproject.galago.utility包,在下文中一共展示了ZipUtil类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testZipFile
import org.lemurproject.galago.utility.ZipUtil; //导入依赖的package包/类
@Test
public void testZipFile() throws IOException {
File tmp = null;
try {
tmp = File.createTempFile("zipUtilTest", ".zip");
String fooContents = "foo is the best";
String fooPath = "data/foo.txt";
String barContents = "bar is the best";
String barPath = "data/subdir/ignore/bar.txt";
// write zip file:
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(tmp.getAbsolutePath()));
ZipUtil.write(zos, fooPath, ByteUtil.fromString(fooContents));
ZipUtil.write(zos, barPath, ByteUtil.fromString(barContents));
zos.close();
ZipFile zipFile = ZipUtil.open(tmp);
// read zip file:
List<String> entries = ZipUtil.listZipFile(zipFile);
assertEquals(2, entries.size());
assertEquals(fooPath, entries.get(0));
assertEquals(barPath, entries.get(1));
assertEquals(fooContents, StreamUtil.copyStreamToString(ZipUtil.streamZipEntry(zipFile, fooPath)));
assertEquals(barContents, StreamUtil.copyStreamToString(ZipUtil.streamZipEntry(zipFile, barPath)));
assertTrue(ZipUtil.hasZipExtension(tmp.getAbsolutePath()));
} finally {
if (tmp != null) {
tmp.delete();
}
}
}
示例2: run
import org.lemurproject.galago.utility.ZipUtil; //导入依赖的package包/类
@Override
public void run(Parameters argp) throws Exception {
List<File> inputFiles = Util.checkAndExpandPaths(argp.getAsList("input", String.class));
// write zip file:
final ZipOutputStream zos = new ZipOutputStream(StreamCreator.openOutputStream(argp.getString("output")));
try {
for (File fp : inputFiles) {
XML.forFieldsInSections(fp, "page", Arrays.asList("title", "text"), new XML.FieldsFunctor() {
@Override
public void process(Map<String, String> data) {
String pageTitle = data.get("title").replace(' ', '_');
if (pageTitle.isEmpty() || pageTitle.startsWith("Template") || pageTitle.startsWith("User"))
return;
String body = WikipediaToHTML.process(pageTitle, data.get("text"));
String html = String.format("<html><head><title>%s</title></head><body>%s</body></html>", pageTitle, body);
try {
ZipUtil.write(zos, pageTitle + ".html", ByteUtil.fromString(html));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
}
} finally {
zos.close();
}
}
示例3: testZipFile
import org.lemurproject.galago.utility.ZipUtil; //导入依赖的package包/类
@Test
public void testZipFile() throws IOException {
File tmp = null;
try {
tmp = File.createTempFile("streamParserZipTest", ".zip");
String fooContents = "foo is the best";
String fooPath = "data/foo.txt";
String barContents = "bar is the best";
String barPath = "data/subdir/ignore/bar.txt";
String trecWebContents = "<DOC>\n"
+ "<DOCNO>CACM-0001</DOCNO>\n"
+ "<DOCHDR>\n"
+ "http://www.yahoo.com:80 some extra text here\n"
+ "even more text in this part\n"
+ "</DOCHDR>\n"
+ "This is some text in a document.\n"
+ "</DOC>\n";
String trecWebPath = "data/blah/easy.trecweb";
String guessTrecWebPath = "data/blah/guess_trecweb";
// write zip file:
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(tmp.getAbsolutePath()));
ZipUtil.write(zos, fooPath, ByteUtil.fromString(fooContents));
ZipUtil.write(zos, barPath, ByteUtil.fromString(barContents));
ZipUtil.write(zos, trecWebPath, ByteUtil.fromString(trecWebContents));
ZipUtil.write(zos, guessTrecWebPath, ByteUtil.fromString(trecWebContents));
zos.close();
ZipFile zipFile = ZipUtil.open(tmp);
// read zip file:
List<String> entries = ZipUtil.listZipFile(zipFile);
assertEquals(4, entries.size());
zipFile.close();
List<DocumentSplit> splits = DocumentSource.processZipFile(tmp, Parameters.create());
assertEquals(4, splits.size());
assertEquals("txt", splits.get(0).fileType);
assertEquals("txt", splits.get(1).fileType);
assertEquals("trecweb", splits.get(2).fileType);
assertEquals("trecweb", splits.get(3).fileType);
DocumentStreamParser parser = DocumentStreamParser.create(splits.get(2), Parameters.create());
Document d = parser.nextDocument();
assertNotNull(d);
assertNull(parser.nextDocument());
parser.close();
assertEquals("http://www.yahoo.com", d.metadata.get("url"));
assertEquals(tmp.getAbsolutePath() + "!" + fooPath, DocumentStreamParser.getFullPath(splits.get(0)));
} finally {
if (tmp != null) {
tmp.delete();
}
}
}
示例4: testForcedZipFile
import org.lemurproject.galago.utility.ZipUtil; //导入依赖的package包/类
@Test
public void testForcedZipFile() throws IOException {
File tmp = null;
try {
tmp = File.createTempFile("zipUtilTest", ".zip");
String fooContents = "foo is the best";
String fooPath = "data/foo.txt";
String trecWebContents = "<DOC>\n"
+ "<DOCNO>CACM-0001</DOCNO>\n"
+ "<DOCHDR>\n"
+ "http://www.yahoo.com:80 some extra text here\n"
+ "even more text in this part\n"
+ "</DOCHDR>\n"
+ "This is some text in a document.\n"
+ "</DOC>\n";
String trecWebPath = "data/blah/easy.trecweb";
// write zip file:
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(tmp.getAbsolutePath()));
ZipUtil.write(zos, fooPath, ByteUtil.fromString(fooContents));
ZipUtil.write(zos, trecWebPath, ByteUtil.fromString(trecWebContents));
zos.close();
ZipFile zipFile = ZipUtil.open(tmp);
// read zip file:
List<String> entries = ZipUtil.listZipFile(zipFile);
assertEquals(2, entries.size());
zipFile.close();
List<DocumentSplit> splits = DocumentSource.processZipFile(tmp, Parameters.parseArray("filetype", "foo"));
assertEquals(2, splits.size());
assertEquals("foo", splits.get(0).fileType);
assertEquals("foo", splits.get(1).fileType);
} finally {
if(tmp != null) assertTrue(tmp.delete());
}
}
示例5: testZipFile
import org.lemurproject.galago.utility.ZipUtil; //导入依赖的package包/类
@Test
public void testZipFile() throws IOException {
File tmp = null;
try {
tmp = File.createTempFile("zipUtilTest", ".zip");
String fooContents = "foo is the best";
String fooPath = "data/foo.txt";
String barContents = "bar is the best";
String barPath = "data/subdir/ignore/bar.txt";
String trecWebContents = "<DOC>\n"
+ "<DOCNO>CACM-0001</DOCNO>\n"
+ "<DOCHDR>\n"
+ "http://www.yahoo.com:80 some extra text here\n"
+ "even more text in this part\n"
+ "</DOCHDR>\n"
+ "This is some text in a document.\n"
+ "</DOC>\n";
String trecWebPath = "data/blah/easy.trecweb";
String guessTrecWebPath = "data/blah/guess_trecweb";
// write zip file:
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(tmp.getAbsolutePath()));
ZipUtil.write(zos, fooPath, ByteUtil.fromString(fooContents));
ZipUtil.write(zos, barPath, ByteUtil.fromString(barContents));
ZipUtil.write(zos, trecWebPath, ByteUtil.fromString(trecWebContents));
ZipUtil.write(zos, guessTrecWebPath, ByteUtil.fromString(trecWebContents));
zos.close();
ZipFile zipFile = ZipUtil.open(tmp);
// read zip file:
List<String> entries = ZipUtil.listZipFile(zipFile);
assertEquals(4, entries.size());
zipFile.close();
List<DocumentSplit> splits = DocumentSource.processZipFile(tmp, Parameters.create());
assertEquals(4, splits.size());
assertEquals("txt", splits.get(0).fileType);
assertEquals("txt", splits.get(1).fileType);
assertEquals("trecweb", splits.get(2).fileType);
assertEquals("trecweb", splits.get(3).fileType);
} finally {
if(tmp != null) assertTrue(tmp.delete());
}
}