@Test public void testMultiColumns() throws Exception { ContentHandler handler = new BodyContentHandler(); Metadata metadata = new Metadata(); try (InputStream stream = SAS7BDATParserTest.class.getResourceAsStream( "/test-documents/test-columnar.sas7bdat")) { AUTO_DETECT_PARSER.parse(stream, handler, metadata, new ParseContext()); } assertEquals("application/x-sas-data", metadata.get(Metadata.CONTENT_TYPE)); assertEquals("TESTING", metadata.get(TikaCoreProperties.TITLE)); assertEquals("2018-05-18T11:38:30Z", metadata.get(TikaCoreProperties.CREATED)); assertEquals("2018-05-18T11:38:30Z", metadata.get(TikaCoreProperties.MODIFIED)); assertEquals("1", metadata.get(PagedText.N_PAGES)); assertEquals("8", metadata.get(Database.COLUMN_COUNT)); assertEquals("11", metadata.get(Database.ROW_COUNT)); assertEquals("windows-1252", metadata.get(HttpHeaders.CONTENT_ENCODING)); assertEquals("X64_7PRO", metadata.get(OfficeOpenXMLExtended.APPLICATION)); assertEquals("9.0401M5", metadata.get(OfficeOpenXMLExtended.APP_VERSION)); assertEquals("32", metadata.get(MachineMetadata.ARCHITECTURE_BITS)); assertEquals("Little", metadata.get(MachineMetadata.ENDIAN)); assertEquals(Arrays.asList("Record Number","Square of the Record Number", "Description of the Row","Percent Done", "Percent Increment","date","datetime","time"), Arrays.asList(metadata.getValues(Database.COLUMN_NAME))); String content = handler.toString(); assertContains("TESTING", content); assertContains("0\t0\tThis", content); assertContains("2\t4\tThis", content); assertContains("4\t16\tThis", content); assertContains("\t01-01-1960\t", content); assertContains("\t01"+SHORT_MONTHS[0]+"1960:00:00", content); }
@Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { metadata.set(Metadata.CONTENT_TYPE, TYPE_SAS7BDAT.toString()); XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); SasFileReader sas = new SasFileReaderImpl(stream); SasFileProperties props = sas.getSasFileProperties(); metadata.set(TikaCoreProperties.TITLE, props.getName()); metadata.set(TikaCoreProperties.CREATED, props.getDateCreated()); metadata.set(TikaCoreProperties.MODIFIED, props.getDateModified()); metadata.set(PagedText.N_PAGES, (int)props.getPageCount()); metadata.set(Database.COLUMN_COUNT, (int)props.getColumnsCount()); metadata.set(Database.ROW_COUNT, (int)props.getRowCount()); metadata.set(HttpHeaders.CONTENT_ENCODING, props.getEncoding()); metadata.set(OfficeOpenXMLExtended.APPLICATION, props.getServerType()); metadata.set(OfficeOpenXMLExtended.APP_VERSION, props.getSasRelease()); metadata.set(MachineMetadata.ARCHITECTURE_BITS, props.isU64() ? "64" : "32"); metadata.set(MachineMetadata.ENDIAN, props.getEndianness() == 1 ? MachineMetadata.Endian.LITTLE.getName() : MachineMetadata.Endian.BIG.getName()); for (Column c : sas.getColumns()) { String name = c.getLabel(); if (name == null || name.isEmpty()) name = c.getName(); metadata.add(Database.COLUMN_NAME, name); } xhtml.element("h1", props.getName()); xhtml.startElement("table"); xhtml.newline(); xhtml.startElement("tr"); for (Column c : sas.getColumns()) { String label = c.getLabel(); if (label == null || label.isEmpty()) label = c.getName(); xhtml.startElement("th", "title", c.getName()); xhtml.characters(label); xhtml.endElement("th"); } xhtml.endElement("tr"); xhtml.newline(); Map<Integer, Format> formatMap = new HashMap<>(); Object[] row = null; while ((row = sas.readNext()) != null) { xhtml.startElement("tr"); for (String val : DataWriterUtil.getRowValues(sas.getColumns(), row, formatMap)) { xhtml.startElement("td"); xhtml.characters(val); xhtml.endElement("td"); } xhtml.endElement("tr"); xhtml.newline(); } xhtml.endElement("table"); xhtml.endDocument(); }
SAS7BDATParser extends AbstractParser { @Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { metadata.set(Metadata.CONTENT_TYPE, TYPE_SAS7BDAT.toString()); XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); SasFileReader sas = new SasFileReaderImpl(stream); SasFileProperties props = sas.getSasFileProperties(); metadata.set(TikaCoreProperties.TITLE, props.getName()); metadata.set(TikaCoreProperties.CREATED, props.getDateCreated()); metadata.set(TikaCoreProperties.MODIFIED, props.getDateModified()); metadata.set(PagedText.N_PAGES, (int)props.getPageCount()); metadata.set(Database.COLUMN_COUNT, (int)props.getColumnsCount()); metadata.set(Database.ROW_COUNT, (int)props.getRowCount()); metadata.set(HttpHeaders.CONTENT_ENCODING, props.getEncoding()); metadata.set(OfficeOpenXMLExtended.APPLICATION, props.getServerType()); metadata.set(OfficeOpenXMLExtended.APP_VERSION, props.getSasRelease()); metadata.set(MachineMetadata.ARCHITECTURE_BITS, props.isU64() ? "64" : "32"); metadata.set(MachineMetadata.ENDIAN, props.getEndianness() == 1 ? MachineMetadata.Endian.LITTLE.getName() : MachineMetadata.Endian.BIG.getName()); for (Column c : sas.getColumns()) { String name = c.getLabel(); if (name == null || name.isEmpty()) name = c.getName(); metadata.add(Database.COLUMN_NAME, name); } xhtml.element("h1", props.getName()); xhtml.startElement("table"); xhtml.newline(); xhtml.startElement("tr"); for (Column c : sas.getColumns()) { String label = c.getLabel(); if (label == null || label.isEmpty()) label = c.getName(); xhtml.startElement("th", "title", c.getName()); xhtml.characters(label); xhtml.endElement("th"); } xhtml.endElement("tr"); xhtml.newline(); Map<Integer, Format> formatMap = new HashMap<>(); Object[] row = null; while ((row = sas.readNext()) != null) { xhtml.startElement("tr"); for (String val : DataWriterUtil.getRowValues(sas.getColumns(), row, formatMap)) { xhtml.startElement("td"); xhtml.characters(val); xhtml.endElement("td"); } xhtml.endElement("tr"); xhtml.newline(); } xhtml.endElement("table"); xhtml.endDocument(); } }
SAS7BDATParser extends AbstractParser { @Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { metadata.set(Metadata.CONTENT_TYPE, TYPE_SAS7BDAT.toString()); XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); SasFileReader sas = new SasFileReaderImpl(stream); SasFileProperties props = sas.getSasFileProperties(); metadata.set(TikaCoreProperties.TITLE, props.getName()); metadata.set(TikaCoreProperties.CREATED, props.getDateCreated()); metadata.set(TikaCoreProperties.MODIFIED, props.getDateModified()); metadata.set(PagedText.N_PAGES, (int)props.getPageCount()); metadata.set(Database.COLUMN_COUNT, (int)props.getColumnsCount()); metadata.set(Database.ROW_COUNT, (int)props.getRowCount()); metadata.set(HttpHeaders.CONTENT_ENCODING, props.getEncoding()); metadata.set(OfficeOpenXMLExtended.APPLICATION, props.getServerType()); metadata.set(OfficeOpenXMLExtended.APP_VERSION, props.getSasRelease()); metadata.set(MachineMetadata.ARCHITECTURE_BITS, props.isU64() ? "64" : "32"); metadata.set(MachineMetadata.ENDIAN, props.getEndianness() == 1 ? MachineMetadata.Endian.LITTLE.getName() : MachineMetadata.Endian.BIG.getName()); for (Column c : sas.getColumns()) { String name = c.getLabel(); if (name == null || name.isEmpty()) name = c.getName(); metadata.add(Database.COLUMN_NAME, name); } xhtml.element("h1", props.getName()); xhtml.startElement("table"); xhtml.newline(); xhtml.startElement("tr"); for (Column c : sas.getColumns()) { String label = c.getLabel(); if (label == null || label.isEmpty()) label = c.getName(); xhtml.startElement("th", "title", c.getName()); xhtml.characters(label); xhtml.endElement("th"); } xhtml.endElement("tr"); xhtml.newline(); Map<Integer, Format> formatMap = new HashMap<>(); Object[] row = null; while ((row = sas.readNext()) != null) { xhtml.startElement("tr"); for (String val : DataWriterUtil.getRowValues(sas.getColumns(), row, formatMap)) { xhtml.startElement("td"); xhtml.characters(val); xhtml.endElement("td"); } xhtml.endElement("tr"); xhtml.newline(); } xhtml.endElement("table"); xhtml.endDocument(); }  }
SAS7BDATParser extends AbstractParser { @Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { metadata.set(Metadata.CONTENT_TYPE, TYPE_SAS7BDAT.toString()); XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); SasFileReader sas = new SasFileReaderImpl(stream); SasFileProperties props = sas.getSasFileProperties(); metadata.set(TikaCoreProperties.TITLE, props.getName()); metadata.set(TikaCoreProperties.CREATED, props.getDateCreated()); metadata.set(TikaCoreProperties.MODIFIED, props.getDateModified()); metadata.set(PagedText.N_PAGES, (int)props.getPageCount()); metadata.set(Database.COLUMN_COUNT, (int)props.getColumnsCount()); metadata.set(Database.ROW_COUNT, (int)props.getRowCount()); metadata.set(HttpHeaders.CONTENT_ENCODING, props.getEncoding()); metadata.set(OfficeOpenXMLExtended.APPLICATION, props.getServerType()); metadata.set(OfficeOpenXMLExtended.APP_VERSION, props.getSasRelease()); metadata.set(MachineMetadata.ARCHITECTURE_BITS, props.isU64() ? "64" : "32"); metadata.set(MachineMetadata.ENDIAN, props.getEndianness() == 1 ? MachineMetadata.Endian.LITTLE.getName() : MachineMetadata.Endian.BIG.getName()); for (Column c : sas.getColumns()) { String name = c.getLabel(); if (name == null || name.isEmpty()) name = c.getName(); metadata.add(Database.COLUMN_NAME, name); } xhtml.element("h1", props.getName()); xhtml.startElement("table"); xhtml.newline(); xhtml.startElement("tr"); for (Column c : sas.getColumns()) { String label = c.getLabel(); if (label == null || label.isEmpty()) label = c.getName(); xhtml.startElement("th", "title", c.getName()); xhtml.characters(label); xhtml.endElement("th"); } xhtml.endElement("tr"); xhtml.newline(); Map<Integer, Format> formatMap = new HashMap<>(); Object[] row = null; while ((row = sas.readNext()) != null) { xhtml.startElement("tr"); for (String val : DataWriterUtil.getRowValues(sas.getColumns(), row, formatMap)) { xhtml.startElement("td"); xhtml.characters(val); xhtml.endElement("td"); } xhtml.endElement("tr"); xhtml.newline(); } xhtml.endElement("table"); xhtml.endDocument(); }  @Override Set<MediaType> getSupportedTypes(ParseContext context); @Override void parse(InputStream stream, ContentHandler handler,
            Metadata metadata, ParseContext context); }
SAS7BDATParser extends AbstractParser { @Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { metadata.set(Metadata.CONTENT_TYPE, TYPE_SAS7BDAT.toString()); XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); SasFileReader sas = new SasFileReaderImpl(stream); SasFileProperties props = sas.getSasFileProperties(); metadata.set(TikaCoreProperties.TITLE, props.getName()); metadata.set(TikaCoreProperties.CREATED, props.getDateCreated()); metadata.set(TikaCoreProperties.MODIFIED, props.getDateModified()); metadata.set(PagedText.N_PAGES, (int)props.getPageCount()); metadata.set(Database.COLUMN_COUNT, (int)props.getColumnsCount()); metadata.set(Database.ROW_COUNT, (int)props.getRowCount()); metadata.set(HttpHeaders.CONTENT_ENCODING, props.getEncoding()); metadata.set(OfficeOpenXMLExtended.APPLICATION, props.getServerType()); metadata.set(OfficeOpenXMLExtended.APP_VERSION, props.getSasRelease()); metadata.set(MachineMetadata.ARCHITECTURE_BITS, props.isU64() ? "64" : "32"); metadata.set(MachineMetadata.ENDIAN, props.getEndianness() == 1 ? MachineMetadata.Endian.LITTLE.getName() : MachineMetadata.Endian.BIG.getName()); for (Column c : sas.getColumns()) { String name = c.getLabel(); if (name == null || name.isEmpty()) name = c.getName(); metadata.add(Database.COLUMN_NAME, name); } xhtml.element("h1", props.getName()); xhtml.startElement("table"); xhtml.newline(); xhtml.startElement("tr"); for (Column c : sas.getColumns()) { String label = c.getLabel(); if (label == null || label.isEmpty()) label = c.getName(); xhtml.startElement("th", "title", c.getName()); xhtml.characters(label); xhtml.endElement("th"); } xhtml.endElement("tr"); xhtml.newline(); Map<Integer, Format> formatMap = new HashMap<>(); Object[] row = null; while ((row = sas.readNext()) != null) { xhtml.startElement("tr"); for (String val : DataWriterUtil.getRowValues(sas.getColumns(), row, formatMap)) { xhtml.startElement("td"); xhtml.characters(val); xhtml.endElement("td"); } xhtml.endElement("tr"); xhtml.newline(); } xhtml.endElement("table"); xhtml.endDocument(); }  @Override Set<MediaType> getSupportedTypes(ParseContext context); @Override void parse(InputStream stream, ContentHandler handler,
            Metadata metadata, ParseContext context);  }