/** * Retrieves the number of bytes in this <code>SerialBlob</code> * object's array of bytes. * * @return a <code>long</code> indicating the length in bytes of this * <code>SerialBlob</code> object's array of bytes * @throws SerialException if an error occurs; * if {@code free} had previously been called on this object */ public long length() throws SerialException { isValid(); return len; }
isValid(); if (start < 1 || start > len) { return -1;
/** * Returns this <code>SerialBlob</code> object as an input stream. * Unlike the related method, <code>setBinaryStream</code>, * a stream is produced regardless of whether the <code>SerialBlob</code> * was created with a <code>Blob</code> object or a <code>byte</code> array. * * @return a <code>java.io.InputStream</code> object that contains * this <code>SerialBlob</code> object's array of bytes * @throws SerialException if an error occurs; * if {@code free} had previously been called on this object * @see #setBinaryStream */ public java.io.InputStream getBinaryStream() throws SerialException { isValid(); InputStream stream = new ByteArrayInputStream(buf); return stream; }
/** * Returns the position in this <code>SerialBlob</code> object where * the given <code>Blob</code> object begins, starting the search at the * specified position. * * @param pattern the <code>Blob</code> object for which to search; * @param start the position of the byte in this * <code>SerialBlob</code> object from which to begin * the search; the first position is <code>1</code>; * must not be less than <code>1</code> nor greater than * the length of this <code>SerialBlob</code> object * @return the position in this <code>SerialBlob</code> object * where the given <code>Blob</code> object begins, starting * at the specified position; <code>-1</code> if the pattern is * not found or the given starting position is out of bounds; * position numbering for the return value starts at <code>1</code> * @throws SerialException if an error occurs when serializing the blob; * if {@code free} had previously been called on this object * @throws SQLException if there is an error accessing the <code>BLOB</code> * value from the database */ public long position(Blob pattern, long start) throws SerialException, SQLException { isValid(); return position(pattern.getBytes(1, (int)(pattern.length())), start); }
isValid(); if (length > len) { length = (int)len;
/** * Truncates the <code>BLOB</code> value that this <code>Blob</code> * object represents to be <code>len</code> bytes in length. * * @param length the length, in bytes, to which the <code>BLOB</code> * value that this <code>Blob</code> object represents should be * truncated * @throws SerialException if there is an error accessing the Blob value; * or the length to truncate is greater that the SerialBlob length; * if {@code free} had previously been called on this object */ public void truncate(long length) throws SerialException { isValid(); if (length > len) { throw new SerialException ("Length more than what can be truncated"); } else if((int)length == 0) { buf = new byte[0]; len = length; } else { len = length; buf = this.getBytes(1, (int)len); } }
isValid(); if (this.blob != null) { return this.blob.setBinaryStream(pos);
isValid(); if (pos < 1 || pos > this.length()) { throw new SerialException("Invalid position in BLOB object set");
throws SerialException, SQLException { isValid(); if (offset < 0 || offset > bytes.length) { throw new SerialException("Invalid offset in byte array set");