1. /*
  2. * @(#)Blob.java 1.10 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.sql;
  8. /**
  9. * JDBC 2.0
  10. *
  11. * <p>
  12. * The representation (mapping) in
  13. * the Java<sup><font size=-2>TM</font></sup> programming
  14. * language of an SQL
  15. * <code>BLOB</code>. An SQL <code>BLOB</code> is a built-in type
  16. * that stores a Binary Large Object as a column value in a row of
  17. * a database table. The driver implements <code>Blob</code> using
  18. * an SQL <code>locator(BLOB)</code>, which means that a
  19. * <code>Blob</code> object contains a logical pointer to the
  20. * SQL <code>BLOB</code> data rather than the data itself.
  21. * A <code>Blob</code> object is valid for the duration of the
  22. * transaction in which is was created.
  23. *
  24. * <P>Methods in the interfaces {@link ResultSet},
  25. * {@link CallableStatement}, and {@link PreparedStatement}, such as
  26. * <code>getBlob</code> and <code>setBlob</code> allow a programmer to
  27. * access the SQL <code>BLOB</code>.
  28. * The <code>Blob</code> interface provides methods for getting the
  29. * length of an SQL <code>BLOB</code> (Binary Large Object) value,
  30. * for materializing a <code>BLOB</code> value on the client, and for
  31. * determining the position of a pattern of bytes within a
  32. * <code>BLOB</code> value.
  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. */
  42. long length() throws SQLException;
  43. /**
  44. * Returns as an array of bytes part or all of the <code>BLOB</code>
  45. * value that this <code>Blob</code> object designates. The byte
  46. * array contains up to <code>length</code> consecutive bytes
  47. * starting at position <code>pos</code>.
  48. * @param pos the ordinal position of the first byte in the
  49. * <code>BLOB</code> value to be extracted; the first byte is at
  50. * position 1
  51. * @param length is the number of consecutive bytes to be copied
  52. * @return a byte array containing up to <code>length</code>
  53. * consecutive bytes from the <code>BLOB</code> value designated
  54. * by this <code>Blob</code> object, starting with the
  55. * byte at position <code>pos</code>.
  56. * @exception SQLException if there is an error accessing the
  57. * <code>BLOB</code>
  58. */
  59. byte[] getBytes(long pos, int length) throws SQLException;
  60. /**
  61. * Retrieves the <code>BLOB</code> designated by this
  62. * <code>Blob</code> instance as a stream.
  63. * @return a stream containing the <code>BLOB</code> data
  64. * @exception SQLException if there is an error accessing the
  65. * <code>BLOB</code>
  66. */
  67. java.io.InputStream getBinaryStream () throws SQLException;
  68. /**
  69. * Determines the byte position at which the specified byte
  70. * <code>pattern</code> begins within the <code>BLOB</code>
  71. * value that this <code>Blob</code> object represents. The
  72. * search for <code>pattern</code. begins at position
  73. * <code>start</code>.
  74. * @param pattern the byte array for which to search
  75. * @param start the position at which to begin searching; the
  76. * first position is 1
  77. * @return the position at which the pattern appears, else -1.
  78. * @exception SQLException if there is an error accessing the
  79. * <code>BLOB</code>
  80. */
  81. long position(byte pattern[], long start) throws SQLException;
  82. /**
  83. * Determines the byte position in the <code>BLOB</code> value
  84. * designated by this <code>Blob</code> object at which
  85. * <code>pattern</code> begins. The search begins at position
  86. * <code>start</code>.
  87. * @param pattern the <code>Blob</code> object designating
  88. * the <code>BLOB</code> value for which to search
  89. * @param start the position in the <code>BLOB</code> value
  90. * at which to begin searching; the first position is 1
  91. * @return the position at which the pattern begins, else -1
  92. * @exception SQLException if there is an error accessing the
  93. * <code>BLOB</code>
  94. */
  95. long position(Blob pattern, long start) throws SQLException;
  96. }