@TeiidFunction(category=FunctionCategoryConstants.CONVERSION, name="to_chars") public static ClobType toChars(BlobType value, String encoding, boolean wellFormed) throws SQLException, IOException { Charset cs = CharsetUtils.getCharset(encoding); BlobInputStreamFactory bisf = new BlobInputStreamFactory(value.getReference()); ClobImpl clob = new ClobImpl(bisf, -1); clob.setCharset(cs); if (!wellFormed && !CharsetUtils.BASE64_NAME.equalsIgnoreCase(encoding) && !CharsetUtils.HEX_NAME.equalsIgnoreCase(encoding)) { //validate that the charcter conversion is possible //TODO: cache the result in a filestore Reader r = clob.getCharacterStream(); try { while (r.read() != -1) { } } catch (IOException e) { CharacterCodingException cce = ExceptionUtil.getExceptionOfType(e, CharacterCodingException.class); if (cce != null) { throw new IOException(CorePlugin.Util.gs(CorePlugin.Event.TEIID10082, cs.displayName()), cce); } throw e; } finally { r.close(); } } return new ClobType(clob); }
is = new BlobInputStreamFactory((Blob)lob).getInputStream(); } else if (lob instanceof BaseClobType) { is = new ClobInputStreamFactory((Clob)lob).getInputStream();
is = new BlobInputStreamFactory((Blob)lob).getInputStream(); } else if (lob instanceof BaseClobType) { is = new ClobInputStreamFactory((Clob)lob).getInputStream();
is = new BlobInputStreamFactory((Blob)lob).getInputStream(); } else if (lob instanceof ClobType) { is = new ClobInputStreamFactory((Clob)lob).getInputStream();
@TeiidFunction(category=FunctionCategoryConstants.CONVERSION, name="to_chars") public static ClobType toChars(BlobType value, String encoding, boolean wellFormed) throws SQLException, IOException { Charset cs = getCharset(encoding); BlobInputStreamFactory bisf = new BlobInputStreamFactory(value.getReference()); ClobImpl clob = new ClobImpl(bisf, -1); clob.setCharset(cs); if (!wellFormed && !CharsetUtils.BASE64_NAME.equalsIgnoreCase(encoding) && !CharsetUtils.HEX_NAME.equalsIgnoreCase(encoding)) { //validate that the charcter conversion is possible //TODO: cache the result in a filestore Reader r = clob.getCharacterStream(); try { while (r.read() != -1) { } } catch (IOException e) { CharacterCodingException cce = ExceptionUtil.getExceptionOfType(e, CharacterCodingException.class); if (cce != null) { throw new IOException(CorePlugin.Util.gs(CorePlugin.Event.TEIID10082, cs.displayName()), cce); } throw e; } finally { r.close(); } } return new ClobType(clob); }
@TeiidFunction(category=FunctionCategoryConstants.CONVERSION, name="to_chars") public static ClobType toChars(BlobType value, String encoding, boolean wellFormed) throws SQLException, IOException { Charset cs = CharsetUtils.getCharset(encoding); BlobInputStreamFactory bisf = new BlobInputStreamFactory(value.getReference()); ClobImpl clob = new ClobImpl(bisf, -1); clob.setCharset(cs); if (!wellFormed && !CharsetUtils.BASE64_NAME.equalsIgnoreCase(encoding) && !CharsetUtils.HEX_NAME.equalsIgnoreCase(encoding)) { //validate that the charcter conversion is possible //TODO: cache the result in a filestore Reader r = clob.getCharacterStream(); try { while (r.read() != -1) { } } catch (IOException e) { CharacterCodingException cce = ExceptionUtil.getExceptionOfType(e, CharacterCodingException.class); if (cce != null) { throw new IOException(CorePlugin.Util.gs(CorePlugin.Event.TEIID10082, cs.displayName()), cce); } throw e; } finally { r.close(); } } return new ClobType(clob); }
public static InputStreamFactory getInputStreamFactory(Streamable<?> s) { if (s.getReference() instanceof Streamable<?>) { return getInputStreamFactory((Streamable<?>) s.getReference()); } if (s.getReference() instanceof BaseLob) { BaseLob bl = (BaseLob) s.getReference(); try { InputStreamFactory isf = bl.getStreamFactory(); if (isf != null) { return isf; } } catch (SQLException e) { } } if (s instanceof BaseClobType) { return new InputStreamFactory.ClobInputStreamFactory((Clob)s.getReference()); } else if (s instanceof BlobType){ return new InputStreamFactory.BlobInputStreamFactory((Blob)s.getReference()); } return new InputStreamFactory.SQLXMLInputStreamFactory((SQLXML)s.getReference()); }
public static InputStreamFactory getInputStreamFactory(Streamable<?> s) { if (s.getReference() instanceof Streamable<?>) { return getInputStreamFactory((Streamable<?>) s.getReference()); } if (s.getReference() instanceof BaseLob) { BaseLob bl = (BaseLob) s.getReference(); try { InputStreamFactory isf = bl.getStreamFactory(); if (isf != null) { return isf; } } catch (SQLException e) { } } if (s instanceof ClobType) { return new InputStreamFactory.ClobInputStreamFactory((Clob)s.getReference()); } else if (s instanceof BlobType){ return new InputStreamFactory.BlobInputStreamFactory((Blob)s.getReference()); } return new InputStreamFactory.SQLXMLInputStreamFactory((SQLXML)s.getReference()); }
public static InputStreamFactory getInputStreamFactory(Streamable<?> s) { if (s.getReference() instanceof Streamable<?>) { return getInputStreamFactory((Streamable<?>) s.getReference()); } if (s.getReference() instanceof BaseLob) { BaseLob bl = (BaseLob) s.getReference(); try { InputStreamFactory isf = bl.getStreamFactory(); if (isf != null) { return isf; } } catch (SQLException e) { } } if (s instanceof BaseClobType) { return new InputStreamFactory.ClobInputStreamFactory((Clob)s.getReference()); } else if (s instanceof BlobType){ return new InputStreamFactory.BlobInputStreamFactory((Blob)s.getReference()); } return new InputStreamFactory.SQLXMLInputStreamFactory((SQLXML)s.getReference()); }
@Test public void testTypeConversion() throws Exception { BufferManager bm = BufferManagerFactory.getStandaloneBufferManager(); String str = "hello world"; Object source = new StreamSource(new StringReader(str)); XMLType xml = (XMLType) ConnectorWorkItem.convertToRuntimeType(bm, source, DataTypeManager.DefaultDataClasses.XML, null); assertEquals(str, xml.getString()); source = new StAXSource(XMLType.getXmlInputFactory().createXMLEventReader(new StringReader("<a/>"))); xml = (XMLType) ConnectorWorkItem.convertToRuntimeType(bm, source, DataTypeManager.DefaultDataClasses.XML, null); XMLInputFactory in = XMLType.getXmlInputFactory(); XMLStreamReader reader = in.createXMLStreamReader(new StringReader(xml.getString())); assertEquals(XMLEvent.START_DOCUMENT, reader.getEventType()); assertEquals(XMLEvent.START_ELEMENT, reader.next()); assertEquals("a", reader.getLocalName()); assertEquals(XMLEvent.END_ELEMENT, reader.next()); byte[] bytes = str.getBytes(Streamable.ENCODING); source = new InputStreamFactory.BlobInputStreamFactory(BlobType.createBlob(bytes)); BlobType blob = (BlobType) ConnectorWorkItem.convertToRuntimeType(bm, source, DataTypeManager.DefaultDataClasses.BLOB, null); assertArrayEquals(bytes, ObjectConverterUtil.convertToByteArray(blob.getBinaryStream())); }
@TeiidFunction(category=FunctionCategoryConstants.JSON) public static ClobType jsonParse(BlobType val, boolean wellformed) throws SQLException, IOException, ParseException { InputStreamReader r = XMLSystemFunctions.getJsonReader(val); try { if (!wellformed) { JSONParser parser = new JSONParser(); parser.parse(r, validatingContentHandler); } ClobImpl clobImpl = new ClobImpl(); clobImpl.setStreamFactory(new InputStreamFactory.BlobInputStreamFactory(val.getReference())); clobImpl.setEncoding(r.getEncoding()); ClobType ct = new ClobType(clobImpl); ct.setType(Type.JSON); return ct; } finally { r.close(); } }
@TeiidFunction(category=FunctionCategoryConstants.JSON) public static JsonType jsonParse(BlobType val, boolean wellformed) throws SQLException, IOException, ParseException { InputStreamReader r = XMLSystemFunctions.getJsonReader(val); try { if (!wellformed) { JSONParser parser = new JSONParser(); parser.parse(r, validatingContentHandler); } ClobImpl clobImpl = new ClobImpl(); clobImpl.setStreamFactory(new InputStreamFactory.BlobInputStreamFactory(val.getReference())); clobImpl.setEncoding(r.getEncoding()); return new JsonType(clobImpl); } finally { r.close(); } }
@TeiidFunction(category=FunctionCategoryConstants.JSON) public static JsonType jsonParse(BlobType val, boolean wellformed) throws SQLException, IOException, ParseException { InputStreamReader r = XMLSystemFunctions.getJsonReader(val); try { if (!wellformed) { JSONParser parser = new JSONParser(); parser.parse(r, validatingContentHandler); } ClobImpl clobImpl = new ClobImpl(); clobImpl.setStreamFactory(new InputStreamFactory.BlobInputStreamFactory(val.getReference())); clobImpl.setEncoding(r.getEncoding()); return new JsonType(clobImpl); } finally { r.close(); } }
@Override public StorageMode getStorageMode() { return getStorageMode(blob); }
@Override public void setTemporary(boolean temp) { setTemporary(blob, temp); }
@Override public StorageMode getStorageMode() { return getStorageMode(blob); }
@Override public void setTemporary(boolean temp) { setTemporary(blob, temp); }