private void resetIfNeeded() throws SQLException { try { if ( needsReset ) { binaryStream.getInputStream().reset(); } } catch ( IOException ioe) { throw new SQLException("could not reset reader"); } needsReset = true; }
private InputStream getStream() throws SQLException { return getUnderlyingStream().getInputStream(); }
@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() ); } }
@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() ); } }
private void resetIfNeeded() throws SQLException { try { if ( needsReset ) { binaryStream.getInputStream().reset(); } } catch ( IOException ioe) { throw new SQLException("could not reset reader"); } needsReset = true; }
private InputStream getStream() throws SQLException { return getUnderlyingStream().getInputStream(); }
@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() ); } }
@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() ); } } };