public static GeometryType geometryFromGml(ClobType gml, Integer srid) throws FunctionExecutionException { try { return geometryFromGml(gml.getCharacterStream(), srid); } catch (SQLException e) { throw new FunctionExecutionException(e); } }
public static GeometryType geometryFromGml(ClobType gml, Integer srid) throws FunctionExecutionException { try { Geometry geom = geometryFromGml(gml.getCharacterStream(), srid); return getGeometryType(geom); } catch (SQLException e) { throw new FunctionExecutionException(e); } }
public static GeometryType geometryFromGml(ClobType gml, Integer srid) throws FunctionExecutionException { try { Geometry geom = geometryFromGml(gml.getCharacterStream(), srid); return getGeometryType(geom); } catch (SQLException e) { throw new FunctionExecutionException(e); } }
@TeiidFunction(category=FunctionCategoryConstants.CONVERSION, name="to_bytes") public static BlobType toBytes(ClobType value, String encoding, boolean wellFormed) throws IOException, SQLException { Charset cs = CharsetUtils.getCharset(encoding); ClobInputStreamFactory cisf = new ClobInputStreamFactory(value.getReference()); cisf.setCharset(cs); if (!wellFormed || CharsetUtils.BASE64_NAME.equalsIgnoreCase(encoding) || CharsetUtils.HEX_NAME.equalsIgnoreCase(encoding)) { //validate that the binary conversion is possible //TODO: cache the result in a filestore InputStream is = new ReaderInputStream(value.getCharacterStream(), cs.newEncoder().onMalformedInput(CodingErrorAction.REPORT) .onUnmappableCharacter(CodingErrorAction.REPORT)); try { while (is.read() != -1) { } } catch (IOException e) { CharacterCodingException cce = ExceptionUtil.getExceptionOfType(e, CharacterCodingException.class); if (cce != null) { throw new IOException(CorePlugin.Util.gs(CorePlugin.Event.TEIID10083, cs.displayName()), cce); } throw e; } finally { is.close(); } } return new BlobType(new BlobImpl(cisf)); }
@TeiidFunction(category=FunctionCategoryConstants.CONVERSION, name="to_bytes") public static BlobType toBytes(ClobType value, String encoding, boolean wellFormed) throws IOException, SQLException { Charset cs = getCharset(encoding); ClobInputStreamFactory cisf = new ClobInputStreamFactory(value.getReference()); cisf.setCharset(cs); if (!wellFormed || CharsetUtils.BASE64_NAME.equalsIgnoreCase(encoding) || CharsetUtils.HEX_NAME.equalsIgnoreCase(encoding)) { //validate that the binary conversion is possible //TODO: cache the result in a filestore InputStream is = new ReaderInputStream(value.getCharacterStream(), cs.newEncoder().onMalformedInput(CodingErrorAction.REPORT) .onUnmappableCharacter(CodingErrorAction.REPORT)); try { while (is.read() != -1) { } } catch (IOException e) { CharacterCodingException cce = ExceptionUtil.getExceptionOfType(e, CharacterCodingException.class); if (cce != null) { throw new IOException(CorePlugin.Util.gs(CorePlugin.Event.TEIID10083, cs.displayName()), cce); } throw e; } finally { is.close(); } } return new BlobType(new BlobImpl(cisf)); }
@TeiidFunction(category=FunctionCategoryConstants.CONVERSION, name="to_bytes") public static BlobType toBytes(ClobType value, String encoding, boolean wellFormed) throws IOException, SQLException { Charset cs = CharsetUtils.getCharset(encoding); ClobInputStreamFactory cisf = new ClobInputStreamFactory(value.getReference()); cisf.setCharset(cs); if (!wellFormed || CharsetUtils.BASE64_NAME.equalsIgnoreCase(encoding) || CharsetUtils.HEX_NAME.equalsIgnoreCase(encoding)) { //validate that the binary conversion is possible //TODO: cache the result in a filestore InputStream is = new ReaderInputStream(value.getCharacterStream(), cs.newEncoder().onMalformedInput(CodingErrorAction.REPORT) .onUnmappableCharacter(CodingErrorAction.REPORT)); try { while (is.read() != -1) { } } catch (IOException e) { CharacterCodingException cce = ExceptionUtil.getExceptionOfType(e, CharacterCodingException.class); if (cce != null) { throw new IOException(CorePlugin.Util.gs(CorePlugin.Event.TEIID10083, cs.displayName()), cce); } throw e; } finally { is.close(); } } return new BlobType(new BlobImpl(cisf)); }
ClobType clob = (ClobType)object; if (clob.getType() == Type.JSON) { Reader r = clob.getCharacterStream(); try { ObjectConverterUtil.write(writer, r, -1, false);
public static ClobType concat(CommandContext context, ClobType str1, ClobType str2) throws IOException, SQLException { BufferManager bm = context.getBufferManager(); FileStore fs = bm.createFileStore("clob"); //$NON-NLS-1$ FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); boolean remove = true; try (Reader characterStream = str1.getCharacterStream(); Reader characterStream2 = str2.getCharacterStream();){ Writer writer = fsisf.getWriter(); int chars = ObjectConverterUtil.write(writer, characterStream, -1, false); chars += ObjectConverterUtil.write(writer, characterStream2, -1, false); writer.close(); if (fsisf.getStorageMode() == StorageMode.MEMORY) { //detach if just in memory byte[] bytes = fsisf.getMemoryBytes(); return new ClobType(new ClobImpl(new String(bytes, Streamable.ENCODING))); } remove = false; context.addCreatedLob(fsisf); return new ClobType(new ClobImpl(fsisf, chars)); } finally { if (remove) { fs.remove(); } } }
public static ClobType concat(CommandContext context, ClobType str1, ClobType str2) throws IOException, SQLException { BufferManager bm = context.getBufferManager(); FileStore fs = bm.createFileStore("clob"); //$NON-NLS-1$ FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); boolean remove = true; try (Reader characterStream = str1.getCharacterStream(); Reader characterStream2 = str2.getCharacterStream();){ Writer writer = fsisf.getWriter(); int chars = ObjectConverterUtil.write(writer, characterStream, -1, false); chars += ObjectConverterUtil.write(writer, characterStream2, -1, false); writer.close(); if (fsisf.getStorageMode() == StorageMode.MEMORY) { //detach if just in memory byte[] bytes = fsisf.getMemoryBytes(); return new ClobType(new ClobImpl(new String(bytes, Streamable.ENCODING))); } remove = false; context.addCreatedLob(fsisf); return new ClobType(new ClobImpl(fsisf, chars)); } finally { if (remove) { fs.remove(); } } }
public static ClobType concat(CommandContext context, ClobType str1, ClobType str2) throws IOException, SQLException { BufferManager bm = context.getBufferManager(); FileStore fs = bm.createFileStore("clob"); //$NON-NLS-1$ FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); boolean remove = true; try (Reader characterStream = str1.getCharacterStream(); Reader characterStream2 = str2.getCharacterStream();){ Writer writer = fsisf.getWriter(); int chars = ObjectConverterUtil.write(writer, characterStream, -1, false); chars += ObjectConverterUtil.write(writer, characterStream2, -1, false); writer.close(); if (fsisf.getStorageMode() == StorageMode.MEMORY) { //detach if just in memory byte[] bytes = fsisf.getMemoryBytes(); return new ClobType(new ClobImpl(new String(bytes, Streamable.ENCODING))); } remove = false; context.addCreatedLob(fsisf); return new ClobType(new ClobImpl(fsisf, chars)); } finally { if (remove) { fs.remove(); } } }
@TeiidFunction(category=FunctionCategoryConstants.JSON) public static ClobType jsonParse(ClobType val, boolean wellformed) throws SQLException, IOException, ParseException { Reader r = null; if (val.getType() == Type.JSON) { return val; } if (!wellformed) { r = val.getCharacterStream(); } try { if (!wellformed) { JSONParser parser = new JSONParser(); parser.parse(r, validatingContentHandler); } ClobType ct = new ClobType(val.getReference()); ct.setType(Type.JSON); return ct; } finally { if (r != null) { r.close(); } } }
@TeiidFunction(category=FunctionCategoryConstants.JSON) public static JsonType jsonParse(ClobType val, boolean wellformed) throws SQLException, IOException, ParseException { Reader r = null; if (val.getType() == Type.JSON) { return new JsonType(val.getReference()); } if (!wellformed) { r = val.getCharacterStream(); } try { if (!wellformed) { JSONParser parser = new JSONParser(); parser.parse(r, validatingContentHandler); } return new JsonType(val.getReference()); } finally { if (r != null) { r.close(); } } }
@TeiidFunction(category=FunctionCategoryConstants.JSON) public static JsonType jsonParse(ClobType val, boolean wellformed) throws SQLException, IOException, ParseException { Reader r = null; if (val.getType() == Type.JSON) { return new JsonType(val.getReference()); } if (!wellformed) { r = val.getCharacterStream(); } try { if (!wellformed) { JSONParser parser = new JSONParser(); parser.parse(r, validatingContentHandler); } return new JsonType(val.getReference()); } finally { if (r != null) { r.close(); } } }
/** * Create a object which can create a sequence of LobChunk objects on a given * LOB object * @throws SQLException */ private ByteLobChunkStream createLobStream(String referenceStreamId) throws TeiidComponentException, SQLException { // get the reference object in the buffer manager, and try to stream off // the original sources. Streamable<?> streamable = parent.resultsBuffer.getLobReference(referenceStreamId); if (streamable instanceof XMLType) { XMLType xml = (XMLType)streamable; return new ByteLobChunkStream(xml.getBinaryStream(), chunkSize); } else if (streamable instanceof ClobType) { ClobType clob = (ClobType)streamable; return new ByteLobChunkStream(new ReaderInputStream(clob.getCharacterStream(), Charset.forName(Streamable.ENCODING)), chunkSize); } BlobType blob = (BlobType)streamable; return new ByteLobChunkStream(blob.getBinaryStream(), chunkSize); }
r = clob.getCharacterStream(); convertReader(writer, eventWriter, r, Type.TEXT, null); } else if (object instanceof BlobType) { r = clob.getCharacterStream(); convertReader(writer, eventWriter, r, Type.TEXT, null); } else if (object instanceof BinaryType) { BinaryType binary = (BinaryType)object; ClobType clob = FunctionMethods.toChars(new BlobType(binary.getBytesDirect()), CharsetUtils.BASE64_NAME, true); r = clob.getCharacterStream(); convertReader(writer, eventWriter, r, Type.TEXT, null); } else {
Reader r = file.getCharacterStream(); if (!(r instanceof BufferedReader)) { reader = new BufferedReader(r);
Reader r = file.getCharacterStream(); if (!(r instanceof BufferedReader)) { reader = new BufferedReader(r);
Reader r = file.getCharacterStream(); if (!(r instanceof BufferedReader)) { reader = new BufferedReader(r);
@Test public void testInvokeXslTransform() throws Exception { CommandContext c = new CommandContext(); c.setBufferManager(BufferManagerFactory.getStandaloneBufferManager()); ClobType result = (ClobType)helpInvokeMethod("xsltransform", new Class<?>[] {DataTypeManager.DefaultDataClasses.XML, DataTypeManager.DefaultDataClasses.XML}, new Object[] {DataTypeManager.transformValue("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name><Quantity>5</Quantity></Item></Items></Catalog></Catalogs>", DataTypeManager.DefaultDataClasses.XML), DataTypeManager.transformValue("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:template match=\"@*|node()\"><xsl:copy><xsl:apply-templates select=\"@*|node()\"/></xsl:copy></xsl:template><xsl:template match=\"Quantity\"/></xsl:stylesheet>", DataTypeManager.DefaultDataClasses.XML)}, c); String xml = ObjectConverterUtil.convertToString(result.getCharacterStream()); assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name></Item></Items></Catalog></Catalogs>", xml); }
@Test public void testClobConcat() throws Exception { CommandContext c = new CommandContext(); c.setBufferManager(BufferManagerFactory.getStandaloneBufferManager()); ClobType result = (ClobType)helpInvokeMethod("concat", new Class<?>[] {DataTypeManager.DefaultDataClasses.CLOB, DataTypeManager.DefaultDataClasses.CLOB}, new Object[] {DataTypeManager.transformValue("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name><Quantity>5</Quantity></Item></Items></Catalog></Catalogs>", DataTypeManager.DefaultDataClasses.CLOB), DataTypeManager.transformValue("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:template match=\"@*|node()\"><xsl:copy><xsl:apply-templates select=\"@*|node()\"/></xsl:copy></xsl:template><xsl:template match=\"Quantity\"/></xsl:stylesheet>", DataTypeManager.DefaultDataClasses.CLOB)}, c); String xml = ObjectConverterUtil.convertToString(result.getCharacterStream()); assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\">" + "<Name>Lamp</Name><Quantity>5</Quantity></Item></Items></Catalog></Catalogs><?xml version=\"1.0\" encoding=\"UTF-8\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" + "<xsl:template match=\"@*|node()\"><xsl:copy><xsl:apply-templates select=\"@*|node()\"/></xsl:copy></xsl:template><xsl:template match=\"Quantity\"/></xsl:stylesheet>", xml); }