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


Java UnsupportedArchiveException类代码示例

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


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

示例1: getFirstChar

import org.gbif.dwca.io.UnsupportedArchiveException; //导入依赖的package包/类
private static Character getFirstChar(String x) throws UnsupportedArchiveException {
  if (x == null || x.length() == 0) {
    return null;
  }
  if (x.length() == 1) {
    return x.charAt(0);
  }
  if (x.equalsIgnoreCase("\\t")) {
    return '\t';
  }
  if (x.equalsIgnoreCase("\\n")) {
    return '\n';
  }
  if (x.equalsIgnoreCase("\\r")) {
    return '\r';
  }
  if (x.length() > 1) {
    throw new UnsupportedArchiveException(
            "Only darwin core archives with a single quotation character are supported, but found >>>" + x + "<<<");
  }
  return ' ';
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:23,代码来源:MetaXMLSaxHandler.java

示例2: buildField

import org.gbif.dwca.io.UnsupportedArchiveException; //导入依赖的package包/类
/**
 * Build an ArchiveField object based on xml attributes.
 */
private ArchiveField buildField(Attributes attributes) {
  // build field
  Term term = TERM_FACTORY.findTerm(getAttr(attributes, "term"));
  String defaultValue = getAttr(attributes, "default");
  String vocabulary = getAttr(attributes, "vocabulary");
  ArchiveField.DataType type = ArchiveField.DataType.findByXmlSchemaType(getAttr(attributes, "type"));
  if (type == null) {
    type = ArchiveField.DataType.string;
  }
  String indexAsString = getAttr(attributes, "index");
  Integer index = null;
  if (indexAsString != null) {
    // let bad errors be thrown up
    try {
      index = Integer.parseInt(indexAsString);
    } catch (NumberFormatException e) {
      throw new UnsupportedArchiveException(e);
    }
  }
  String delimiter = getAttr(attributes, "delimitedBy");
  return new ArchiveField(index, term, defaultValue, type, delimiter, vocabulary);
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:26,代码来源:MetaXMLSaxHandler.java

示例3: main

import org.gbif.dwca.io.UnsupportedArchiveException; //导入依赖的package包/类
public static void main(String[] args) throws IOException, UnsupportedArchiveException {
  // opens csv files with headers or dwc-a direcotries with a meta.xml descriptor
  Archive arch = ArchiveFactory
    .openArchive(new File("/Volumes/Scratch/ecat-data-col/checklists/beac2c55-d889-4358-a414-b1db79ba3536/dwc-a"));

  // does scientific name exist?
  if (!arch.getCore().hasTerm(DwcTerm.scientificName)) {
    System.out.println("This application requires dwc-a with scientific names");
    System.exit(1);
  }

  // loop over core darwin core records
  Iterator<DarwinCoreRecord> iter = arch.iteratorDwc();
  DarwinCoreRecord dwc;
  while (iter.hasNext()) {
    dwc = iter.next();
    if (dwc.getScientificName().startsWith("Ambispora callosa")) {
      System.out.println(dwc.getScientificName());
      System.out.println(dwc.getScientificNameAuthorship());
      System.out.println(dwc);
    }
  }
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:24,代码来源:ScanArchiveForScientificName.java

示例4: main

import org.gbif.dwca.io.UnsupportedArchiveException; //导入依赖的package包/类
public static void main(String[] args) throws IOException, UnsupportedArchiveException {
  // opens csv files with headers or dwc-a direcotries with a meta.xml descriptor
  Archive arch = ArchiveFactory.openArchive(new File(args[0]));

  System.out.println("Reading archive from "+arch.getLocation().getAbsolutePath());
  System.out.println("Archive of rowtype "+arch.getCore().getRowType()+" with "+arch.getExtensions().size()+" extensions");
  // loop over star records. i.e. core with all linked extension records
  for (StarRecord rec : arch) {
    // print core ID + scientific name
    System.out.println(rec.core().id()
      + " sciname:" + rec.core().value(DwcTerm.scientificName)
      + " bor:" + rec.core().value(DwcTerm.basisOfRecord)
    );
    // print out all rowTypes
    for (Record erec : rec) {
      // print out extension rowtype
      System.out.println(erec.rowType() + ", id="+erec.value(DcTerm.identifier));
    }
  }
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:21,代码来源:UsageExample.java

示例5: downloadAndExtract

import org.gbif.dwca.io.UnsupportedArchiveException; //导入依赖的package包/类
private void downloadAndExtract(Dataset d, URI dwcaUri) throws IOException, UnsupportedArchiveException {
  final File dwca = cfg.archiveFile(d.getKey());
  if (dwca.exists()) {
    dwca.delete();
    LOG.debug("Removed previous dwc archive at {}", dwca.getAbsolutePath());
  }
  http.download(dwcaUri, dwca);

  // success!
  LOG.info("Downloaded dwc archive for dataset {} from {} to {}", d.getTitle(), dwcaUri, dwca.getAbsolutePath());

  // open archive
  final File archiveDir = cfg.archiveDir(d.getKey());
  if (archiveDir.exists()) {
    FileUtils.deleteDirectory(archiveDir);
    LOG.debug("Removed previous dwc archive dir {}", dwca.getAbsolutePath());
  }
  ArchiveFactory.openArchive(dwca, archiveDir);
  LOG.debug("Opened dwc archive successfully for dataset {} at {}", d.getTitle(), dwca, archiveDir.getAbsolutePath());
}
 
开发者ID:gbif,项目名称:checklistbank,代码行数:21,代码来源:CrawlerService.java

示例6: fromMetaDescriptor

import org.gbif.dwca.io.UnsupportedArchiveException; //导入依赖的package包/类
/**
 * Read the provided meta descriptor (e.g. meta.xml) and return a {@link Archive}.
 * @param metaDescriptor
 * @throws SAXException
 * @throws IOException
 * @throws UnsupportedArchiveException
 * @return a new {@link Archive}, never null
 */
public static Archive fromMetaDescriptor(InputStream metaDescriptor) throws SAXException, IOException, UnsupportedArchiveException {
  Archive archive = new Archive();
  try (BOMInputStream bomInputStream = new BOMInputStream(metaDescriptor)) {
    SAXParser p = SAX_FACTORY.newSAXParser();
    MetaXMLSaxHandler mh = new MetaXMLSaxHandler(archive);
    p.parse(bomInputStream, mh);
  } catch (ParserConfigurationException e) {
    throw new SAXException(e);
  }
  return archive;
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:20,代码来源:DwcMetaFiles.java

示例7: buildArchiveFile

import org.gbif.dwca.io.UnsupportedArchiveException; //导入依赖的package包/类
private ArchiveFile buildArchiveFile(Attributes attr) throws UnsupportedArchiveException {
  ArchiveFile dwcFile = new ArchiveFile();

  // extract the File attributes
  if (getAttr(attr, "encoding") != null) {
    dwcFile.setEncoding(getAttr(attr, "encoding"));
  }
  if (getAttr(attr, "fieldsTerminatedBy") != null) {
    dwcFile.setFieldsTerminatedBy(unescapeBackslash(getAttr(attr, "fieldsTerminatedBy")));
  }
  // for fieldsEnclosedBy there is a distinction between not provided and provided with an empty string
  if (getAttr(attr, "fieldsEnclosedBy") != null) {
    dwcFile.setFieldsEnclosedBy(getFirstChar(getAttr(attr, "fieldsEnclosedBy")));
  }
  else if (getAttrRaw(attr, "fieldsEnclosedBy") != null) {
    dwcFile.setFieldsEnclosedBy(null);
  }
  if (getAttr(attr, "linesTerminatedBy") != null) {
    dwcFile.setLinesTerminatedBy(unescapeBackslash(getAttr(attr, "linesTerminatedBy")));
  }
  if (getAttr(attr, "rowType") != null) {
    dwcFile.setRowType(TERM_FACTORY.findTerm(getAttr(attr, "rowType")));
  }
  String ignoreHeaderLines = getAttr(attr, "ignoreHeaderLines");
  try {
    dwcFile.setIgnoreHeaderLines(Integer.parseInt(ignoreHeaderLines));
  } catch (NumberFormatException ignored) { // swallow null or bad value
  }
  return dwcFile;
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:31,代码来源:MetaXMLSaxHandler.java

示例8: fromCompressed

import org.gbif.dwca.io.UnsupportedArchiveException; //导入依赖的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

示例9: fromLocation

import org.gbif.dwca.io.UnsupportedArchiveException; //导入依赖的package包/类
/**
 * @param dwcLocation the location of an expanded dwc archive directory or just a single dwc text file
 * @return new {@link Archive}, never null. But, the {@link Archive} can be empty (e.g. no core)
 */
static Archive fromLocation(Path dwcLocation) throws IOException, UnsupportedArchiveException {
  if (!Files.exists(dwcLocation)) {
    throw new FileNotFoundException("dwcLocation does not exist: " + dwcLocation.toAbsolutePath());
  }
  // delegate to {@link #archiveFromSingleFile) if its a single file, not a folder
  if (Files.isRegularFile(dwcLocation)) {
    return archiveFromSingleFile(dwcLocation);
  }

  Archive archive = new Archive();
  applyIpt205Patch(dwcLocation);

  // Check for meta descriptor
  Path metaDescriptorFile = dwcLocation.resolve(Archive.META_FN);
  if (Files.exists(metaDescriptorFile)) {
    // read metaDescriptor file
    try {
      archive = DwcMetaFiles.fromMetaDescriptor(new FileInputStream(metaDescriptorFile.toFile()));
    } catch (SAXException | IOException e) {
      // using UnsupportedArchiveException for backward compatibility but IOException would be fine here
      throw new UnsupportedArchiveException(e);
    }
  } else {
    // meta.xml lacking.
    // Try to detect data files ourselves as best as we can.
    // look for a single, visible text data file
    List<File> dataFiles = extractPossibleDataFile(dwcLocation.toFile());
    if (dataFiles.size() == 1) {
      archive = archiveFromSingleFile(dataFiles.get(0).toPath());
    }
  }

  // check if we also have a metadata file next to this data file
  DwcMetaFiles.discoverMetadataFile(dwcLocation)
          .ifPresent(archive::setMetadataLocation);

  archive.setLocation(dwcLocation.toFile());
  archive.setDwcLayout(DwcLayout.DIRECTORY_ROOT);

  return archive;
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:46,代码来源:InternalDwcFileFactory.java

示例10: fromSingleFile

import org.gbif.dwca.io.UnsupportedArchiveException; //导入依赖的package包/类
/**
 * Return a {@link ArchiveFile} based on a single data file.
 * Delimiter, quote char and encoding will be extracted from the file using {@link TabularFileMetadataExtractor}.
 * Columns will be determined by extracting the first line of the file.
 * The end of line character can only be {@link #DEFAULT_ENDLINE_CHAR}.
 * @param dataFile
 * @return
 * @throws UnsupportedArchiveException
 * @throws IOException
 */
static ArchiveFile fromSingleFile(Path dataFile) throws UnsupportedArchiveException, IOException {
  Preconditions.checkArgument(Files.isRegularFile(dataFile), "dataFile shall be a file");
  ArchiveFile dwcFile = new ArchiveFile();
 // dwcFile.addLocation(null);
  dwcFile.setIgnoreHeaderLines(1);

  TabularFileMetadata tabularFileMetadata = TabularFileMetadataExtractor.extractTabularFileMetadata(dataFile);
  dwcFile.setFieldsTerminatedBy(Optional.ofNullable(tabularFileMetadata.getDelimiter()).orElse(DEFAULT_DELIMITER_CHAR).toString());
  dwcFile.setFieldsEnclosedBy(tabularFileMetadata.getQuotedBy());
  dwcFile.setEncoding(tabularFileMetadata.getEncoding().name());

  List<String> headers;
  try (TabularDataFileReader<List<String>> reader =
               TabularFiles.newTabularFileReader(Files.newBufferedReader(dataFile, tabularFileMetadata.getEncoding()),
                       dwcFile.getFieldsTerminatedBy().charAt(0), DEFAULT_ENDLINE_CHAR,
                       dwcFile.getFieldsEnclosedBy(), true)) {
    headers = reader.getHeaderLine() == null ? Collections.emptyList() : reader.getHeaderLine();
  }

  // detect dwc terms as good as we can based on header row
  int index = 0;
  for (String head : headers) {
    // there are never any quotes in term names - remove them just in case the we didn't recognize them
    if (head != null && head.length() > 1) {
      try {
        Term dt = TERM_FACTORY.findTerm(head);
        dwcFile.addField(new ArchiveField(index, dt, null, ArchiveField.DataType.string));
      } catch (IllegalArgumentException e) {
        LOG.warn("Illegal term name >>{}<< found in header, ignore column {}", head, index);
      }
    }
    index++;
  }

  List<Term> headerAsTerm = dwcFile.getFields().keySet()
          .stream()
          .collect(Collectors.toList());

  determineRecordIdentifier(headerAsTerm).ifPresent(
          t -> dwcFile.setId(dwcFile.getField(t))
  );

  determineRowType(headerAsTerm).ifPresent(dwcFile::setRowType);
  return dwcFile;
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:56,代码来源:InternalDwcFileFactory.java

示例11: testFromCompressedZip

import org.gbif.dwca.io.UnsupportedArchiveException; //导入依赖的package包/类
@Test
public void testFromCompressedZip() throws UnsupportedArchiveException, IOException {
  // test zip with 1 extension file
  File zip = FileUtils.getClasspathFile("archive-tax.zip");
  assertIdInCompressed(zip.toPath(), "113775");
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:7,代码来源:InternalDwcFileFactoryTest.java

示例12: testFromCompressedTarGzip

import org.gbif.dwca.io.UnsupportedArchiveException; //导入依赖的package包/类
@Test
public void testFromCompressedTarGzip() throws UnsupportedArchiveException, IOException {
  // test gziped tar file with 1 extension
  File gzip = FileUtils.getClasspathFile("archive-tax.tar.gz");
  assertIdInCompressed(gzip.toPath(), "113775");
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:7,代码来源:InternalDwcFileFactoryTest.java

示例13: fromLocation

import org.gbif.dwca.io.UnsupportedArchiveException; //导入依赖的package包/类
/**
 * Build an {@link Archive} from a location. The location can be an uncompressed directory or an uncompressed file.
 *
 * @param dwcLocation the location of an expanded dwc archive directory, a single dwc text file or a metadata
 *                    document
 *
 * @return new {@link Archive}, never null. But, the {@link Archive} can be empty (e.g. no core)
 */
public static Archive fromLocation(Path dwcLocation) throws IOException, UnsupportedArchiveException {
  // delegate to InternalDwcFileFactory
  return InternalDwcFileFactory.fromLocation(dwcLocation);
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:13,代码来源:DwcFiles.java

示例14: fromCompressed

import org.gbif.dwca.io.UnsupportedArchiveException; //导入依赖的package包/类
/**
 * Build an {@link Archive} from a compressed file. The compressed file will be extracted in the provided directory.
 * The supported compressions are zip and gzip.
 *
 * @param dwcaLocation the location of a dwc archive(compressed)
 * @param destination  the destination of the uncompressed content.
 *
 * @return new {@link Archive}, never null. But, the {@link Archive} can be empty (e.g. no core)
 *
 * @throws IOException
 * @throws UnsupportedArchiveException
 */
public static Archive fromCompressed(Path dwcaLocation, Path destination) throws IOException, UnsupportedArchiveException {
  // delegate to InternalDwcFileFactory
  return InternalDwcFileFactory.fromCompressed(dwcaLocation, destination);
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:17,代码来源:DwcFiles.java


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