当前位置: 首页>>代码示例>>Java>>正文


Java ZipUtil.open方法代码示例

本文整理汇总了Java中org.lemurproject.galago.utility.ZipUtil.open方法的典型用法代码示例。如果您正苦于以下问题:Java ZipUtil.open方法的具体用法?Java ZipUtil.open怎么用?Java ZipUtil.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.lemurproject.galago.utility.ZipUtil的用法示例。


在下文中一共展示了ZipUtil.open方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
        }
    }

}
 
开发者ID:teanalab,项目名称:demidovii,代码行数:40,代码来源:ZipUtilTest.java

示例2: 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();
        }
    }
}
 
开发者ID:teanalab,项目名称:demidovii,代码行数:61,代码来源:DocumentStreamParserTest.java

示例3: 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());
  }
}
 
开发者ID:teanalab,项目名称:demidovii,代码行数:42,代码来源:DocumentSourceTest.java

示例4: 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());
  }
}
 
开发者ID:teanalab,项目名称:demidovii,代码行数:50,代码来源:DocumentSourceTest.java


注:本文中的org.lemurproject.galago.utility.ZipUtil.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。