@Override public InputStream getBinaryStream() throws SQLException { try { return new XMLInputStream(getSource(StAXSource.class), XMLOutputFactory.newFactory(), getCharset().name()); } catch (XMLStreamException e) { throw new SQLException(e); } catch (FactoryConfigurationError e) { throw new SQLException(e); } }
@Test public void testUTF16Streaming() throws Exception { StringBuilder xmlBuilder = new StringBuilder(); xmlBuilder.append("<root>"); for (int i = 0; i < 1000; i++) { xmlBuilder.append("<a></a>"); xmlBuilder.append("<b></b>"); } xmlBuilder.append("</root>"); String xml = xmlBuilder.toString(); StAXSource source = new StAXSource(XMLType.getXmlInputFactory().createXMLEventReader(new StringReader(xml))); XMLInputStream is = new XMLInputStream(source, XMLOutputFactory.newFactory(), "UTF-16"); byte[] bytes = ObjectConverterUtil.convertToByteArray(is); String string = new String(bytes, "UTF-16"); assertTrue(string, string.startsWith("<?xml version=\"1.0\"")); //omit document declaration assertEquals(xml, string.substring(string.indexOf("><") + 1)); }
@Test public void testStreaming() throws Exception { StringBuilder xmlBuilder = new StringBuilder(); xmlBuilder.append("<root>"); for (int i = 0; i < 1000; i++) { xmlBuilder.append("<a></a>"); xmlBuilder.append("<b></b>"); } xmlBuilder.append("</root>"); String xml = xmlBuilder.toString(); StAXSource source = new StAXSource(XMLType.getXmlInputFactory().createXMLEventReader(new StringReader(xml))); XMLInputStream is = new XMLInputStream(source, XMLOutputFactory.newFactory()); byte[] bytes = ObjectConverterUtil.convertToByteArray(is); String string = new String(bytes, "UTF-8"); assertTrue(string, string.startsWith("<?xml version=\"1.0\"")); //omit document declaration assertEquals(xml, string.substring(string.indexOf("><") + 1)); }
final FileStore fs = bm.createFileStore("xml"); //$NON-NLS-1$ final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); value = new SaveOnReadInputStream(new XMLInputStream(ss, XMLSystemFunctions.getOutputFactory(true)), fsisf).getInputStreamFactory(); if (context != null) { context.addCreatedLob(fsisf);
final FileStore fs = bm.createFileStore("xml"); //$NON-NLS-1$ final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); value = new SaveOnReadInputStream(new XMLInputStream(ss, XMLSystemFunctions.getOutputFactory(true)), fsisf).getInputStreamFactory(); if (context != null) { context.addCreatedLob(fsisf);
final FileStore fs = bm.createFileStore("xml"); //$NON-NLS-1$ final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); value = new SaveOnReadInputStream(new XMLInputStream(ss, XMLSystemFunctions.getOutputFactory(true)), fsisf).getInputStreamFactory(); if (context != null) { context.addCreatedLob(fsisf);