Blob getBytes - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Blob getBytes method.

This code example shows how to use the following methods:getBytes, length
	@Override 
	public byte[] getBlobAsBytes(ResultSet rs, int columnIndex) throws SQLException {
		logger.debug("Returning BLOB as bytes");
		if (this.wrapAsLob) {
			Blob blob = rs.getBlob(columnIndex);
			return blob.getBytes(1, (int) blob.length());
		} 
		else { 
			return rs.getBytes(columnIndex);
		} 
	} 
 
	@Override 
	public InputStream getBlobAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException {
		logger.debug("Returning BLOB as binary stream");
		if (this.wrapAsLob) {
			Blob blob = rs.getBlob(columnIndex);
			return blob.getBinaryStream();
		} 
		else { 
7
CodeRank
This code example shows how to use the following methods:getBytes, length
    else if (o instanceof Blob)
    { 
      try 
      { 
        final Blob b = (Blob) o;
        final byte[] data = b.getBytes(1, (int) b.length());
        final ResourceManager resManager = runtime.getProcessingContext().getResourceManager();
        final Resource resource = resManager.createDirectly(data, DrawableWrapper.class);
        return resource.getResource();
      } 
      catch (Exception e)
      { 
        if (DrawableLoadFilter.logger.isDebugEnabled())
        { 
          DrawableLoadFilter.logger.warn("Error while loading the drawable from an blob", e);
        } 
        else if (DrawableLoadFilter.logger.isWarnEnabled())
        { 
          DrawableLoadFilter.logger.warn("Error while loading the drawable from an blob: " + e);
        } 
6
CodeRank
This code example shows how to use the following methods:getBytes, length
        // Get as a BLOB 
        Blob aBlob = rs.getBlob(index);
        if (aBlob == null) {
            return null; 
        } 
        return aBlob.getBytes(1, (int) aBlob.length());
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getBytes, length
    public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
            throws HibernateException, SQLException 
    { 
        Blob blob = rs.getBlob(names[0]);
        if (blob != null)
            return blob.getBytes(1, (int) blob.length());
 
        return null; 
    } 
 
    public void nullSafeSet(PreparedStatement st, Object value, int index)
            throws HibernateException, SQLException 
    { 
        st.setBinaryStream(index,
                           new java.io.ByteArrayInputStream((byte[]) value), ((byte[]) value).length);
    } 
 
    public Object deepCopy(Object value)
    { 
        return value;
6
CodeRank
This code example shows how to use the following methods:getBinaryStream, getBytes, length
 
	public void testLobAccess() throws SQLException { 
		LobCreator lobCreator = JdbcSupportLoader.loadJdbcSupport( null ).getLobCreator( lobCreationContext );
 
		Blob blob = lobCreator.createBlob( "Hi".getBytes() );
		assertEquals( 2, blob.length() );
		assertEquals( 2, blob.getBytes( 1, 5 ).length );
		blob.getBinaryStream();
 
		Clob clob = lobCreator.createClob( "Hi" );
		assertEquals( 2, clob.length() );
		assertEquals( 2, clob.getSubString( 1, 5 ).length() );
		clob.getCharacterStream();
		clob.getAsciiStream();
	} 
} 
5
CodeRank
This code example shows how to use the following methods:getBytes, length
         return (new String(binaryData)).indexOf(new String(pattern), (int) start);
     } 
  
     @Override 
    public long position(java.sql.Blob pattern, long start) throws SQLException	{
         return position(pattern.getBytes(0, (int) pattern.length()), start);
     } 
  
     @Override 
    public int setBytes(long pos, byte[] bytes) throws SQLException	{
         // TODO impl. 
         throw new SQLException("JDBC 3.0 Method setBytes not implemented");
     } 
 
     @Override 
    public int setBytes(long pos, byte[] bytes, int offset, int len)	throws SQLException	{
         // TODO impl. 
         throw new SQLException("JDBC 3.0 Method setBytes not implemented");
     } 
  
6
CodeRank
This code example shows how to use the following methods:getBytes, length
  public byte[] getNullableResult(ResultSet rs, String columnName)
      throws SQLException {
    Blob blob = rs.getBlob(columnName);
    byte[] returnValue = null;
    if (null != blob) {
      returnValue = blob.getBytes(1, (int) blob.length());
    } 
    return returnValue;
  } 
 
  @Override 
  public byte[] getNullableResult(ResultSet rs, int columnIndex)
      throws SQLException {
    Blob blob = rs.getBlob(columnIndex);
    byte[] returnValue = null;
    if (null != blob) {
      returnValue = blob.getBytes(1, (int) blob.length());
    } 
    return returnValue;
  } 
6
CodeRank
This code example shows how to use the following methods:getBinaryStream, getBytes, length, position
        PreparedStatement ps = prepareStatement("values cast(? as blob)");
        ps.setBinaryStream(1, new LoopingAlphabetStream(length), length);
        ResultSet rs = ps.executeQuery();
        assertTrue(rs.next());
        Blob b = rs.getBlob(1);
        assertEquals(length, b.length());
        // Select some parts of the Blob, moving backwards. 
        assertEquals(100, b.getBytes(32*1024-27, 100).length);
        assertEquals(1029, b.getBytes(19*1024, 1029).length);
        // Compare a fresh stream with the one from the Blob. 
        assertEquals(new LoopingAlphabetStream(length), b.getBinaryStream());
        assertEquals(-1, b.position(new byte[] {(byte)'a', (byte)'A'}, 1));
        assertEquals(length, b.length());
        assertFalse(rs.next());
        rs.close();
    } 
 
 
    /** 
     * Tests that a lob can be safely occur multiple times in a SQL select. 
6
CodeRank
This code example shows how to use the following methods:getBytes, length
                javaValue = new java.util.Date(((java.sql.Date) jdbcValue).getTime());
            } 
        } else if (jdbcValue instanceof Blob && property.getType().equals(byte[].class)) {
            Blob blob = (Blob) jdbcValue;
            try { 
                long llength = (int) blob.length();
                // completely artificial limit of 42 megabytes... 
                if (llength > 42 * 1024 * 1024) {
                    throw new IllegalStateException("blob too large to assign to byte[] (limit is 42M)");
                } 
                int length = (int) llength;
                javaValue = blob.getBytes(1, length);
            } catch (SQLException e) {
                throw new IllegalArgumentException(e.getMessage());
            } 
 
        } else { 
            // add more here if required 
        } 
        return javaValue;
5
CodeRank
This code example shows how to use the following methods:getBytes, length
 
    @Override 
    protected byte[] getBinaryData(ResultSet rs, int index) throws SQLException {
        // Get as a BLOB 
        Blob aBlob = rs.getBlob(index);
        return aBlob.getBytes(1, (int) aBlob.length());
    } 
} 
6
CodeRank

Related Blob getBytes Questions & Answers:

getBytes Method Overview
Retrieves all or part of the BLOB value that this Blob object represents, as an array of bytes.
See Code Examples for other Java 8 Blob Methods: