@Override public List<?> next() throws TranslatorException, DataNotAvailableException { final DBObject value = nextRow(); if (value == null) { return null; } BlobType result = new BlobType(new BlobImpl(new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(JSON.serialize(value).getBytes(Streamable.CHARSET)); } })); if (returnsArray) { List<Object[]> row = new ArrayList<Object[]>(1); row.add(new Object[] {result}); return row; } return Arrays.asList(result); }
throw new SQLException(CorePlugin.Util.getString("MMClob_MMBlob.2", params)); //$NON-NLS-1$ else if (length == 0 || pos > length()) { return new byte[0]; throw new SQLException(CorePlugin.Util.getString("MMClob_MMBlob.3", params)); //$NON-NLS-1$ else if (pos + length > length()) { length = (int)(length() - pos); InputStream in = getBinaryStream(); try { long skipped = 0;
public void testBlobImplGetBytes() throws Exception { BlobImpl b = new BlobImpl(new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(new byte[0]); } }); byte[] b1 = b.getBytes(1, 0); assertEquals(0, b1.length); byte[] b2 = b.getBytes(1, 1); assertEquals(0, b2.length); b = new BlobImpl(new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(new byte[]{1,2}); } }); byte[] b3 = b.getBytes(1, 1); assertEquals(1, b3.length); }
/** * Determines the byte position in the <code>BLOB</code> value * designated by this <code>Blob</code> object at which * <code>pattern</code> begins. The search begins at position * <code>start</code>. * @param pattern the <code>Blob</code> object designating * the <code>BLOB</code> value for which to search * @param start the position in the <code>BLOB</code> value * at which to begin searching; the first position is 1 * @return the position at which the pattern begins, else -1 * @exception SQLException if there is an error accessing the * <code>BLOB</code> */ public long position(final Blob pattern, long start) throws SQLException { if (pattern == null) { return -1; } return LobSearchUtil.position(new LobSearchUtil.StreamProvider() { public InputStream getBinaryStream() throws SQLException { return pattern.getBinaryStream(); } }, pattern.length(), this, this.length(), start, 1); }
/** * Determines the byte position in the <code>BLOB</code> value * designated by this <code>Blob</code> object at which * <code>pattern</code> begins. The search begins at position * <code>start</code>. * @param pattern the <code>Blob</code> object designating * the <code>BLOB</code> value for which to search * @param start the position in the <code>BLOB</code> value * at which to begin searching; the first position is 1 * @return the position at which the pattern begins, else -1 * @exception SQLException if there is an error accessing the * <code>BLOB</code> */ public long position(final Blob pattern, long start) throws SQLException { if (pattern == null) { return -1; } return LobSearchUtil.position(new LobSearchUtil.StreamProvider() { public InputStream getBinaryStream() throws SQLException { return pattern.getBinaryStream(); } }, pattern.length(), this, this.length(), start, 1); }
private static Object asLob(InputStreamFactory value, Class<?> desiredType) { if (desiredType == DataTypeManager.DefaultDataClasses.CLOB) { //assumes UTF-8 return new ClobType(new ClobImpl(value, -1)); } return new BlobType(new BlobImpl(value)); }
throw new SQLException(CorePlugin.Util.getString("MMClob_MMBlob.2", params)); //$NON-NLS-1$ else if (length == 0 || pos > length()) { return new byte[0]; throw new SQLException(CorePlugin.Util.getString("MMClob_MMBlob.3", params)); //$NON-NLS-1$ else if (pos + length > length()) { length = (int)(length() - pos); InputStream in = getBinaryStream(); try { long skipped = 0;
private static Object asLob(InputStreamFactory value, Class<?> desiredType) { if (desiredType == DataTypeManager.DefaultDataClasses.CLOB) { //assumes UTF-8 return new ClobType(new ClobImpl(value, -1)); } return new BlobType(new BlobImpl(value)); }
void setBlob(Object parameterIndex, final InputStream inputStream) throws SQLException { if (inputStream == null) { this.setObject(parameterIndex, null); return; } this.setObject(parameterIndex, new BlobImpl(new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { return inputStream; } })); }
void setBlob(Object parameterIndex, final InputStream inputStream) throws SQLException { if (inputStream == null) { this.setObject(parameterIndex, null); return; } this.setObject(parameterIndex, new BlobImpl(new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { return inputStream; } })); }
return new BlobImpl(new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { return new SQLXMLImpl(rawContents); } else if (expectedType.isAssignableFrom(AbstractGeospatialType.class)) { return new GeometryType(new BlobImpl(new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException {
public BlobImpl getVDBResourceAsBlob(String resourcePath) { final VDBResources.Resource f = getFile(resourcePath); if (f == null) { return null; } return new BlobImpl(new VirtualFileInputStreamFactory(f)); }
public static Object convertByteArrayToTeiidRuntimeType(final Class<?> type, final byte[] contents, final String odataType, String srid) throws TeiidException { if (contents == null) { return null; } Object value = null; if (DataTypeManager.isLOB(type)) { InputStreamFactory isf = new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(contents); } }; if (type.isAssignableFrom(SQLXML.class)) { value = new SQLXMLImpl(isf); } else if (type.isAssignableFrom(ClobType.class)) { value = new ClobImpl(isf, -1); } else if (type.isAssignableFrom(BlobType.class)) { value = new BlobImpl(isf); } } else if (DataTypeManager.DefaultDataClasses.VARBINARY.equals(type)) { value = contents; } else { value = convertToTeiidRuntimeType(type, new String(contents), odataType, srid); } return value; }
public BlobImpl getVDBResourceAsBlob(String resourcePath) { final VDBResources.Resource f = getFile(resourcePath); if (f == null) { return null; } return new BlobImpl(new VirtualFileInputStreamFactory(f)); }
public BlobImpl getVDBResourceAsBlob(String resourcePath) { final VDBResources.Resource f = getFile(resourcePath); if (f == null) { return null; } return new BlobImpl(new VirtualFileInputStreamFactory(f)); }
public static Object convertByteArrayToTeiidRuntimeType(final Class<?> type, final byte[] contents, final String odataType, String srid) throws TeiidException { if (contents == null) { return null; } Object value = null; if (DataTypeManager.isLOB(type)) { InputStreamFactory isf = new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(contents); } }; if (type.isAssignableFrom(SQLXML.class)) { value = new SQLXMLImpl(isf); } else if (type.isAssignableFrom(ClobType.class)) { value = new ClobImpl(isf, -1); } else if (type.isAssignableFrom(BlobType.class)) { value = new BlobImpl(isf); } } else if (DataTypeManager.DefaultDataClasses.VARBINARY.equals(type)) { value = contents; } else { value = convertToTeiidRuntimeType(type, new String(contents), odataType, srid); } return value; }
Blob b = new BlobImpl(streamFactory);
@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)); }