@SuppressWarnings("unchecked") public <T extends Source> T getSource(Class<T> sourceClass) throws SQLException { if (sourceClass == null || sourceClass == StreamSource.class) { return (T)new StreamSource(getBinaryStream(), this.getStreamFactory().getSystemId()); } else if (sourceClass == StAXSource.class) { XMLInputFactory factory = XMLType.getXmlInputFactory(); try { return (T) new StAXSource(factory.createXMLStreamReader(getBinaryStream())); } catch (XMLStreamException e) { throw new SQLException(e); return (T) new SAXSource(new InputSource(getBinaryStream())); } else if (sourceClass == DOMSource.class) { try { Node doc = docBuilder.parse(new InputSource(getBinaryStream())); return (T) new DOMSource(doc); } catch (ParserConfigurationException e) {
@SuppressWarnings("unchecked") public <T extends Source> T getSource(Class<T> sourceClass) throws SQLException { if (sourceClass == null || sourceClass == StreamSource.class) { return (T)new StreamSource(getBinaryStream(), this.getStreamFactory().getSystemId()); } else if (sourceClass == StAXSource.class) { XMLInputFactory factory = XMLType.getXmlInputFactory(); try { return (T) new StAXSource(factory.createXMLStreamReader(getBinaryStream())); } catch (XMLStreamException e) { throw new SQLException(e); return (T) new SAXSource(new InputSource(getBinaryStream())); } else if (sourceClass == DOMSource.class) { try { Node doc = docBuilder.parse(new InputSource(getBinaryStream())); return (T) new DOMSource(doc); } catch (ParserConfigurationException e) {
try { if (obj instanceof SQLXMLImpl) { streams.add(((SQLXMLImpl)obj).getBinaryStream()); StreamFactoryReference sfr = new SQLXMLImpl(); references.add(sfr);
try { if (obj instanceof SQLXMLImpl) { streams.add(((SQLXMLImpl)obj).getBinaryStream()); StreamFactoryReference sfr = new SQLXMLImpl(); references.add(sfr);
@Override public Charset getCharset() { Charset cs = super.getCharset(); if (cs != null) { return cs; } String enc = null; try { enc = XMLType.getEncoding(this.getBinaryStream()); } catch (SQLException e) { } if (enc != null) { setEncoding(enc); } else { super.setCharset(Streamable.CHARSET); } return super.getCharset(); }
@Override public Charset getCharset() { Charset cs = super.getCharset(); if (cs != null) { return cs; } String enc = null; try { enc = XMLType.getEncoding(this.getBinaryStream()); } catch (SQLException e) { } if (enc != null) { setEncoding(enc); } else { super.setCharset(Streamable.CHARSET); } return super.getCharset(); }
@Test public void testGetBinaryStream() throws Exception { SQLXMLImpl xml = new SQLXMLImpl(testStr); assertEquals(testStr, new String(ObjectConverterUtil.convertToByteArray(xml.getBinaryStream()), Streamable.ENCODING)); }