/** * Used by the system table logic * @return */ public Clob getSpatialRefSys() { return new ClobImpl(new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { return getClass().getClassLoader().getResourceAsStream("org/teiid/metadata/spatial_ref_sys.csv"); //$NON-NLS-1$ } }, -1); }
/** * Gets the <code>CLOB</code> value designated by this <code>Clob</code> * object as a stream of Ascii bytes. * @return an ascii stream containing the <code>CLOB</code> data * @exception SQLException if there is an error accessing the * <code>CLOB</code> value */ public InputStream getAsciiStream() throws SQLException { return new ReaderInputStream(getCharacterStream(), Charset.forName("US-ASCII")); //$NON-NLS-1$ }
@Override protected void readReference(ObjectInput in) throws IOException { char[] chars = new char[(int)length]; for (int i = 0; i < chars.length; i++) { chars[i] = in.readChar(); } this.reference = ClobImpl.createClob(chars); }
/** * Determines the character position at which the specified substring * <code>searchstr</code> appears in the SQL <code>CLOB</code> value * represented by this <code>Clob</code> object. The search * begins at position <code>start</code>. * @param searchstr the substring for which to search * @param start the position at which to begin searching; the first position * is 1 * @return the position at which the substring appears, else -1; the first * position is 1 * @exception SQLException if there is an error accessing the * <code>CLOB</code> value */ public long position(String searchstr, long start) throws SQLException { if (searchstr == null) { return -1; } return position(new ClobImpl(searchstr), start); }
Object[] params = new Object[] {new Long(pos)}; throw new SQLException(CorePlugin.Util.getString("MMClob_MMBlob.2", params)); //$NON-NLS-1$ } else if (pos > length()) { return null; Object[] params = new Object[] {new Integer( length)}; throw new SQLException(CorePlugin.Util.getString("MMClob_MMBlob.1", params)); //$NON-NLS-1$ } else if ((pos+length) > length()) { length = (int)(length()-pos); Reader in = getCharacterStream(); try { try {
@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.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(); } }
ClobImpl clob = new ClobImpl(new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { clob.setEncoding(charset(part));
return sfr; } else if (obj instanceof ClobImpl) { streams.add(new ReaderInputStream(((ClobImpl)obj).getCharacterStream(), Charset.forName(Streamable.ENCODING))); StreamFactoryReference sfr = new ClobImpl(); references.add(sfr); return sfr; } else if (obj instanceof Clob) { streams.add(new ReaderInputStream(((Clob)obj).getCharacterStream(), Charset.forName(Streamable.ENCODING))); StreamFactoryReference sfr = new ClobImpl(); references.add(sfr); return sfr;
@Override public List<?> next() throws TranslatorException, DataNotAvailableException { if (files == null || index >= files.length) { return null; } ArrayList<Object> result = new ArrayList<>(2); final VirtualFile file = files[index++]; LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Getting", file.getName()); //$NON-NLS-1$ InputStreamFactory isf = file.createInputStreamFactory(); Object value = null; if (isText) { ClobImpl clob = new ClobImpl(isf, -1); clob.setCharset(encoding); value = new ClobType(clob); } else { value = new BlobType(new BlobImpl(isf)); } result.add(value); result.add(file.getName()); if (command.getMetadataObject().getResultSet().getColumns().size() > 2) { result.add(new Timestamp(file.getLastModified())); result.add(new Timestamp(file.getCreationTime())); result.add(file.getSize()); } return result; }
@Test public void testClobSubstring() throws Exception { ClobImpl clob = new ClobImpl() { public java.io.Reader getCharacterStream() throws java.sql.SQLException { return new Reader() { assertEquals("aa", clob.getSubString(1, 3)); assertEquals("", clob.getSubString(1, 0)); clob = new ClobImpl("hello world"); assertEquals("hel", clob.getSubString(1, 3)); assertEquals("orld", clob.getSubString(8, 5));
@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); }
@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(); } }
ClobImpl clob = new ClobImpl(new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { clob.setEncoding(charset(part));
return sfr; } else if (obj instanceof ClobImpl) { streams.add(new ReaderInputStream(((ClobImpl)obj).getCharacterStream(), Charset.forName(Streamable.ENCODING))); StreamFactoryReference sfr = new ClobImpl(); references.add(sfr); return sfr; } else if (obj instanceof Clob) { streams.add(new ReaderInputStream(((Clob)obj).getCharacterStream(), Charset.forName(Streamable.ENCODING))); StreamFactoryReference sfr = new ClobImpl(); references.add(sfr); return sfr;
/** * Determines the character position at which the specified substring * <code>searchstr</code> appears in the SQL <code>CLOB</code> value * represented by this <code>Clob</code> object. The search * begins at position <code>start</code>. * @param searchstr the substring for which to search * @param start the position at which to begin searching; the first position * is 1 * @return the position at which the substring appears, else -1; the first * position is 1 * @exception SQLException if there is an error accessing the * <code>CLOB</code> value */ public long position(String searchstr, long start) throws SQLException { if (searchstr == null) { return -1; } return position(new ClobImpl(searchstr), start); }
Object[] params = new Object[] {new Long(pos)}; throw new SQLException(CorePlugin.Util.getString("MMClob_MMBlob.2", params)); //$NON-NLS-1$ } else if (pos > length()) { return null; Object[] params = new Object[] {new Integer( length)}; throw new SQLException(CorePlugin.Util.getString("MMClob_MMBlob.1", params)); //$NON-NLS-1$ } else if ((pos+length) > length()) { length = (int)(length()-pos); Reader in = getCharacterStream(); try { try {
/** * Used by the system table logic * @return */ public Clob getSpatialRefSys() { return new ClobImpl(new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { return getClass().getClassLoader().getResourceAsStream("org/teiid/metadata/spatial_ref_sys.csv"); //$NON-NLS-1$ } }, -1); }
@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); }
@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(); } }