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


Java FileUtils.getClasspathFile方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: testMappedTabularDataFileReaderAlwaysQuotes

import org.gbif.utils.file.FileUtils; //导入方法依赖的package包/类
@Test
public void testMappedTabularDataFileReaderAlwaysQuotes() throws Exception {
  File csv = FileUtils.getClasspathFile("csv_optional_quotes_excel2008CSV.csv");

  Term[] columnsMapping = new Term[]{DwcTerm.occurrenceID,
          DwcTerm.scientificName, DwcTerm.locality};

  TermTabularDataFileReader mappedReader =
          TermTabularFiles.newTermMappedTabularFileReader(Files.newBufferedReader(csv.toPath(), StandardCharsets.UTF_8),
                  ',', true, columnsMapping);

  TermTabularDataLine mappedLine = mappedReader.read();
  assertEquals(1, mappedLine.getLineNumber());
  assertEquals("1", mappedLine.getMappedData().get(DwcTerm.occurrenceID));
  assertEquals("This has a, comma", mappedLine.getMappedData().get(DwcTerm.locality));

  mappedLine = mappedReader.read();
  assertEquals("I say this is only a \"quote\"", mappedLine.getMappedData().get(DwcTerm.locality));

  int recordCount = 0;
  while (mappedReader.read() != null && recordCount < LOOP_SAFEGUARD) {
    recordCount++;
  }
  assertTrue("Reader loop terminate before LOOP_SAFEGUARD", recordCount < LOOP_SAFEGUARD);

  mappedReader.close();
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:28,代码来源:TermTabularDataFileReaderTest.java

示例9: testMappedTabularDataFileReaderException

import org.gbif.utils.file.FileUtils; //导入方法依赖的package包/类
@Test
public void testMappedTabularDataFileReaderException() throws Exception {
  File csv = FileUtils.getClasspathFile("csv_optional_quotes_excel2008CSV.csv");

  //only declare 2 mapping (the file includes 3 columns)
  Term[] columnsMapping = new Term[]{DwcTerm.occurrenceID, DwcTerm.scientificName};

  TermTabularDataFileReader mappedReader =
          TermTabularFiles.newTermMappedTabularFileReader(Files.newBufferedReader(csv.toPath(), StandardCharsets.UTF_8),
                  ',', true, columnsMapping);

  TermTabularDataLine mappedLine = mappedReader.read();
  assertEquals(1, mappedLine.getLineNumber());
  assertEquals("1", mappedLine.getMappedData().get(DwcTerm.occurrenceID));
  assertEquals("Got 2 mapped", 2, mappedLine.getMappedData().size());
  assertEquals("Got 1 unmapped ", 1, mappedLine.getUnmappedData().size());
  assertEquals("Returned number of column matches the content of the file", 3, mappedLine.getNumberOfColumn());

  mappedReader.close();

  //declare 1 field more
  columnsMapping = new Term[]{DwcTerm.occurrenceID, DwcTerm.scientificName, DwcTerm.locality, DwcTerm.country};
  mappedReader =
          TermTabularFiles.newTermMappedTabularFileReader(Files.newBufferedReader(csv.toPath(), StandardCharsets.UTF_8),
                  ',', true, columnsMapping);

  mappedLine = mappedReader.read();
  assertEquals(1, mappedLine.getLineNumber());
  assertEquals("1", mappedLine.getMappedData().get(DwcTerm.occurrenceID));
  assertEquals("Got 3 mapped", 3, mappedLine.getMappedData().size());
  assertNull("Got no unmapped ", mappedLine.getUnmappedData());
  assertEquals("Returned number of column matches the content of the file", 3, mappedLine.getNumberOfColumn());
  mappedReader.close();
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:35,代码来源:TermTabularDataFileReaderTest.java

示例10: testEmlOnly

import org.gbif.utils.file.FileUtils; //导入方法依赖的package包/类
@Test
public void testEmlOnly() throws IOException {
  File eml = FileUtils.getClasspathFile("metadata/eml-alone/");
  Archive archive = DwcFiles.fromLocation(eml.toPath());
  assertNotNull(archive.getMetadataLocationFile());
  assertEquals(DwcLayout.DIRECTORY_ROOT, archive.getDwcLayout());

  eml = FileUtils.getClasspathFile("metadata/eml-alone/eml.xml");
  archive = DwcFiles.fromLocation(eml.toPath());
  assertNotNull(archive.getMetadataLocationFile());
  assertEquals(DwcLayout.FILE_ROOT, archive.getDwcLayout());
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:13,代码来源:InternalDwcFileFactoryTest.java

示例11: testBuildReaderFile

import org.gbif.utils.file.FileUtils; //导入方法依赖的package包/类
@Test
public void testBuildReaderFile() throws IOException {
  File zip = FileUtils.getClasspathFile("plazi/6632D8151686A3F8C71D4B5A5B1181A4.zip");
  File tmpDir = FileUtils.createTempDir();
  tmpDir.deleteOnExit();

  Archive arch = ArchiveFactory.openArchive(zip, tmpDir);
  assertNumberStarRecords(arch, 10);
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:10,代码来源:ArchivePlaziTest.java

示例12: testIteratorDwc

import org.gbif.utils.file.FileUtils; //导入方法依赖的package包/类
@Test
public void testIteratorDwc() throws Exception {
  File csv = FileUtils.getClasspathFile("null_data.txt");
  CSVReader reader = new CSVReader(csv, "utf8", "\t", null, 1);

  Archive arch = new Archive();
  ArchiveField id = new ArchiveField(0, null, null, null);
  ArchiveField taxStatus = new ArchiveField(1, DwcTerm.taxonomicStatus, "a", null);
  ArchiveField dcmodified = new ArchiveField(6, DcTerm.modified, "mod", null);

  ArchiveFile core = mock(ArchiveFile.class);
  when(core.getCSVReader()).thenReturn(reader);
  when(core.getId()).thenReturn(id);
  when(core.getArchive()).thenReturn(arch);
  when(core.getField(Matchers.<Term>any())).thenReturn(taxStatus);
  Map<Term, ArchiveField> fields = new HashMap<Term, ArchiveField>();
  fields.put(DwcTerm.taxonomicStatus, taxStatus);
  fields.put(DcTerm.modified, dcmodified);
  when(core.getFields()).thenReturn(fields);
  when(core.hasTerm(eq(DwcTerm.taxonomicStatus))).thenReturn(true);
  when(core.hasTerm(eq(DcTerm.modified))).thenReturn(true);
  arch.setCore(core);

  Iterator<DarwinCoreRecord> iter = arch.iteratorDwc();
  while (iter.hasNext()) {
    DarwinCoreRecord rec = iter.next();
    assertEquals("a", rec.getTaxonomicStatus());
    assertEquals("mod", rec.getModified());
  }
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:31,代码来源:ArchiveTest.java

示例13: testGnubTab

import org.gbif.utils.file.FileUtils; //导入方法依赖的package包/类
/**
 * Test GNUB style dwca with a single tab delimited file that has a .tab suffix.
 */
@Test
public void testGnubTab() throws UnsupportedArchiveException, IOException {
  File tab = FileUtils.getClasspathFile("gnub.tab");
  // read archive from this tmp dir
  Archive arch = ArchiveFactory.openArchive(tab);

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

示例14: testGnubTabZip

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

示例15: testTab2

import org.gbif.utils.file.FileUtils; //导入方法依赖的package包/类
@Test
public void testTab2() throws UnsupportedArchiveException, IOException {
  File tab = FileUtils.getClasspathFile("issues/Borza.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 (count == 1) {
      //1 Borza:Corophiidae:1 Borza Borza:Corophiidae Corophiidae 1   Animalia  Arthropoda  Malacostraca  Amphipoda Corophiidae Chelicorophium    sowinskyi   Chelicorophium sowinskyi  "(Martynov, 1924)"  species   Péter Borza   Europe  Danube  Hungary     47.788111 18.960944           Preserved Specimen  1917-07-17  1917  7 17      Unger E
      assertEquals("1", rec.id());
      assertEquals("Chelicorophium sowinskyi", rec.value(DwcTerm.scientificName));
      // we do detect optional quotation in tab files...
      assertEquals("(Martynov, 1924)", rec.value(DwcTerm.scientificNameAuthorship));
      assertEquals("47.788111", rec.value(DwcTerm.decimalLatitude));
      assertEquals("18.960944", rec.value(DwcTerm.decimalLongitude));
    }
    if ("173".equals(rec.id())) {
      found = true;
      assertEquals("Chelicorophium curvispinum", rec.value(DwcTerm.scientificName));
      assertEquals("(G. O. Sars, 1895)", rec.value(DwcTerm.scientificNameAuthorship));
      assertEquals("47.965166", rec.value(DwcTerm.decimalLatitude));
      assertEquals("17.304666", rec.value(DwcTerm.decimalLongitude));
    }
  }
  assertTrue(arch.getCore().getIgnoreHeaderLines() == 1);
  assertEquals(435, count);
  assertTrue(found);
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:32,代码来源:ArchiveFactoryTest.java


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