@Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { final BinaryStream binaryStream = javaTypeDescriptor.unwrap( value, BinaryStream.class, options ); if ( value instanceof BlobImplementer ) { try ( InputStream is = new CloseSuppressingInputStream( binaryStream.getInputStream() ) ) { st.setBinaryStream( index, is, binaryStream.getLength() ); } catch (IOException e) { // can't happen => ignore } } else { st.setBinaryStream( index, binaryStream.getInputStream(), binaryStream.getLength() ); } }
byte[] data = ( (BinaryStream ) inputStream ).getBytes(); int size = Math.min( length, data.length ); byte[] result = new byte[size];
@Override public void free() { binaryStream.release(); }
private void resetIfNeeded() throws SQLException { try { if ( needsReset ) { binaryStream.getInputStream().reset(); } } catch ( IOException ioe) { throw new SQLException("could not reset reader"); } needsReset = true; }
@Override public long length() throws SQLException { return binaryStream.getLength(); }
private InputStream getStream() throws SQLException { return getUnderlyingStream().getInputStream(); }
@Override public long length() throws SQLException { return binaryStream.getLength(); }
@Override protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException { final BinaryStream binaryStream = javaTypeDescriptor.unwrap( value, BinaryStream.class, options ); if ( value instanceof BlobImplementer ) { try ( InputStream is = new CloseSuppressingInputStream( binaryStream.getInputStream() ) ) { st.setBinaryStream( name, is, binaryStream.getLength() ); } catch (IOException e) { // can't happen => ignore } } else { st.setBinaryStream( name, binaryStream.getInputStream(), binaryStream.getLength() ); } } };
@Test @TestForIssue( jiraKey = "HHH-8193" ) public void testStreamResetOnAccess() throws IOException, SQLException { byte[] bytes = new byte[] { 1, 2, 3, 4 }; BlobImplementer blob = (BlobImplementer) BlobProxy.generateProxy( bytes ); int value = blob.getUnderlyingStream().getInputStream().read(); // Call to BlobImplementer#getUnderlyingStream() should mark input stream for reset. assertEquals( bytes.length, blob.getUnderlyingStream().getInputStream().available() ); } }
return ( (BinaryStream ) inputStream ).getBytes();
@Override public void free() { binaryStream.release(); }
@Override protected void doBind( PreparedStatement st, int index, X value, ExecutionContext executionContext) throws SQLException { final BinaryStream binaryStream = javaTypeDescriptor.unwrap( value, BinaryStream.class, executionContext.getSession() ); if ( value instanceof BlobImplementer ) { try ( InputStream is = new CloseSuppressingInputStream( binaryStream.getInputStream() ) ) { st.setBinaryStream( index, is, binaryStream.getLength() ); } catch (IOException e) { // can't happen => ignore } } else { st.setBinaryStream( index, binaryStream.getInputStream(), binaryStream.getLength() ); } }
private void resetIfNeeded() throws SQLException { try { if ( needsReset ) { binaryStream.getInputStream().reset(); } } catch ( IOException ioe) { throw new SQLException("could not reset reader"); } needsReset = true; }
if ( BlobImplementer.class.isInstance( value ) ) { return (X) ( (BlobImplementer) value ).getUnderlyingStream().getBytes();
@Override protected void doBind( CallableStatement st, String name, X value, ExecutionContext executionContext) throws SQLException { final BinaryStream binaryStream = javaTypeDescriptor.unwrap( value, BinaryStream.class, executionContext.getSession() ); if ( value instanceof BlobImplementer ) { try ( InputStream is = new CloseSuppressingInputStream( binaryStream.getInputStream() ) ) { st.setBinaryStream( name, is, binaryStream.getLength() ); } catch (IOException e) { // can't happen => ignore } } else { st.setBinaryStream( name, binaryStream.getInputStream(), binaryStream.getLength() ); } } };
private InputStream getStream() throws SQLException { return getUnderlyingStream().getInputStream(); }
byte[] data = ( (BinaryStream) inputStream ).getBytes(); int size = Math.min( length, data.length ); byte[] result = new byte[size];
return ( (BinaryStream) inputStream ).getBytes();
if ( BlobImplementer.class.isInstance( value ) ) { return (X) ( (BlobImplementer) value ).getUnderlyingStream().getBytes();