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

Java FileUtils类代码示例

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

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



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

示例1: testDwcRecordIterator

import org.gbif.utils.file.FileUtils; //导入依赖的package包/类
@Test
public void testDwcRecordIterator() throws IOException {
  Archive arch = DwcFiles.fromLocation(FileUtils.getClasspathFile("archive-dwc").toPath());
  int count=0;
  try(ClosableIterator<Record> it = DwcFiles.iterator(arch.getCore())) {
    while (it.hasNext()) {
      it.next();
      count++;
    }
  }
  catch (Exception e) {
    e.printStackTrace();
    fail();
  }
  assertEquals(3248, count);
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:17,代码来源:DwcFilesTest.java


示例2: testNormalizeAndSort

import org.gbif.utils.file.FileUtils; //导入依赖的package包/类
@Test
public void testNormalizeAndSort() throws IOException, InterruptedException {

  Archive arch = DwcFiles.fromLocation(FileUtils.getClasspathFile("archive-dwc").toPath());
  ArchiveFile core = arch.getCore();
  File sortedFile = ArchiveFile.getLocationFileSorted(core.getLocationFile());

  //ensure the sorted file for the core doesn't exist
  if(sortedFile.exists()) {
    sortedFile.delete();
  }
  assertTrue(DwcFiles.normalizeAndSort(arch.getCore()));
  assertTrue(sortedFile.exists());

  //call the method again. Should return false since we already have the sorted file available.
  assertFalse(DwcFiles.normalizeAndSort(arch.getCore()));
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:18,代码来源:DwcFilesTest.java


示例3: testHeaders3

import org.gbif.utils.file.FileUtils; //导入依赖的package包/类
@Test(expected = IllegalStateException.class)
public void testHeaders3() throws Exception {
  File dwcaDir = FileUtils.createTempDir();
  dwcaDir.deleteOnExit();
  DwcaWriter writer = new DwcaWriter(DwcTerm.Taxon, dwcaDir, true);

  writer.newRecord("dummy1");
  writer.addCoreColumn(DwcTerm.parentNameUsageID);
  writer.addCoreColumn(DwcTerm.acceptedNameUsageID);

  // define extension columns
  Map<Term, String> eData = Maps.newHashMap();
  eData.put(DwcTerm.locality, "locality1");
  eData.put(DwcTerm.occurrenceStatus, "present");
  writer.addExtensionRecord(GbifTerm.Distribution, eData);

  eData.put(DwcTerm.establishmentMeans, "alien");
  writer.addExtensionRecord(GbifTerm.Distribution, eData);
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:20,代码来源:DwcaWriterTest.java


示例4: testWriterUsingCoreIdTerm

import org.gbif.utils.file.FileUtils; //导入依赖的package包/类
@Test
public void testWriterUsingCoreIdTerm() throws Exception {
  File dwcaDir = FileUtils.createTempDir();
  dwcaDir.deleteOnExit();
  LOG.info("Test archive writer in {}", dwcaDir.getAbsolutePath());

  DwcaWriter writer = new DwcaWriter(DwcTerm.Taxon, DwcTerm.taxonID, dwcaDir, true);

  writer.newRecord("dummy1");
  writer.addCoreColumn(DwcTerm.parentNameUsageID);
  writer.addCoreColumn(DwcTerm.acceptedNameUsageID);
  writer.close();

  Archive arch = ArchiveFactory.openArchive(dwcaDir);
  Iterator<Record> recIt = arch.getCore().iterator();
  Record firstRecord = recIt.next();
  assertEquals("dummy1", firstRecord.id());
  assertEquals("dummy1", firstRecord.value(DwcTerm.taxonID));
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:20,代码来源:DwcaWriterTest.java


示例5: write

import org.gbif.utils.file.FileUtils; //导入依赖的package包/类
@Test
public void write() throws Exception {
    File dwca = FileUtils.createTempDir();
    Map<Term, Integer> mapping = ImmutableMap.of(
            DwcTerm.taxonID, 0,
            DwcTerm.scientificName, 1,
            DwcTerm.taxonRank, 2);
    try (DwcaStreamWriter dwcaWriter = new DwcaStreamWriter(dwca, DwcTerm.Taxon, DwcTerm.taxonID, true)){
        Dataset d = new Dataset();
        d.setTitle("Abies of the Alps");
        d.setDescription("Abies of the Alps excl Switzerland.");
        dwcaWriter.setMetadata(d);
        dwcaWriter.write(DwcTerm.Taxon, 0, mapping, ImmutableList.<String[]>builder()
                .add(new String[] { "tax-1", "Abies Mill.", "genus" })
                .add(new String[] { "tax-2", "Abies alba Mill.", "species" })
                .add(new String[] { "tax-3", "Piceae abies L.", "species" })
                .add(new String[] { "tax-4", "Piceae abies subsp. helvetica L.", "subspecies" })
                .build()
        );

    } finally {
        org.apache.commons.io.FileUtils.deleteQuietly(dwca);
    }
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:25,代码来源:DwcaStreamWriterTest.java


示例6: testConstituents

import org.gbif.utils.file.FileUtils; //导入依赖的package包/类
@Test
public void testConstituents() throws Exception {
  File dir = FileUtils.getClasspathFile("constituentsdwca");

  Archive arch = new Archive();
  arch.setLocation(dir);
  arch.setMetadataLocation("eml.xml");
  ArchiveField id = new ArchiveField(0, null, null, null);
  ArchiveField datasetId = new ArchiveField(1, DwcTerm.datasetID, null, null);
  ArchiveField sciname = new ArchiveField(2, DwcTerm.scientificName, null, null);

  Map<Term, ArchiveField> fields = new HashMap<Term, ArchiveField>();
  fields.put(DwcTerm.taxonomicStatus, sciname);
  fields.put(DwcTerm.datasetID, datasetId);

  Map<String, File> cons = arch.getConstituentMetadata();
  assertEquals(6, cons.size());
  for (Map.Entry<String, File> c : cons.entrySet()) {
    final String name = c.getKey();
    final File file = c.getValue();
    assertEquals(name, file.getName().split("\\.")[0]);
  }
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:24,代码来源:ArchiveTest.java


示例7: testBuildReaderFile

import org.gbif.utils.file.FileUtils; //导入依赖的package包/类
@Test
public void testBuildReaderFile() throws IOException {
  Archive arch = ArchiveFactory.openArchive(FileUtils.getClasspathFile("TDB_104.csv"));
  CSVReader reader = arch.getCore().getCSVReader();
  assertEquals(7, reader.next().length);
  reader.close();

  reader = ArchiveFactory.openArchive(FileUtils.getClasspathFile("iucn100.tab.txt")).getCore().getCSVReader();
  assertEquals(8, reader.next().length);
  reader.close();

  reader = ArchiveFactory.openArchive(FileUtils.getClasspathFile("iucn100.pipe.txt")).getCore().getCSVReader();
  assertEquals(8, reader.next().length);
  reader.close();

  reader = ArchiveFactory.openArchive(FileUtils.getClasspathFile("csv_quoted-unquoted_headers.csv")).getCore()
    .getCSVReader();
  assertEquals(4, reader.next().length);
  reader.close();
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:21,代码来源:ArchiveFactoryTest.java


示例8: testCsv

import org.gbif.utils.file.FileUtils; //导入依赖的package包/类
/**
 * Test dwca-reader bug 83
 *
 * @see <a href="http://code.google.com/p/darwincore/issues/detail?id=83">Issue 83</a>
 */
@Test
public void testCsv() throws UnsupportedArchiveException, IOException {
  File csv = FileUtils.getClasspathFile("csv_always_quoted.csv");
  // read archive from this tmp dir
  Archive arch = ArchiveFactory.openArchive(csv);

  boolean found = false;
  for (Record rec : arch.getCore()) {
    if ("ENNH0192".equals(rec.id())) {
      found = true;
      assertEquals("Martins Wood, Ightham", rec.value(DwcTerm.locality));
    }
  }
  assertTrue(found);
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:21,代码来源:ArchiveFactoryTest.java


示例9: testCsvExcelStyle

import org.gbif.utils.file.FileUtils; //导入依赖的package包/类
@Test
public void testCsvExcelStyle() throws UnsupportedArchiveException, IOException {
  File csv = FileUtils.getClasspathFile("csv_optional_quotes_excel2008CSV.csv");
  // read archive from this tmp dir
  Archive arch = ArchiveFactory.openArchive(csv);
  CSVReader reader = arch.getCore().getCSVReader();

  String[] atom = reader.next();
  assertEquals(3, atom.length);
  assertEquals("1", atom[0]);
  assertEquals("This has a, comma", atom[2]);
  atom = reader.next();
  assertEquals("I say this is only a \"quote\"", atom[2]);
  atom = reader.next();
  assertEquals("What though, \"if you have a quote\" and a comma", atom[2]);
  atom = reader.next();
  assertEquals("What, if we have a \"quote, which has a comma, or 2\"", atom[2]);

  reader.close();

}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:22,代码来源:ArchiveFactoryTest.java


示例10: testCsvOptionalQuotes

import org.gbif.utils.file.FileUtils; //导入依赖的package包/类
/**
 * Testing CSV with optional quotes
 */
@Test
public void testCsvOptionalQuotes() throws UnsupportedArchiveException, IOException {
  File csv = FileUtils.getClasspathFile("csv_optional_quotes_excel2008CSV.csv");
  Archive arch = ArchiveFactory.openArchive(csv);
  String[] ids = {"1", "2", "3", "4"};
  String[] scinames = {"Gadus morhua", "Abies alba", "Pomatoma saltatrix", "Yikes ofcourses"};
  String[] localities =
    {"This has a, comma", "I say this is only a \"quote\"", "What though, \"if you have a quote\" and a comma",
      "What, if we have a \"quote, which has a comma, or 2\""};
  int row = 0;
  for (Record rec : arch.getCore()) {
    assertEquals(ids[row], rec.id());
    assertEquals(scinames[row], rec.value(DwcTerm.scientificName));
    assertEquals(localities[row], rec.value(DwcTerm.locality));
    row++;
  }
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:21,代码来源:ArchiveFactoryTest.java


示例11: testIssue2158

import org.gbif.utils.file.FileUtils; //导入依赖的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


示例12: testExtensionNPE

import org.gbif.utils.file.FileUtils; //导入依赖的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


示例13: testIssue78

import org.gbif.utils.file.FileUtils; //导入依赖的package包/类
/**
 * Identifier not set properly when reading single csv file
 * the csv file attached is a utf16 little endian encoded file.
 * This encoding is known to cause problems and not supported.
 * If you look at the detected concept terms you will find that there is NO concept at all detected because of the
 * wrong character encoding used (the factory tries it with utf8).
 *
 * @see <a href="http://code.google.com/p/darwincore/issues/detail?id=78">Issue 78</a>
 */
@Test
public void testIssue78() throws IOException, UnsupportedArchiveException {
  // test folder with single text file in
  Archive arch = ArchiveFactory.openArchive(FileUtils.getClasspathFile("MOBOTDarwinCore.csv"));
  assertNotNull(arch.getCore());
  assertNotNull(arch.getCore().getId());
  assertEquals(DwcTerm.occurrenceID, arch.getCore().getId().getTerm());
  assertNotNull(arch.getCore().getRowType());
  assertEquals(DwcTerm.Occurrence, arch.getCore().getRowType());
  assertTrue(arch.getCore().hasTerm(DwcTerm.occurrenceID));
  assertTrue(arch.getCore().hasTerm(DwcTerm.scientificName));
  assertEquals("UTF-8", arch.getCore().getEncoding());

  int i = 0;
  for (Record rec : arch.getCore()) {
    i++;
    assertEquals(rec.id(), "MO:Tropicos:" + i);
  }
  assertEquals(3, i);
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:30,代码来源:ArchiveFactoryTest.java


示例14: testOpenSmallArchiveWithEmptyLines

import org.gbif.utils.file.FileUtils; //导入依赖的package包/类
@Test
public void testOpenSmallArchiveWithEmptyLines() throws IOException, UnsupportedArchiveException {
  // test folder with single text file in
  Archive arch = ArchiveFactory.openArchive(FileUtils.getClasspathFile("empty_line.tab"));
  assertNotNull(arch.getCore());
  assertNotNull(arch.getCore().getId());
  assertTrue(arch.getCore().hasTerm(DwcTerm.scientificName));
  assertEquals(0, arch.getExtensions().size());
  Iterator<StarRecord> dwci = arch.iterator();
  StarRecord star = dwci.next();
  star = dwci.next();
  star = dwci.next();
  star = dwci.next();
  star = dwci.next();
  assertEquals("Delphinus delphis var. delphis", star.core().value(DwcTerm.scientificName));
  int i = 0;
  for (StarRecord rec : arch) {
    i++;
    if (i > 20) {
      break;
    }
  }
  assertEquals(6, i);
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:25,代码来源:ArchiveFactoryTest.java


示例15: testQuotedHeaders

import org.gbif.utils.file.FileUtils; //导入依赖的package包/类
/**
 * Test bug 77.
 *
 * @see <a href="http://code.google.com/p/darwincore/issues/detail?id=77">Issue 77</a>
 */
@Test
public void testQuotedHeaders() throws IOException, UnsupportedArchiveException {
  // test folder with single text file in
  Archive arch = ArchiveFactory.openArchive(FileUtils.getClasspathFile("quoted_headers_MOBOTDarwinCore.csv"));
  assertNotNull(arch.getCore());
  assertNotNull(arch.getCore().getId());
  assertTrue(arch.getCore().hasTerm(DwcTerm.occurrenceID));
  assertTrue(arch.getCore().hasTerm(DwcTerm.catalogNumber));
  assertTrue(arch.getCore().hasTerm(DwcTerm.institutionCode));
  assertTrue(arch.getCore().hasTerm(DwcTerm.basisOfRecord));
  assertTrue(arch.getCore().hasTerm(DwcTerm.scientificName));
  assertTrue(arch.getCore().hasTerm(DwcTerm.maximumElevationInMeters));
  assertTrue(arch.getCore().hasTerm(DcTerm.references));

  int i = 0;
  for (Record rec : arch.getCore()) {
    i++;
    assertEquals(rec.id(), "MO:Tropicos:" + i);
  }
  assertEquals(2, i);
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:27,代码来源:ArchiveFactoryTest.java


示例16: testTab

import org.gbif.utils.file.FileUtils; //导入依赖的package包/类
@Test
public void testTab() throws UnsupportedArchiveException, IOException {
  File tab = FileUtils.getClasspathFile("dwca/DarwinCore.txt");
  // read archive from this tmp dir
  Archive arch = ArchiveFactory.openArchive(tab);

  boolean found = false;
  int count = 0;
  for (Record rec : arch.getCore()) {
    count++;
    if ("1559060".equals(rec.id())) {
      found = true;
      assertEquals("Globicephala melaena melaena Traill", rec.value(DwcTerm.scientificName));
      assertEquals("Hershkovitz, P., Catalog of Living Whales, Smithsonian Institution, Bulletin 246, 1966, p. 91",
        rec.value(DwcTerm.nameAccordingTo));
      assertEquals("105849", rec.value(DwcTerm.parentNameUsageID));
    }
  }
  assertTrue(arch.getCore().getIgnoreHeaderLines() == 1);
  assertEquals(0, arch.getExtensions().size());
  assertEquals(24, count);
  assertTrue(found);
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:24,代码来源:ArchiveFactoryTest.java


示例17: testNullCoreID

import org.gbif.utils.file.FileUtils; //导入依赖的package包/类
/**
 * Ensure that extensions are just skipped for archives that do not have the core id in the mapped extension.
 * https://code.google.com/p/darwincore/issues/detail?id=232
 */
@Test
public void testNullCoreID() throws IOException {
  try {
    File tmpDir = Files.createTempDirectory("dwca-io-test").toFile();
    tmpDir.deleteOnExit();

    Archive archive = ArchiveFactory.openArchive(FileUtils.getClasspathFile("nullCoreID.zip"), tmpDir);
    Iterator<StarRecord> iter = archive.iterator();
    while (iter.hasNext()) {
      iter.next();
    }
  } catch (UnsupportedArchiveException e) {
    fail("Extensions with no core IDs should be ignored");
  }
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:20,代码来源:ArchiveFactoryTest.java


示例18: testOpenArchiveForEventCore

import org.gbif.utils.file.FileUtils; //导入依赖的package包/类
/**
 * Test opening a single data file with both eventID column, meaning it has dwc:Event rowType.
 */
@Test
public void testOpenArchiveForEventCore() throws IOException, UnsupportedArchiveException {
  Archive arch = ArchiveFactory.openArchive(FileUtils.getClasspathFile("event.txt"));
  assertNotNull(arch.getCore());
  assertNotNull(arch.getCore().getId());
  assertEquals(DwcTerm.eventID, arch.getCore().getId().getTerm());
  assertNotNull(arch.getCore().getRowType());
  assertEquals(DwcTerm.Event, arch.getCore().getRowType());
  assertTrue(arch.getCore().hasTerm(DwcTerm.samplingProtocol));
  assertEquals(0, arch.getExtensions().size());
  Iterator<StarRecord> dwci = arch.iterator();
  StarRecord star = dwci.next();
  assertEquals("Aubach above Wiesthal", star.core().value(DwcTerm.locality));
  assertEquals(DwcLayout.FILE_ROOT, arch.getDwcLayout());
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:19,代码来源:ArchiveFactoryTest.java


示例19: testIterator

import org.gbif.utils.file.FileUtils; //导入依赖的package包/类
@Test
public void testIterator() throws UnsupportedArchiveException, IOException {
  // test proper archive
  Archive arch = ArchiveFactory.openArchive(FileUtils.getClasspathFile("archive-dwc/DarwinCore.txt"));
  ArchiveFile af = arch.getCore();

  assertNotNull(af);
  assertNotNull(af.getId());
  assertTrue(af.hasTerm(DwcTerm.scientificName));

  // test iterator
  int counter = 0;
  Record last = null;
  for (Record rec : af) {
    counter++;
    last = rec;
    if (counter == 1) {
      assertEquals("1559060", rec.id());
    }
  }
  assertEquals(3248, counter);
  assertEquals("3082", last.id());
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:24,代码来源:ArchiveFileTest.java


示例20: testMetaDescriptorReading

import org.gbif.utils.file.FileUtils; //导入依赖的package包/类
/**
 * Test the reading of a static meta.xml file.
 *
 * @throws Exception
 */
@Test
public void testMetaDescriptorReading() throws Exception {
  // we can read only a meta.xml file as an Archive
  Archive arch = DwcMetaFiles.fromMetaDescriptor(new FileInputStream(FileUtils.getClasspathFile("meta/meta.xml")));

  //validate archive ID field
  ArchiveField af = arch.getCore().getId();
  assertEquals(Integer.valueOf(1), af.getIndex());
  //not specified, should be set to the default value
  assertEquals(ArchiveFile.DEFAULT_FIELDS_ENCLOSED_BY, arch.getCore().getFieldsEnclosedBy());

  //validate default
  af = arch.getCore().getField(DwcTerm.kingdom);
  assertEquals("Animalia", af.getDefaultValue());

  // validate vocabulary
  af = arch.getCore().getField(DwcTerm.nomenclaturalCode);
  assertEquals(NOMENCLATURAL_CODE_VOCABULARY, af.getVocabulary());

  //explicitly set to empty string which means we should not use a fieldsEnclosedBy (value == null)
  assertNull(arch.getExtension(TERM_FACTORY
          .findTerm("http://rs.tdwg.org/invented/Links")).getFieldsEnclosedBy());
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:29,代码来源:MetaDescriptorTest.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java GoraException类代码示例发布时间:2022-05-22
下一篇:
Java LiveVariableLattice类代码示例发布时间: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