Esempio n. 1
0
 /**
  * Return a character from the specified index.
  *
  * @param index the position from which to return a character
  * @return a character
  * @throws IndexOutOfBoundsException if the index argument is negative or not less than length()
  */
 public char charAt(int index) {
   init();
   if (index < 0) {
     throw new IndexOutOfBoundsException("index is less than zero");
   }
   if (index >= length) {
     throw new IndexOutOfBoundsException("index is not less than length");
   }
   int page = index / CLOB_PAGE_SIZE;
   String pageText = (String) results.get(page);
   return pageText.charAt(index - page * CLOB_PAGE_SIZE);
 }
Esempio n. 2
0
 /**
  * Sends the entire contents of the Clob into the given PrintStream. This method should be used in
  * preference to toString() in order to save memory with large Clobs.
  *
  * @param out a PrintStream to write the Clob value to
  */
 public void drainToPrintStream(PrintStream out) {
   init();
   int lowestPage = offset / CLOB_PAGE_SIZE;
   int highestPage = (offset + length - 1) / CLOB_PAGE_SIZE;
   for (int page = lowestPage; page <= highestPage; page++) {
     String pageText = (String) results.get(page);
     if (page == highestPage) {
       pageText = pageText.substring(0, offset + length - page * CLOB_PAGE_SIZE);
     }
     if (page == lowestPage) {
       pageText = pageText.substring(offset - page * CLOB_PAGE_SIZE, pageText.length());
     }
     out.print(pageText);
   }
 }
Esempio n. 3
0
 /**
  * Returns a new CharSequence that is a subsequence of this sequence, from start (inclusive) to
  * end (exclusive).
  *
  * @param start the start index, inclusive
  * @param end the end index, exclusive
  * @return the specified sequence
  * @throws IndexOutOfBoundsException if the start or end are negative, if end is greater than
  *     length(), or if start is greater than end
  */
 public ClobAccess subSequence(int start, int end) {
   init();
   if (start < 0) {
     throw new IndexOutOfBoundsException("start is less than zero");
   }
   if (end > length) {
     throw new IndexOutOfBoundsException("end is greater than the length of this Clob");
   }
   if (end < start) {
     throw new IndexOutOfBoundsException("end is less than start");
   }
   if ((start == 0) && (end == length)) {
     return this;
   }
   return new ClobAccess(results, clob, start + offset, end - start);
 }
Esempio n. 4
0
  /**
   * Converts the Clob into a String. Be careful that it can fit in memory!
   *
   * @return a String
   */
  @Override
  public String toString() {
    init();
    StringBuilder retval = new StringBuilder();

    if (length > 0) {
      int lowestPage = offset / CLOB_PAGE_SIZE;
      int highestPage = (offset + length - 1) / CLOB_PAGE_SIZE;
      for (int page = lowestPage; page <= highestPage; page++) {
        String pageText = (String) results.get(page);
        if (page == highestPage) {
          pageText = pageText.substring(0, offset + length - page * CLOB_PAGE_SIZE);
        }
        if (page == lowestPage) {
          pageText = pageText.substring(offset - page * CLOB_PAGE_SIZE, pageText.length());
        }
        retval.append(pageText);
      }
    }
    return retval.toString();
  }
Esempio n. 5
0
 /**
  * Returns the length of this character sequence.
  *
  * @return the number of chars in this sequence
  */
 public int length() {
   init();
   return length;
 }