• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java CompressionUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.gbif.utils.file.CompressionUtil的典型用法代码示例。如果您正苦于以下问题:Java CompressionUtil类的具体用法?Java CompressionUtil怎么用?Java CompressionUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CompressionUtil类属于org.gbif.utils.file包,在下文中一共展示了CompressionUtil类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testIssue2158

import org.gbif.utils.file.CompressionUtil; //导入依赖的package包/类
/**
 * Test IPT bug 2158
 *
 * @see <a href="http://code.google.com/p/gbif-providertoolkit/source/detail?r=2158">IPT revision 2158</a>
 */
@Test
public void testIssue2158() throws UnsupportedArchiveException, IOException {
  // test zip with 1 extension file
  File zip = FileUtils.getClasspathFile("archive-tax.zip");
  File tmpDir = Files.createTempDirectory("dwca-io-test").toFile();
  CompressionUtil.decompressFile(tmpDir, zip);
  // read archive from this tmp dir
  Archive arch = ArchiveFactory.openArchive(tmpDir);
  assertNotNull(arch.getCore().getId());
  assertEquals(1, arch.getExtensions().size());

  boolean found = false;
  for (Record rec : arch.getCore()) {
    if ("113775".equals(rec.id())) {
      found = true;
      assertEquals(
        "Ehrenberg, 1832, in Hemprich and Ehrenberg, Symbolæ Phisicæ Mammalia, 2: ftn. 1 (last page of fascicle headed \"Herpestes leucurus H. E.\").",
        rec.value(DwcTerm.originalNameUsageID));
    }
  }
  assertTrue(found);
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:28,代码来源:ArchiveFactoryTest.java


示例2: testExtensionNPE

import org.gbif.utils.file.CompressionUtil; //导入依赖的package包/类
/**
 * The pensoft archive http://pensoft.net/dwc/bdj/checklist_980.zip
 * contains empty extension files which caused NPE in the dwca reader.
 */
@Test
public void testExtensionNPE() throws UnsupportedArchiveException, IOException {
  File zip = FileUtils.getClasspathFile("checklist_980.zip");
  File tmpDir = Files.createTempDirectory("dwca-io-test").toFile();
  CompressionUtil.decompressFile(tmpDir, zip);
  // read archive from this tmp dir
  Archive arch = ArchiveFactory.openArchive(tmpDir);
  assertNotNull(arch.getCore().getId());
  assertEquals(3, arch.getExtensions().size());

  boolean found = false;
  for (StarRecord rec : arch) {
    if ("980-sp10".equals(rec.core().id())) {
      found = true;
    }
  }
  assertTrue(found);
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:23,代码来源:ArchiveFactoryTest.java


示例3: DwcArchive

import org.gbif.utils.file.CompressionUtil; //导入依赖的package包/类
/**
 * Constructor from a URI
 *
 * @param source
 * @throws IOException
 */
public DwcArchive(URL source) throws IOException {

    File dwca = File.createTempFile("dwcaFile-", null);
    dwca.deleteOnExit();

    System.out.println("Downloading DarwinCore archive " + source.toString());
    try {
        // download
        DefaultHttpClient client = new DefaultHttpClient();
        HttpUtil http = new HttpUtil(client);
        http.download(source, dwca);
    } catch (Exception e) {
        System.out.println("Cannot download DarwinCore archive. Abort.");
        System.exit(0);
    }

    location = CompressionUtil.decompressFile(dwca);
    System.out.println("Uncompressed into directory: " + location.getAbsolutePath());
    archive = ArchiveFactory.openArchive(location);
}
 
开发者ID:GBIF-Sweden,项目名称:bourgogne,代码行数:27,代码来源:DwcArchive.java


示例4: openArchive

import org.gbif.utils.file.CompressionUtil; //导入依赖的package包/类
/**
 * Opens an archive from a local file and decompresses or copies it into the given archive directory.
 * Make sure the archive directory does not contain files already!
 *
 * @param archiveFile the location of a compressed archive or single data file
 * @param archiveDir  empty, writable directory used to keep decompress archive in
 */
public static Archive openArchive(File archiveFile, File archiveDir) throws IOException, UnsupportedArchiveException {
	// try to decompress archive
	try {
		List<File> files = CompressionUtil.decompressFile(archiveDir, archiveFile);
		// continue to read archive from the tmp dir
		return openArchive(archiveDir);

	} catch (CompressionUtil.UnsupportedCompressionType e) {
		// If its a text file only we will get this exception - but also for corrupt compressions
		// try to open as text file only
		return openArchive(archiveFile);
	}
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:21,代码来源:ArchiveFactory.java


示例5: fromCompressed

import org.gbif.utils.file.CompressionUtil; //导入依赖的package包/类
static Archive fromCompressed(Path dwcaLocation, Path destination) throws IOException, UnsupportedArchiveException {
  if (!Files.exists(dwcaLocation)) {
    throw new FileNotFoundException("dwcaLocation does not exist: " + dwcaLocation.toAbsolutePath());
  }

  if (Files.exists(destination)) {
    // clean up any existing folder
    LOG.debug("Deleting existing archive folder [{}]", destination.toAbsolutePath());
    org.gbif.utils.file.FileUtils.deleteDirectoryRecursively(destination.toFile());
  }
  FileUtils.forceMkdir(destination.toFile());
  // try to decompress archive
  try {
    CompressionUtil.decompressFile(destination.toFile(), dwcaLocation.toFile(), true);
    // we keep subfolder, but often the entire archive is within one subfolder. Remove that root folder if present
    File[] rootFiles = destination.toFile().listFiles((FileFilter) HiddenFileFilter.VISIBLE);
    if (rootFiles.length == 1) {
      File root = rootFiles[0];
      if (root.isDirectory()) {
        // single root dir, flatten structure
        LOG.debug("Removing single root folder {} found in decompressed archive", root.getAbsoluteFile());
        for (File f : FileUtils.listFiles(root, TrueFileFilter.TRUE, null)) {
          File f2 = new File(destination.toFile(), f.getName());
          f.renameTo(f2);
        }
      }
    }
    // continue to read archive from the tmp dir
    return fromLocation(destination);
  } catch (CompressionUtil.UnsupportedCompressionType e) {
    throw new UnsupportedArchiveException(e);
  }
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:34,代码来源:InternalDwcFileFactory.java


示例6: testGnubTabZip

import org.gbif.utils.file.CompressionUtil; //导入依赖的package包/类
/**
 * Test GNUB style dwca with a single tab delimited file that has a .tab suffix.
 */
@Test
public void testGnubTabZip() throws UnsupportedArchiveException, IOException {
  // test GNUB zip with 1 data file
  File tmpDir = Files.createTempDirectory("dwca-io-test").toFile();
  tmpDir.deleteOnExit();
  File zip = FileUtils.getClasspathFile("gnub.tab.zip");
  CompressionUtil.decompressFile(tmpDir, zip);

  // read archive from this tmp dir
  Archive arch = ArchiveFactory.openArchive(tmpDir);

  Record rec = arch.getCore().iterator().next();
  assertEquals("246daa62-6fce-448f-88b4-94b0ccc89cf1", rec.id());
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:18,代码来源:ArchiveFactoryTest.java


示例7: download

import org.gbif.utils.file.CompressionUtil; //导入依赖的package包/类
private void download(String url) throws IOException {
  HttpUtil hutil = new HttpUtil(HttpUtil.newMultithreadedClient(2000, 5, 2));

  File dwca = File.createTempFile("clb", ".dwca");
  hutil.download(url, dwca);
  System.out.println("Downloaded raw archive to " + dwca.getAbsolutePath());
  CompressionUtil.decompressFile(nCfg.archiveDir(datasetKey), dwca);
  System.out.println("Decompressed archive to " + nCfg.archiveDir(datasetKey));
}
 
开发者ID:gbif,项目名称:checklistbank,代码行数:10,代码来源:IndexerApp.java


示例8: manyNormalizersInParallel

import org.gbif.utils.file.CompressionUtil; //导入依赖的package包/类
@Test
public void manyNormalizersInParallel() throws Exception {
  final int tasks = 500;

  ExecutorCompletionService<Object> ecs = new ExecutorCompletionService(Executors.newFixedThreadPool(threads));
  List<Future<Object>> futures = Lists.newArrayList();
  for (int i = 0; i < tasks; i++) {
    UUID dk = UUID.randomUUID();

    // copy dwca
    File dwca = cfgN.archiveDir(dk);
    CompressionUtil.decompressFile(dwca, this.zip);

    Normalizer normalizer = Normalizer.create(cfgN, registry, dk);
    System.out.println("Submit normalizer " + i);
    futures.add(ecs.submit(Executors.callable(normalizer)));
  }

  int idx = 1;
  for (Future<Object> f : futures) {
    f.get();
    System.out.println("Finished normalizer " + idx++);
    monitor.run();
  }
  System.out.println("Finished all jobs");
  monitor.run();
  for (Thread t : Thread.getAllStackTraces().keySet()) {
    System.out.println(t.getState() + " " + t.getName());
  }
}
 
开发者ID:gbif,项目名称:checklistbank,代码行数:31,代码来源:MultiThreadingCliTest.java


示例9: manyNormalizersInParallel

import org.gbif.utils.file.CompressionUtil; //导入依赖的package包/类
@Test
public void manyNormalizersInParallel() throws Exception {
    final int tasks = 500;

    NormalizerConfiguration cfgN = new NormalizerConfiguration();
    cfgN.neo.neoRepository = Files.createTempDirectory("neotest").toFile();
    cfgN.archiveRepository = Files.createTempDirectory("neotestdwca").toFile();

    MetricRegistry registry = new MetricRegistry();

    File zip = new File(getClass().getResource("/plazi.zip").getFile());
    zip = new File("/Users/markus/code/checklistbank/checklistbank-cli/src/test/resources/plazi.zip");

    Timer timer = new Timer();
    ResourcesMonitor monitor = new ResourcesMonitor();
    timer.schedule(monitor, 500);


    ExecutorCompletionService<InsertMetadata> ecs = new ExecutorCompletionService(Executors.newFixedThreadPool(threads));
    List<Future<InsertMetadata>> futures = Lists.newArrayList();
    for (int i = 0; i < tasks; i++) {
        UUID dk = UUID.randomUUID();

        // copy dwca
        File dwca = cfgN.archiveDir(dk);
        CompressionUtil.decompressFile(dwca, zip);

        System.out.println("Submit inserter job " + i);
        futures.add(ecs.submit(new InserterJob(dk, cfgN, registry)));
    }

    int idx = 1;
    for (Future<InsertMetadata> f : futures) {
        f.get();
        System.out.println("Finished inserter " + idx++);
        monitor.run();
    }
    System.out.println("Finished all jobs");
    System.out.println("Open files: " + monitor.getOpenFileDescriptorCount());
    System.out.println("Running threads: " + Thread.getAllStackTraces().size());
    for (Thread t : Thread.getAllStackTraces().keySet()) {
        System.out.println(t.getState() + " " + t.getName());
    }

    System.out.println("Cleaning up artifacts...");
    FileUtils.deleteQuietly(cfgN.neo.neoRepository);
    FileUtils.deleteQuietly(cfgN.archiveRepository);
}
 
开发者ID:gbif,项目名称:checklistbank,代码行数:49,代码来源:MultiThreadingNeoInserterTest.java


示例10: buildArchive

import org.gbif.utils.file.CompressionUtil; //导入依赖的package包/类
/**
 * Main method to assemble the dwc archive and do all the work until we have a final zip file.
 *
 * @param zipFile the final zip file holding the entire archive
 */
public void buildArchive(File zipFile) throws DownloadException {
  LOG.info("Start building the archive {} ", zipFile.getPath());

  try {
    if (zipFile.exists()) {
      zipFile.delete();
    }
    if (!configuration.isSmallDownload()) {
      // oozie might try several times to run this job, so make sure our filesystem is clean
      cleanupFS();

      // create the temp archive dir
      archiveDir.mkdirs();
    }

    // metadata, citation and rights
    License downloadLicense = addConstituentMetadata();

    // persist the License assigned to the download
    persistDownloadLicense(configuration.getDownloadKey(), downloadLicense);

    // metadata about the entire archive data
    generateMetadata();

    // meta.xml
    DwcArchiveUtils.createArchiveDescriptor(archiveDir);

    // zip up
    LOG.info("Zipping archive {}", archiveDir.toString());
    CompressionUtil.zipDir(archiveDir, zipFile, true);

    // add the large download data files to the zip stream
    if (!configuration.isSmallDownload()) {
      appendPreCompressedFiles(zipFile);
    }
    targetFs.moveFromLocalFile(new Path(zipFile.getPath()),
                               new Path(workflowConfiguration.getHdfsOutputPath(), zipFile.getName()));

  } catch (IOException e) {
    throw new DownloadException(e);

  } finally {
    // always cleanUp temp dir
    cleanupFS();
  }

}
 
开发者ID:gbif,项目名称:occurrence,代码行数:53,代码来源:DwcaArchiveBuilder.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ClientConnectionManager类代码示例发布时间:2022-05-22
下一篇:
Java RangeDifferencer类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap