@Test public void testParseGlobalMetadata() throws Exception { Parser parser = new GribParser(); Metadata metadata = new Metadata(); ContentHandler handler = new BodyContentHandler(); try (InputStream stream = GribParser.class.getResourceAsStream("/test-documents/gdas1.forecmwf.2014062612.grib2")) { parser.parse(stream, handler, metadata, new ParseContext()); } assertNotNull(metadata); String content = handler.toString(); assertTrue(content.contains("dimensions:")); assertTrue(content.contains("variables:")); }
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { metadata.set(Metadata.CONTENT_TYPE, GRIB_MIME_TYPE); TikaInputStream tis = TikaInputStream.get(stream, new TemporaryResources()); File gribFile = tis.getFile(); try { NetcdfFile ncFile = NetcdfDataset.openFile(gribFile.getAbsolutePath(), null); for (Attribute attr : ncFile.getGlobalAttributes()) { Property property = resolveMetadataKey(attr.getFullName()); if (attr.getDataType().isString()) { metadata.add(property, attr.getStringValue()); } else if (attr.getDataType().isNumeric()) { int value = attr.getNumericValue().intValue(); metadata.add(property, String.valueOf(value)); } } XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); xhtml.newline(); xhtml.startElement("ul"); xhtml.characters("dimensions:"); xhtml.newline(); for (Dimension dim : ncFile.getDimensions()){ xhtml.element("li", dim.getFullName() + "=" + String.valueOf(dim.getLength()) + ";"); xhtml.newline(); } xhtml.startElement("ul"); xhtml.characters("variables:"); xhtml.newline(); for (Variable var : ncFile.getVariables()){ xhtml.element("p", String.valueOf(var.getDataType()) + var.getNameAndDimensions() + ";"); for(Attribute element : var.getAttributes()){ xhtml.element("li", " :" + element + ";"); xhtml.newline(); } } xhtml.endElement("ul"); xhtml.endElement("ul"); xhtml.endDocument(); } catch (IOException e) { throw new TikaException("NetCDF parse error", e); } }
GribParser extends AbstractParser { public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { metadata.set(Metadata.CONTENT_TYPE, GRIB_MIME_TYPE); TikaInputStream tis = TikaInputStream.get(stream, new TemporaryResources()); File gribFile = tis.getFile(); try { NetcdfFile ncFile = NetcdfDataset.openFile(gribFile.getAbsolutePath(), null); for (Attribute attr : ncFile.getGlobalAttributes()) { Property property = resolveMetadataKey(attr.getFullName()); if (attr.getDataType().isString()) { metadata.add(property, attr.getStringValue()); } else if (attr.getDataType().isNumeric()) { int value = attr.getNumericValue().intValue(); metadata.add(property, String.valueOf(value)); } } XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); xhtml.newline(); xhtml.startElement("ul"); xhtml.characters("dimensions:"); xhtml.newline(); for (Dimension dim : ncFile.getDimensions()){ xhtml.element("li", dim.getFullName() + "=" + String.valueOf(dim.getLength()) + ";"); xhtml.newline(); } xhtml.startElement("ul"); xhtml.characters("variables:"); xhtml.newline(); for (Variable var : ncFile.getVariables()){ xhtml.element("p", String.valueOf(var.getDataType()) + var.getNameAndDimensions() + ";"); for(Attribute element : var.getAttributes()){ xhtml.element("li", " :" + element + ";"); xhtml.newline(); } } xhtml.endElement("ul"); xhtml.endElement("ul"); xhtml.endDocument(); } catch (IOException e) { throw new TikaException("NetCDF parse error", e); } } }
GribParser extends AbstractParser { public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { metadata.set(Metadata.CONTENT_TYPE, GRIB_MIME_TYPE); TikaInputStream tis = TikaInputStream.get(stream, new TemporaryResources()); File gribFile = tis.getFile(); try { NetcdfFile ncFile = NetcdfDataset.openFile(gribFile.getAbsolutePath(), null); for (Attribute attr : ncFile.getGlobalAttributes()) { Property property = resolveMetadataKey(attr.getFullName()); if (attr.getDataType().isString()) { metadata.add(property, attr.getStringValue()); } else if (attr.getDataType().isNumeric()) { int value = attr.getNumericValue().intValue(); metadata.add(property, String.valueOf(value)); } } XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); xhtml.newline(); xhtml.startElement("ul"); xhtml.characters("dimensions:"); xhtml.newline(); for (Dimension dim : ncFile.getDimensions()){ xhtml.element("li", dim.getFullName() + "=" + String.valueOf(dim.getLength()) + ";"); xhtml.newline(); } xhtml.startElement("ul"); xhtml.characters("variables:"); xhtml.newline(); for (Variable var : ncFile.getVariables()){ xhtml.element("p", String.valueOf(var.getDataType()) + var.getNameAndDimensions() + ";"); for(Attribute element : var.getAttributes()){ xhtml.element("li", " :" + element + ";"); xhtml.newline(); } } xhtml.endElement("ul"); xhtml.endElement("ul"); xhtml.endDocument(); } catch (IOException e) { throw new TikaException("NetCDF parse error", e); } }  }
GribParser extends AbstractParser { public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { metadata.set(Metadata.CONTENT_TYPE, GRIB_MIME_TYPE); TikaInputStream tis = TikaInputStream.get(stream, new TemporaryResources()); File gribFile = tis.getFile(); try { NetcdfFile ncFile = NetcdfDataset.openFile(gribFile.getAbsolutePath(), null); for (Attribute attr : ncFile.getGlobalAttributes()) { Property property = resolveMetadataKey(attr.getFullName()); if (attr.getDataType().isString()) { metadata.add(property, attr.getStringValue()); } else if (attr.getDataType().isNumeric()) { int value = attr.getNumericValue().intValue(); metadata.add(property, String.valueOf(value)); } } XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); xhtml.newline(); xhtml.startElement("ul"); xhtml.characters("dimensions:"); xhtml.newline(); for (Dimension dim : ncFile.getDimensions()){ xhtml.element("li", dim.getFullName() + "=" + String.valueOf(dim.getLength()) + ";"); xhtml.newline(); } xhtml.startElement("ul"); xhtml.characters("variables:"); xhtml.newline(); for (Variable var : ncFile.getVariables()){ xhtml.element("p", String.valueOf(var.getDataType()) + var.getNameAndDimensions() + ";"); for(Attribute element : var.getAttributes()){ xhtml.element("li", " :" + element + ";"); xhtml.newline(); } } xhtml.endElement("ul"); xhtml.endElement("ul"); xhtml.endDocument(); } catch (IOException e) { throw new TikaException("NetCDF parse error", e); } }  Set<MediaType> getSupportedTypes(ParseContext context); void parse(InputStream stream, ContentHandler handler,
                      Metadata metadata, ParseContext context); }
GribParser extends AbstractParser { public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { metadata.set(Metadata.CONTENT_TYPE, GRIB_MIME_TYPE); TikaInputStream tis = TikaInputStream.get(stream, new TemporaryResources()); File gribFile = tis.getFile(); try { NetcdfFile ncFile = NetcdfDataset.openFile(gribFile.getAbsolutePath(), null); for (Attribute attr : ncFile.getGlobalAttributes()) { Property property = resolveMetadataKey(attr.getFullName()); if (attr.getDataType().isString()) { metadata.add(property, attr.getStringValue()); } else if (attr.getDataType().isNumeric()) { int value = attr.getNumericValue().intValue(); metadata.add(property, String.valueOf(value)); } } XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); xhtml.newline(); xhtml.startElement("ul"); xhtml.characters("dimensions:"); xhtml.newline(); for (Dimension dim : ncFile.getDimensions()){ xhtml.element("li", dim.getFullName() + "=" + String.valueOf(dim.getLength()) + ";"); xhtml.newline(); } xhtml.startElement("ul"); xhtml.characters("variables:"); xhtml.newline(); for (Variable var : ncFile.getVariables()){ xhtml.element("p", String.valueOf(var.getDataType()) + var.getNameAndDimensions() + ";"); for(Attribute element : var.getAttributes()){ xhtml.element("li", " :" + element + ";"); xhtml.newline(); } } xhtml.endElement("ul"); xhtml.endElement("ul"); xhtml.endDocument(); } catch (IOException e) { throw new TikaException("NetCDF parse error", e); } }  Set<MediaType> getSupportedTypes(ParseContext context); void parse(InputStream stream, ContentHandler handler,
                      Metadata metadata, ParseContext context); static final String GRIB_MIME_TYPE; }