/** * Retrieves the number of characters in this <code>SerialClob</code> * object's array of characters. * * @return a <code>long</code> indicating the length in characters of this * <code>SerialClob</code> object's array of character * @throws SerialException if an error occurs; * if {@code free} had previously been called on this object */ public long length() throws SerialException { isValid(); return len; }
/** * Returns this <code>SerialClob</code> object's data as a stream * of Unicode characters. Unlike the related method, <code>getAsciiStream</code>, * a stream is produced regardless of whether the <code>SerialClob</code> object * was created with a <code>Clob</code> object or a <code>char</code> array. * * @return a <code>java.io.Reader</code> object containing this * <code>SerialClob</code> object's data * @throws SerialException if an error occurs; * if {@code free} had previously been called on this object */ public java.io.Reader getCharacterStream() throws SerialException { isValid(); return (java.io.Reader) new CharArrayReader(buf); }
isValid(); if (start < 1 || start > len) { return -1;
/** * Returns the position in this <code>SerialClob</code> object * where the given <code>Clob</code> signature begins, starting * the search at the specified position. This method returns * <code>-1</code> if the pattern is not found. * * @param searchStr the <code>Clob</code> object for which to search * @param start the position in this <code>SerialClob</code> object * at 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>SerialClob</code> object * @return the position at which the given <code>Clob</code> * object begins in this <code>SerialClob</code> object, * at or after the specified starting position * @throws SerialException if an error occurs locating the Clob signature; * if the {@code free} method had been previously called on this object * @throws SQLException if there is an error accessing the Clob value * from the database */ public long position(Clob searchStr, long start) throws SerialException, SQLException { isValid(); return position(searchStr.getSubString(1,(int)searchStr.length()), start); }
/** * Truncates the <code>CLOB</code> value that this <code>SerialClob</code> * object represents so that it has a length of <code>len</code> * characters. * <p> * Truncating a <code>SerialClob</code> object to length 0 has the effect of * clearing its contents. * * @param length the length, in bytes, to which the <code>CLOB</code> * value should be truncated * @throws SerialException if there is an error accessing the * <code>CLOB</code> value; * if the {@code free} method had been previously 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 { len = length; // re-size the buffer if (len == 0) { buf = new char[] {}; } else { buf = (this.getSubString(1, (int)len)).toCharArray(); } } }
/** * Retrieves the <code>CLOB</code> value designated by this <code>SerialClob</code> * object as an ascii stream. This method forwards the <code>getAsciiStream</code> * call to the underlying <code>Clob</code> object in the event that this * <code>SerialClob</code> object is instantiated with a <code>Clob</code> * object. If this <code>SerialClob</code> object is instantiated with * a <code>char</code> array, a <code>SerialException</code> object is thrown. * * @return a <code>java.io.InputStream</code> object containing * this <code>SerialClob</code> object's data * @throws SerialException if this {@code SerialClob} object was not * instantiated with a <code>Clob</code> object; * if {@code free} had previously been called on this object * @throws SQLException if there is an error accessing the * <code>CLOB</code> value represented by the <code>Clob</code> object * that was used to create this <code>SerialClob</code> object */ public java.io.InputStream getAsciiStream() throws SerialException, SQLException { isValid(); if (this.clob != null) { return this.clob.getAsciiStream(); } else { throw new SerialException("Unsupported operation. SerialClob cannot " + "return a the CLOB value as an ascii stream, unless instantiated " + "with a fully implemented Clob object."); } }
/** * Retrieves a stream to be used to write Ascii characters to the * <code>CLOB</code> value that this <code>SerialClob</code> object represents, * starting at position <code>pos</code>. This method forwards the * <code>setAsciiStream()</code> call to the underlying <code>Clob</code> object in * the event that this <code>SerialClob</code> object is instantiated with a * <code>Clob</code> object. If this <code>SerialClob</code> object is instantiated * with a <code>char</code> array, a <code>SerialException</code> object is thrown. * * @param pos the position at which to start writing to the * <code>CLOB</code> object * @return the stream to which ASCII encoded characters can be written * @throws SerialException if SerialClob is not instantiated with a * Clob object; * if the {@code free} method had been previously called on this object * @throws SQLException if there is an error accessing the * <code>CLOB</code> value * @see #getAsciiStream */ public java.io.OutputStream setAsciiStream(long pos) throws SerialException, SQLException { isValid(); if (this.clob != null) { return this.clob.setAsciiStream(pos); } else { throw new SerialException("Unsupported operation. SerialClob cannot " + "return a writable ascii stream\n unless instantiated with a Clob object " + "that has a setAsciiStream() implementation"); } }
isValid(); if (this.clob != null) { return this.clob.setCharacterStream(pos);
/** * Returns a {@code Reader} object that contains a partial * {@code SerialClob} value, starting * with the character specified by pos, which is length characters in length. * * @param pos the offset to the first character of the partial value to * be retrieved. The first character in the {@code SerialClob} is at position 1. * @param length the length in characters of the partial value to be retrieved. * @return {@code Reader} through which the partial {@code SerialClob} * value can be read. * @throws SQLException if pos is less than 1 or if pos is greater than the * number of characters in the {@code SerialClob} or if pos + length * is greater than the number of characters in the {@code SerialClob}; * @throws SerialException if the {@code free} method had been previously * called on this object * @since 1.6 */ public Reader getCharacterStream(long pos, long length) throws SQLException { isValid(); if (pos < 1 || pos > len) { throw new SerialException("Invalid position in Clob object set"); } if ((pos-1) + length > len) { throw new SerialException("Invalid position and substring length"); } if (length <= 0) { throw new SerialException("Invalid length specified"); } return new CharArrayReader(buf, (int)pos, (int)length); }
isValid(); String temp = str.substring(offset); char cPattern[] = temp.toCharArray();
isValid(); if (pos < 1 || pos > this.length()) { throw new SerialException("Invalid position in SerialClob object set");