本文整理汇总了Java中org.gbif.utils.file.FileUtils类的典型用法代码示例。如果您正苦于以下问题:Java FileUtils类的具体用法?Java FileUtils怎么用?Java FileUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileUtils类属于org.gbif.utils.file包,在下文中一共展示了FileUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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()));
}
示例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);
}
示例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));
}
示例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);
}
}
示例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]);
}
}
示例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();
}
示例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);
}
示例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();
}
示例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++;
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}