Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/sql/Blob.java
38829 views
/*1* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.sql;2627import java.io.InputStream;2829/**30* The representation (mapping) in31* the Java™ programming32* language of an SQL33* <code>BLOB</code> value. An SQL <code>BLOB</code> is a built-in type34* that stores a Binary Large Object as a column value in a row of35* a database table. By default drivers implement <code>Blob</code> using36* an SQL <code>locator(BLOB)</code>, which means that a37* <code>Blob</code> object contains a logical pointer to the38* SQL <code>BLOB</code> data rather than the data itself.39* A <code>Blob</code> object is valid for the duration of the40* transaction in which is was created.41*42* <P>Methods in the interfaces {@link ResultSet},43* {@link CallableStatement}, and {@link PreparedStatement}, such as44* <code>getBlob</code> and <code>setBlob</code> allow a programmer to45* access an SQL <code>BLOB</code> value.46* The <code>Blob</code> interface provides methods for getting the47* length of an SQL <code>BLOB</code> (Binary Large Object) value,48* for materializing a <code>BLOB</code> value on the client, and for49* determining the position of a pattern of bytes within a50* <code>BLOB</code> value. In addition, this interface has methods for updating51* a <code>BLOB</code> value.52* <p>53* All methods on the <code>Blob</code> interface must be fully implemented if the54* JDBC driver supports the data type.55*56* @since 1.257*/5859public interface Blob {6061/**62* Returns the number of bytes in the <code>BLOB</code> value63* designated by this <code>Blob</code> object.64* @return length of the <code>BLOB</code> in bytes65* @exception SQLException if there is an error accessing the66* length of the <code>BLOB</code>67* @exception SQLFeatureNotSupportedException if the JDBC driver does not support68* this method69* @since 1.270*/71long length() throws SQLException;7273/**74* Retrieves all or part of the <code>BLOB</code>75* value that this <code>Blob</code> object represents, as an array of76* bytes. This <code>byte</code> array contains up to <code>length</code>77* consecutive bytes starting at position <code>pos</code>.78*79* @param pos the ordinal position of the first byte in the80* <code>BLOB</code> value to be extracted; the first byte is at81* position 182* @param length the number of consecutive bytes to be copied; the value83* for length must be 0 or greater84* @return a byte array containing up to <code>length</code>85* consecutive bytes from the <code>BLOB</code> value designated86* by this <code>Blob</code> object, starting with the87* byte at position <code>pos</code>88* @exception SQLException if there is an error accessing the89* <code>BLOB</code> value; if pos is less than 1 or length is90* less than 091* @exception SQLFeatureNotSupportedException if the JDBC driver does not support92* this method93* @see #setBytes94* @since 1.295*/96byte[] getBytes(long pos, int length) throws SQLException;9798/**99* Retrieves the <code>BLOB</code> value designated by this100* <code>Blob</code> instance as a stream.101*102* @return a stream containing the <code>BLOB</code> data103* @exception SQLException if there is an error accessing the104* <code>BLOB</code> value105* @exception SQLFeatureNotSupportedException if the JDBC driver does not support106* this method107* @see #setBinaryStream108* @since 1.2109*/110java.io.InputStream getBinaryStream () throws SQLException;111112/**113* Retrieves the byte position at which the specified byte array114* <code>pattern</code> begins within the <code>BLOB</code>115* value that this <code>Blob</code> object represents. The116* search for <code>pattern</code> begins at position117* <code>start</code>.118*119* @param pattern the byte array for which to search120* @param start the position at which to begin searching; the121* first position is 1122* @return the position at which the pattern appears, else -1123* @exception SQLException if there is an error accessing the124* <code>BLOB</code> or if start is less than 1125* @exception SQLFeatureNotSupportedException if the JDBC driver does not support126* this method127* @since 1.2128*/129long position(byte pattern[], long start) throws SQLException;130131/**132* Retrieves the byte position in the <code>BLOB</code> value133* designated by this <code>Blob</code> object at which134* <code>pattern</code> begins. The search begins at position135* <code>start</code>.136*137* @param pattern the <code>Blob</code> object designating138* the <code>BLOB</code> value for which to search139* @param start the position in the <code>BLOB</code> value140* at which to begin searching; the first position is 1141* @return the position at which the pattern begins, else -1142* @exception SQLException if there is an error accessing the143* <code>BLOB</code> value or if start is less than 1144* @exception SQLFeatureNotSupportedException if the JDBC driver does not support145* this method146* @since 1.2147*/148long position(Blob pattern, long start) throws SQLException;149150// -------------------------- JDBC 3.0 -----------------------------------151152/**153* Writes the given array of bytes to the <code>BLOB</code> value that154* this <code>Blob</code> object represents, starting at position155* <code>pos</code>, and returns the number of bytes written.156* The array of bytes will overwrite the existing bytes157* in the <code>Blob</code> object starting at the position158* <code>pos</code>. If the end of the <code>Blob</code> value is reached159* while writing the array of bytes, then the length of the <code>Blob</code>160* value will be increased to accommodate the extra bytes.161* <p>162* <b>Note:</b> If the value specified for <code>pos</code>163* is greater then the length+1 of the <code>BLOB</code> value then the164* behavior is undefined. Some JDBC drivers may throw a165* <code>SQLException</code> while other drivers may support this166* operation.167*168* @param pos the position in the <code>BLOB</code> object at which169* to start writing; the first position is 1170* @param bytes the array of bytes to be written to the <code>BLOB</code>171* value that this <code>Blob</code> object represents172* @return the number of bytes written173* @exception SQLException if there is an error accessing the174* <code>BLOB</code> value or if pos is less than 1175* @exception SQLFeatureNotSupportedException if the JDBC driver does not support176* this method177* @see #getBytes178* @since 1.4179*/180int setBytes(long pos, byte[] bytes) throws SQLException;181182/**183* Writes all or part of the given <code>byte</code> array to the184* <code>BLOB</code> value that this <code>Blob</code> object represents185* and returns the number of bytes written.186* Writing starts at position <code>pos</code> in the <code>BLOB</code>187* value; <code>len</code> bytes from the given byte array are written.188* The array of bytes will overwrite the existing bytes189* in the <code>Blob</code> object starting at the position190* <code>pos</code>. If the end of the <code>Blob</code> value is reached191* while writing the array of bytes, then the length of the <code>Blob</code>192* value will be increased to accommodate the extra bytes.193* <p>194* <b>Note:</b> If the value specified for <code>pos</code>195* is greater then the length+1 of the <code>BLOB</code> value then the196* behavior is undefined. Some JDBC drivers may throw a197* <code>SQLException</code> while other drivers may support this198* operation.199*200* @param pos the position in the <code>BLOB</code> object at which201* to start writing; the first position is 1202* @param bytes the array of bytes to be written to this <code>BLOB</code>203* object204* @param offset the offset into the array <code>bytes</code> at which205* to start reading the bytes to be set206* @param len the number of bytes to be written to the <code>BLOB</code>207* value from the array of bytes <code>bytes</code>208* @return the number of bytes written209* @exception SQLException if there is an error accessing the210* <code>BLOB</code> value or if pos is less than 1211* @exception SQLFeatureNotSupportedException if the JDBC driver does not support212* this method213* @see #getBytes214* @since 1.4215*/216int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException;217218/**219* Retrieves a stream that can be used to write to the <code>BLOB</code>220* value that this <code>Blob</code> object represents. The stream begins221* at position <code>pos</code>.222* The bytes written to the stream will overwrite the existing bytes223* in the <code>Blob</code> object starting at the position224* <code>pos</code>. If the end of the <code>Blob</code> value is reached225* while writing to the stream, then the length of the <code>Blob</code>226* value will be increased to accommodate the extra bytes.227* <p>228* <b>Note:</b> If the value specified for <code>pos</code>229* is greater then the length+1 of the <code>BLOB</code> value then the230* behavior is undefined. Some JDBC drivers may throw a231* <code>SQLException</code> while other drivers may support this232* operation.233*234* @param pos the position in the <code>BLOB</code> value at which235* to start writing; the first position is 1236* @return a <code>java.io.OutputStream</code> object to which data can237* be written238* @exception SQLException if there is an error accessing the239* <code>BLOB</code> value or if pos is less than 1240* @exception SQLFeatureNotSupportedException if the JDBC driver does not support241* this method242* @see #getBinaryStream243* @since 1.4244*/245java.io.OutputStream setBinaryStream(long pos) throws SQLException;246247/**248* Truncates the <code>BLOB</code> value that this <code>Blob</code>249* object represents to be <code>len</code> bytes in length.250* <p>251* <b>Note:</b> If the value specified for <code>pos</code>252* is greater then the length+1 of the <code>BLOB</code> value then the253* behavior is undefined. Some JDBC drivers may throw a254* <code>SQLException</code> while other drivers may support this255* operation.256*257* @param len the length, in bytes, to which the <code>BLOB</code> value258* that this <code>Blob</code> object represents should be truncated259* @exception SQLException if there is an error accessing the260* <code>BLOB</code> value or if len is less than 0261* @exception SQLFeatureNotSupportedException if the JDBC driver does not support262* this method263* @since 1.4264*/265void truncate(long len) throws SQLException;266267/**268* This method frees the <code>Blob</code> object and releases the resources that269* it holds. The object is invalid once the <code>free</code>270* method is called.271*<p>272* After <code>free</code> has been called, any attempt to invoke a273* method other than <code>free</code> will result in a <code>SQLException</code>274* being thrown. If <code>free</code> is called multiple times, the subsequent275* calls to <code>free</code> are treated as a no-op.276*<p>277*278* @throws SQLException if an error occurs releasing279* the Blob's resources280* @exception SQLFeatureNotSupportedException if the JDBC driver does not support281* this method282* @since 1.6283*/284void free() throws SQLException;285286/**287* Returns an <code>InputStream</code> object that contains a partial <code>Blob</code> value,288* starting with the byte specified by pos, which is length bytes in length.289*290* @param pos the offset to the first byte of the partial value to be retrieved.291* The first byte in the <code>Blob</code> is at position 1292* @param length the length in bytes of the partial value to be retrieved293* @return <code>InputStream</code> through which the partial <code>Blob</code> value can be read.294* @throws SQLException if pos is less than 1 or if pos is greater than the number of bytes295* in the <code>Blob</code> or if pos + length is greater than the number of bytes296* in the <code>Blob</code>297*298* @exception SQLFeatureNotSupportedException if the JDBC driver does not support299* this method300* @since 1.6301*/302InputStream getBinaryStream(long pos, long length) throws SQLException;303}304305306