1. /*
  2. * @(#)Blob.java 1.27 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.sql;
  8. /**
  9. * The representation (mapping) in
  10. * the Java<sup><font size=-2>TM</font></sup> programming
  11. * language of an SQL
  12. * <code>BLOB</code> value. An SQL <code>BLOB</code> is a built-in type
  13. * that stores a Binary Large Object as a column value in a row of
  14. * a database table. By default drivers implement <code>Blob</code> using
  15. * an SQL <code>locator(BLOB)</code>, which means that a
  16. * <code>Blob</code> object contains a logical pointer to the
  17. * SQL <code>BLOB</code> data rather than the data itself.
  18. * A <code>Blob</code> object is valid for the duration of the
  19. * transaction in which is was created.
  20. *
  21. * <P>Methods in the interfaces {@link ResultSet},
  22. * {@link CallableStatement}, and {@link PreparedStatement}, such as
  23. * <code>getBlob</code> and <code>setBlob</code> allow a programmer to
  24. * access an SQL <code>BLOB</code> value.
  25. * The <code>Blob</code> interface provides methods for getting the
  26. * length of an SQL <code>BLOB</code> (Binary Large Object) value,
  27. * for materializing a <code>BLOB</code> value on the client, and for
  28. * determining the position of a pattern of bytes within a
  29. * <code>BLOB</code> value. In addition, this interface has methods for updating
  30. * a <code>BLOB</code> value.
  31. *
  32. * @since 1.2
  33. */
  34. public interface Blob {
  35. /**
  36. * Returns the number of bytes in the <code>BLOB</code> value
  37. * designated by this <code>Blob</code> object.
  38. * @return length of the <code>BLOB</code> in bytes
  39. * @exception SQLException if there is an error accessing the
  40. * length of the <code>BLOB</code>
  41. * @since 1.2
  42. */
  43. long length() throws SQLException;
  44. /**
  45. * Retrieves all or part of the <code>BLOB</code>
  46. * value that this <code>Blob</code> object represents, as an array of
  47. * bytes. This <code>byte</code> array contains up to <code>length</code>
  48. * consecutive bytes starting at position <code>pos</code>.
  49. *
  50. * @param pos the ordinal position of the first byte in the
  51. * <code>BLOB</code> value to be extracted; the first byte is at
  52. * position 1
  53. * @param length the number of consecutive bytes to be copied
  54. * @return a byte array containing up to <code>length</code>
  55. * consecutive bytes from the <code>BLOB</code> value designated
  56. * by this <code>Blob</code> object, starting with the
  57. * byte at position <code>pos</code>
  58. * @exception SQLException if there is an error accessing the
  59. * <code>BLOB</code> value
  60. * @see #setBytes
  61. * @since 1.2
  62. */
  63. byte[] getBytes(long pos, int length) throws SQLException;
  64. /**
  65. * Retrieves the <code>BLOB</code> value designated by this
  66. * <code>Blob</code> instance as a stream.
  67. *
  68. * @return a stream containing the <code>BLOB</code> data
  69. * @exception SQLException if there is an error accessing the
  70. * <code>BLOB</code> value
  71. * @see #setBinaryStream
  72. * @since 1.2
  73. */
  74. java.io.InputStream getBinaryStream () throws SQLException;
  75. /**
  76. * Retrieves the byte position at which the specified byte array
  77. * <code>pattern</code> begins within the <code>BLOB</code>
  78. * value that this <code>Blob</code> object represents. The
  79. * search for <code>pattern</code> begins at position
  80. * <code>start</code>.
  81. *
  82. * @param pattern the byte array for which to search
  83. * @param start the position at which to begin searching; the
  84. * first position is 1
  85. * @return the position at which the pattern appears, else -1
  86. * @exception SQLException if there is an error accessing the
  87. * <code>BLOB</code>
  88. * @since 1.2
  89. */
  90. long position(byte pattern[], long start) throws SQLException;
  91. /**
  92. * Retrieves the byte position in the <code>BLOB</code> value
  93. * designated by this <code>Blob</code> object at which
  94. * <code>pattern</code> begins. The search begins at position
  95. * <code>start</code>.
  96. *
  97. * @param pattern the <code>Blob</code> object designating
  98. * the <code>BLOB</code> value for which to search
  99. * @param start the position in the <code>BLOB</code> value
  100. * at which to begin searching; the first position is 1
  101. * @return the position at which the pattern begins, else -1
  102. * @exception SQLException if there is an error accessing the
  103. * <code>BLOB</code> value
  104. * @since 1.2
  105. */
  106. long position(Blob pattern, long start) throws SQLException;
  107. // -------------------------- JDBC 3.0 -----------------------------------
  108. /**
  109. * Writes the given array of bytes to the <code>BLOB</code> value that
  110. * this <code>Blob</code> object represents, starting at position
  111. * <code>pos</code>, and returns the number of bytes written.
  112. *
  113. * @param pos the position in the <code>BLOB</code> object at which
  114. * to start writing
  115. * @param bytes the array of bytes to be written to the <code>BLOB</code>
  116. * value that this <code>Blob</code> object represents
  117. * @return the number of bytes written
  118. * @exception SQLException if there is an error accessing the
  119. * <code>BLOB</code> value
  120. * @see #getBytes
  121. * @since 1.4
  122. */
  123. int setBytes(long pos, byte[] bytes) throws SQLException;
  124. /**
  125. * Writes all or part of the given <code>byte</code> array to the
  126. * <code>BLOB</code> value that this <code>Blob</code> object represents
  127. * and returns the number of bytes written.
  128. * Writing starts at position <code>pos</code> in the <code>BLOB</code>
  129. * value; <code>len</code> bytes from the given byte array are written.
  130. *
  131. * @param pos the position in the <code>BLOB</code> object at which
  132. * to start writing
  133. * @param bytes the array of bytes to be written to this <code>BLOB</code>
  134. * object
  135. * @param offset the offset into the array <code>bytes</code> at which
  136. * to start reading the bytes to be set
  137. * @param len the number of bytes to be written to the <code>BLOB</code>
  138. * value from the array of bytes <code>bytes</code>
  139. * @return the number of bytes written
  140. * @exception SQLException if there is an error accessing the
  141. * <code>BLOB</code> value
  142. * @see #getBytes
  143. * @since 1.4
  144. */
  145. int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException;
  146. /**
  147. * Retrieves a stream that can be used to write to the <code>BLOB</code>
  148. * value that this <code>Blob</code> object represents. The stream begins
  149. * at position <code>pos</code>.
  150. *
  151. * @param pos the position in the <code>BLOB</code> value at which
  152. * to start writing
  153. * @return a <code>java.io.OutputStream</code> object to which data can
  154. * be written
  155. * @exception SQLException if there is an error accessing the
  156. * <code>BLOB</code> value
  157. * @see #getBinaryStream
  158. * @since 1.4
  159. */
  160. java.io.OutputStream setBinaryStream(long pos) throws SQLException;
  161. /**
  162. * Truncates the <code>BLOB</code> value that this <code>Blob</code>
  163. * object represents to be <code>len</code> bytes in length.
  164. *
  165. * @param len the length, in bytes, to which the <code>BLOB</code> value
  166. * that this <code>Blob</code> object represents should be truncated
  167. * @exception SQLException if there is an error accessing the
  168. * <code>BLOB</code> value
  169. * @since 1.4
  170. */
  171. void truncate(long len) throws SQLException;
  172. }