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


Java FileUtils.createTempDir方法代码示例

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


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

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

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

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

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

示例5: testAddingCoreIdTermTwice

import org.gbif.utils.file.FileUtils; //导入方法依赖的package包/类
@Test(expected = IllegalStateException.class)
public void testAddingCoreIdTermTwice() throws Exception {
  File dwcaDir = FileUtils.createTempDir();
  dwcaDir.deleteOnExit();
  DwcaWriter writer = new DwcaWriter(DwcTerm.Taxon, DwcTerm.taxonID, dwcaDir, true);
  writer.newRecord("dummy1");
  writer.addCoreColumn(DwcTerm.taxonID, "dummy1");
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:9,代码来源:DwcaWriterTest.java

示例6: testHeaders1

import org.gbif.utils.file.FileUtils; //导入方法依赖的package包/类
@Test
public void testHeaders1() 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);
  writer.newRecord("dummy2");
  writer.addCoreColumn(DwcTerm.parentNameUsageID);
  writer.addCoreColumn(DwcTerm.acceptedNameUsageID);
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:14,代码来源:DwcaWriterTest.java

示例7: testHeaders2

import org.gbif.utils.file.FileUtils; //导入方法依赖的package包/类
@Test(expected = IllegalStateException.class)
public void testHeaders2() 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);
  writer.newRecord("dummy2");
  writer.addCoreColumn(DwcTerm.scientificName);
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:13,代码来源:DwcaWriterTest.java

示例8: writeEmpty

import org.gbif.utils.file.FileUtils; //导入方法依赖的package包/类
@Test(expected = IllegalStateException.class)
public void writeEmpty() throws Exception {
    File dwca = FileUtils.createTempDir();
    try (DwcaStreamWriter dwcaWriter = new DwcaStreamWriter(dwca, DwcTerm.Taxon, DwcTerm.taxonID, true)){

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

示例9: testStartUp

import org.gbif.utils.file.FileUtils; //导入方法依赖的package包/类
/**
 * Make sure messages are all registered and the service starts up fine.
 */
@Test
public void testStartUp() throws Exception {
  File neoTmp = FileUtils.createTempDir();
  neoTmp.deleteOnExit();
  ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
  ImporterConfiguration cfg = mapper.readValue(Resources.getResource("cfg-importer.yaml"),
                                               ImporterConfiguration.class);
  cfg.neo.neoRepository = neoTmp;

  ImporterService imp = new ImporterService(cfg);
  imp.startUp();
}
 
开发者ID:gbif,项目名称:checklistbank,代码行数:16,代码来源:ImporterServiceIT.java

示例10: testExport

import org.gbif.utils.file.FileUtils; //导入方法依赖的package包/类
@Test
public void testExport() throws Exception {
  ClbConfiguration cfg = mapper.readValue(Resources.getResource("clb-cfg.yaml"), ClbConfiguration.class);
  File repository = FileUtils.createTempDir();

  try {
    Exporter exp = Exporter.create(repository, cfg, "http://api.gbif.org/v1");
    exp.export(dataset(Constants.NUB_DATASET_KEY));

    exp.export(dataset(ClbDbTestRule.SQUIRRELS_DATASET_KEY));

  } finally {
    org.apache.commons.io.FileUtils.deleteDirectory(repository);
  }
}
 
开发者ID:gbif,项目名称:checklistbank,代码行数:16,代码来源:ExporterIT.java

示例11: testHeaderWriting

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

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

  writer.newRecord("dummy1");
  writer.addCoreColumn(DwcTerm.parentNameUsageID);
  writer.addCoreColumn(DwcTerm.acceptedNameUsageID);
  writer.addCoreColumn(DwcTerm.scientificName);
  writer.addCoreColumn(GbifTerm.canonicalName);
  writer.addCoreColumn(DwcTerm.taxonRank, "species");
  writer.addCoreColumn(DwcTerm.taxonomicStatus);
  writer.addCoreColumn(DwcTerm.kingdom);
  writer.addCoreColumn(DwcTerm.phylum);
  writer.addCoreColumn(DwcTerm.class_);
  writer.addCoreColumn(DwcTerm.order);
  writer.addCoreColumn(DwcTerm.family);
  writer.addCoreColumn(GbifTerm.depth);
  writer.addCoreColumn(GbifTerm.depthAccuracy);

  writer.newRecord("dummy2");
  writer.addCoreColumn(DwcTerm.kingdom, "Plantae");
  writer.addCoreColumn(DwcTerm.phylum);
  writer.addCoreColumn(DwcTerm.class_);
  writer.addCoreColumn(DwcTerm.order);
  writer.addCoreColumn(DwcTerm.family, "Asteraceae");

  writer.newRecord("dummy3");
  writer.addCoreColumn(GbifTerm.depth, "2");
  writer.addCoreColumn(GbifTerm.depthAccuracy, "1");

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

  eData.put(DwcTerm.locality, "locality2");
  writer.addExtensionRecord(GbifTerm.Distribution, eData);

  writer.close();

  File cf = new File(dwcaDir, writer.getDataFiles().get(DwcTerm.Taxon));
  File df = new File(dwcaDir, writer.getDataFiles().get(GbifTerm.Distribution));

  // check if taxon file contains headers
  String[] headers = getFirstRow(cf);
  LOG.debug(Joiner.on("; ").useForNull("NULL").join(headers));
  assertEquals(14, headers.length);
  assertEquals("taxonID", headers[0]);
  assertEquals("parentNameUsageID", headers[1]);
  assertEquals("kingdom", headers[7]);

  // check if extension file contains headers
  headers = getFirstRow(df);
  LOG.debug(Joiner.on("; ").useForNull("NULL").join(headers));
  assertEquals(4, headers.length);
  assertEquals("taxonID", headers[0]);
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:65,代码来源:DwcaWriterTest.java

示例12: testWriterUsingDefaultValues

import org.gbif.utils.file.FileUtils; //导入方法依赖的package包/类
/**
 * Test the writing of an archive that includes some default values in the core and in one extension.
 * 
 * @throws Exception
 */
@Test
public void testWriterUsingDefaultValues() 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, "1");
  writer.addCoreColumn(DwcTerm.acceptedNameUsageID, "2");
  writer.addCoreColumn(DwcTerm.countryCode);
  
  // add a VernacularName extension record
  Map<Term,String> extensionRecord = new HashMap<Term, String>();
  extensionRecord.put(DwcTerm.vernacularName, "Komodo Dragon");
  extensionRecord.put(DcTerm.language, null);
  writer.addExtensionRecord(GbifTerm.VernacularName, extensionRecord);
  
  writer.addCoreDefaultValue(DwcTerm.collectionCode, "A2Z");
  writer.addCoreDefaultValue(DwcTerm.countryCode, "CA");
  writer.addDefaultValue(GbifTerm.VernacularName, DcTerm.language, "en");
  
  // add a second records and overwrite the default value
  writer.newRecord("dummy2");
  writer.addCoreColumn(DwcTerm.parentNameUsageID, "1");
  writer.addCoreColumn(DwcTerm.acceptedNameUsageID, "2");
  writer.addCoreColumn(DwcTerm.countryCode, "ID");
  
  // add a VernacularName extension record
  extensionRecord = new HashMap<Term, String>();
  extensionRecord.put(DwcTerm.vernacularName, "Varano De Komodo");
  extensionRecord.put(DcTerm.language, "es");
  writer.addExtensionRecord(GbifTerm.VernacularName, extensionRecord);
  
  writer.close();

  // validate core content
  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));
  assertEquals("A2Z", firstRecord.value(DwcTerm.collectionCode));
  assertEquals("CA", firstRecord.value(DwcTerm.countryCode));
  assertEquals("A2Z", arch.getCore().getField(DwcTerm.collectionCode).getDefaultValue());
  assertEquals("CA", arch.getCore().getField(DwcTerm.countryCode).getDefaultValue());
  
  Record secondRecord = recIt.next();
  assertEquals("dummy2", secondRecord.id());
  assertEquals("dummy2", secondRecord.value(DwcTerm.taxonID));
  assertEquals("A2Z", secondRecord.value(DwcTerm.collectionCode));
  assertEquals("ID", secondRecord.value(DwcTerm.countryCode));
  
  // validate extension content
  Iterator<Record> extRecIt = arch.getExtension(GbifTerm.VernacularName).iterator();
  assertEquals("en", arch.getExtension(GbifTerm.VernacularName).getField(DcTerm.language).getDefaultValue());
  firstRecord = extRecIt.next();
  assertEquals("dummy1", firstRecord.id());
  assertEquals("en", firstRecord.value(DcTerm.language));
  
  secondRecord = extRecIt.next();
  assertEquals("dummy2", secondRecord.id());
  assertEquals("es", secondRecord.value(DcTerm.language));
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:71,代码来源:DwcaWriterTest.java

示例13: downloadArchive

import org.gbif.utils.file.FileUtils; //导入方法依赖的package包/类
private Archive downloadArchive() throws IOException, URISyntaxException {
  // download url
  final String url = props.getProperty("col.annotation.url");
  // local work dir
  File workDir = FileUtils.createTempDir();
  workDir.deleteOnExit();
  // local zip file
  File zip = new File(workDir, "annotation.zip");
  // local decompressed dwca
  File dwca = new File(workDir, "annotation");
  // insert folders
  org.apache.commons.io.FileUtils.forceMkdir(dwca);

  // use a 10 minutes timeout
  HttpClient client = HttpUtil.newMultithreadedClient(600000, 10, 10);
  // authentication
  HttpContext authContext = new BasicHttpContext();
  URI authUri = new URI(url);
  AuthScope scope = new AuthScope(authUri.getHost(), AuthScope.ANY_PORT, AuthScope.ANY_REALM);

  CredentialsProvider credsProvider = new BasicCredentialsProvider();
  credsProvider.setCredentials(scope, new UsernamePasswordCredentials(props.getProperty("col.annotation.user"), props.getProperty("col.annotation.password")));
  authContext.setAttribute(ClientContext.CREDS_PROVIDER, credsProvider);

  HttpGet get = new HttpGet(url);
  HttpResponse response = client.execute(get, authContext);

  if (response.getStatusLine().getStatusCode() != 200) {
    LOG.error("{} error downloading annotations from {}: {}", response.getStatusLine(), url,
      response.getStatusLine().getReasonPhrase());
    System.exit(1);
  }

  HttpEntity entity = response.getEntity();
  if (entity != null) {
    // copy stream to local file
    OutputStream fos = new FileOutputStream(zip, false);
    try {
      entity.writeTo(fos);
    } finally {
      fos.close();
    }
  }

  LOG.info("Successfully downloaded {} to {}", url, zip.getAbsolutePath());

  // open archive
  Archive arch = ArchiveFactory.openArchive(zip, dwca);
  return arch;
}
 
开发者ID:gbif,项目名称:checklistbank,代码行数:51,代码来源:ColAnnotationImport.java


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