public void setEncoding(String encoding) { this.encoding = CharsetUtils.getCharset(encoding); }
@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.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 = 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_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); }
CharsetUtils.getCharset((String)((Constant)obj.getArg(1)).getValue()); } catch (IllegalArgumentException e) { handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.invalid_encoding", obj.getArg(1)), obj); //$NON-NLS-1$
CharsetUtils.getCharset((String)((Constant)obj.getArg(1)).getValue()); } catch (IllegalArgumentException e) { handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.invalid_encoding", obj.getArg(1)), obj); //$NON-NLS-1$