Java 8 Blob - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Blob class.

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 { 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: getBinaryStream
    public Object get(ResultSet rs, String colName) throws SQLException {
        File f = this.createTempFile();
        Blob blob = rs.getBlob(colName);
        if (blob == null)
            return null; 
        Files.write(f, blob.getBinaryStream());
        return new SimpleBlob(f);
    } 
 
    public void set(PreparedStatement stat, Object obj, int i) throws SQLException {
        if (null == obj) {
            stat.setNull(i, Types.BLOB);
        } else { 
            Blob blob = (Blob) obj;
            stat.setBlob(i, blob);
        } 
    } 
 
} 
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: length
	 * @return String 
	 */ 
	private static String formatLogParam(Blob obj) {
		String result="";
		try { 
			result= "(blob of length "+obj.length()+")";
		} catch (SQLException e) {
			result = "(blob of unknown length)";
		} 
		return result;
	} 
 
	/** Formatter for debugging purposes only.  
	 * @param obj to print 
	 * @return String 
	 */ 
	private static String formatLogParam(Clob obj) {
		String result="";
		try { 
			result= "(cblob of length "+obj.length()+")";
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: setBytes, truncate
                throw new IOException("Failed select blob for message: " + sequence + " in container.");
            } 
 
            // Update the blob 
            Blob blob = rs.getBlob(1);
            blob.truncate(0);
            blob.setBytes(1, data);
            rs.updateBlob(1, blob);
            rs.updateRow();             // Update the row with the updated blob
        } finally { 
            close(rs);
            close(s);
        } 
    } 
 
    @Override 
    public byte[] doGetMessage(TransactionContext c, MessageId id) throws SQLException, IOException {
        PreparedStatement s = null;
        ResultSet rs = null;
        cleanupExclusiveLock.readLock().lock(); 
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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;
  } 
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: getBinaryStream, length
		if (blob == null)
			return null; 
		 
		InputStream is = null;
		try { 
			is = blob.getBinaryStream();
			byte[] data = new byte[(int)blob.length()];		// byte[] data = new byte[is.available()];
			is.read(data);
			is.close();
			return data;
		} catch (IOException e) {
			throw new RuntimeException(e);
		} 
		finally { 
			try {is.close();} catch (IOException e) {throw new RuntimeException(e);}
		} 
	} 
	 
	public static String handleClob(Clob clob) throws SQLException {
		if (clob == null)
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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. 
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: getBinaryStream, length
			return; 
		} 
 
		Blob blob = ( Blob ) value;
 
		if ( WrappedBlob.class.isInstance( blob ) ) {
			blob = ( (WrappedBlob) value ).getWrappedBlob();
		} 
 
		final boolean useInputStream = session.getFactory().getDialect().useInputStreamToInsertBlob()
				&& BlobImplementer.class.isInstance( blob );
 
		if ( useInputStream ) {
			st.setBinaryStream( index, blob.getBinaryStream(), (int) blob.length() );
		} 
		else { 
			st.setBlob( index, blob );
		} 
	} 
 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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);
        } 
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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");
     } 
  
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 Blob Questions & Answers:

See Code Examples for Java 8 Blob Methods: