Class BlobImpl

  • All Implemented Interfaces:
    java.sql.Blob

    public class BlobImpl
    extends java.lang.Object
    implements java.sql.Blob

    The representation (mapping) in the Java programming language of an SQL BLOB value. An SQL BLOB is a built-in type that stores a Binary Large Object as a column value in a row of a database table. The driver implements Blob using an SQL locator(BLOB), which means that a Blob object contains a logical pointer to the SQL BLOB data rather than the data itself. A Blob object is valid for the duration of the transaction in which is was created.

    Methods in the interfaces ResultSet, CallableStatement, and PreparedStatement, such as getBlob and setBlob allow a programmer to access an SQL BLOB value. The Blob interface provides methods for getting the length of an SQL BLOB (Binary Large Object) value, for materializing a BLOB value on the client, and for determining the position of a pattern of bytes within a BLOB value.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private byte[] bytes  
      (package private) boolean freed
      Whether we have already freed resources.
      private int length  
      private java.io.InputStream stream  
    • Constructor Summary

      Constructors 
      Constructor Description
      BlobImpl​(byte[] bytes)
      Constructor taking a byte array.
      BlobImpl​(java.io.InputStream stream)
      Constructor taking an InputStream.
      BlobImpl​(java.lang.Object obj)
      Constructor taking a serialised object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void free()
      Free the Blob object and releases the resources that it holds.
      java.io.InputStream getBinaryStream()  
      java.io.InputStream getBinaryStream​(long pos, long length)
      Returns an InputStream object that contains a partial Blob value, starting with the byte specified by pos, which is length bytes in length.
      byte[] getBytes​(long pos, int length)  
      java.lang.Object getObject()
      Accessor for the Object.
      long length()  
      long position​(byte[] pattern, long start)  
      long position​(java.sql.Blob pattern, long start)  
      java.io.OutputStream setBinaryStream​(long value)  
      int setBytes​(long value, byte[] bytes)  
      int setBytes​(long value, byte[] bytes, int pos, int length)  
      void truncate​(long value)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • stream

        private java.io.InputStream stream
      • length

        private int length
      • bytes

        private byte[] bytes
      • freed

        boolean freed
        Whether we have already freed resources.
    • Constructor Detail

      • BlobImpl

        public BlobImpl​(java.lang.Object obj)
                 throws java.io.IOException
        Constructor taking a serialised object.
        Parameters:
        obj - The serialised object.
        Throws:
        java.io.IOException - if an error occurs
      • BlobImpl

        public BlobImpl​(byte[] bytes)
        Constructor taking a byte array.
        Parameters:
        bytes - The byte array
      • BlobImpl

        public BlobImpl​(java.io.InputStream stream)
        Constructor taking an InputStream.
        Parameters:
        stream - The InputStream
    • Method Detail

      • getObject

        public java.lang.Object getObject()
                                   throws java.sql.SQLException
        Accessor for the Object.
        Returns:
        The object.
        Throws:
        java.sql.SQLException - if an error occurs
      • length

        public long length()
                    throws java.sql.SQLException
        Specified by:
        length in interface java.sql.Blob
        Throws:
        java.sql.SQLException
      • getBytes

        public byte[] getBytes​(long pos,
                               int length)
                        throws java.sql.SQLException
        Specified by:
        getBytes in interface java.sql.Blob
        Throws:
        java.sql.SQLException
      • setBytes

        public int setBytes​(long value,
                            byte[] bytes,
                            int pos,
                            int length)
                     throws java.sql.SQLException
        Specified by:
        setBytes in interface java.sql.Blob
        Throws:
        java.sql.SQLException
      • truncate

        public void truncate​(long value)
                      throws java.sql.SQLException
        Specified by:
        truncate in interface java.sql.Blob
        Throws:
        java.sql.SQLException
      • setBytes

        public int setBytes​(long value,
                            byte[] bytes)
                     throws java.sql.SQLException
        Specified by:
        setBytes in interface java.sql.Blob
        Throws:
        java.sql.SQLException
      • getBinaryStream

        public java.io.InputStream getBinaryStream()
                                            throws java.sql.SQLException
        Specified by:
        getBinaryStream in interface java.sql.Blob
        Throws:
        java.sql.SQLException
      • getBinaryStream

        public java.io.InputStream getBinaryStream​(long pos,
                                                   long length)
                                            throws java.sql.SQLException
        Returns an InputStream object that contains a partial Blob value, starting with the byte specified by pos, which is length bytes in length.
        Specified by:
        getBinaryStream in interface java.sql.Blob
        Parameters:
        pos - the offset to the first byte of the partial value to be retrieved. The first byte in the Blob is at position 1
        length - the length in bytes of the partial value to be retrieved
        Throws:
        java.sql.SQLException
      • setBinaryStream

        public java.io.OutputStream setBinaryStream​(long value)
                                             throws java.sql.SQLException
        Specified by:
        setBinaryStream in interface java.sql.Blob
        Throws:
        java.sql.SQLException
      • free

        public void free()
                  throws java.sql.SQLException
        Free the Blob object and releases the resources that it holds. The object is invalid once the free method is called.
        Specified by:
        free in interface java.sql.Blob
        Throws:
        java.sql.SQLException - if an error occurs
      • position

        public long position​(byte[] pattern,
                             long start)
                      throws java.sql.SQLException
        Specified by:
        position in interface java.sql.Blob
        Throws:
        java.sql.SQLException
      • position

        public long position​(java.sql.Blob pattern,
                             long start)
                      throws java.sql.SQLException
        Specified by:
        position in interface java.sql.Blob
        Throws:
        java.sql.SQLException