コード例 #1
0
ファイル: ClobAccess.java プロジェクト: elcovi/modmine
 /**
  * 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);
 }
コード例 #2
0
ファイル: ClobAccess.java プロジェクト: elcovi/modmine
 /**
  * Initialises the state of this object. This is done lazily, because it requires the use of a
  * database connection to discover the length of the clob, and that cannot be done while inside
  * the ObjectStoreWriter while it has exclusive use of the connection.
  */
 protected void init() {
   if (results == null) {
     Query q = new Query();
     q.addToSelect(clob);
     results = os.executeSingleton(q, 20, false, false, true);
     int pageCount = results.size();
     if (pageCount == 0) {
       length = 0;
     } else {
       String lastPage = (String) results.get(pageCount - 1);
       length = CLOB_PAGE_SIZE * (pageCount - 1) + lastPage.length();
     }
   }
 }
コード例 #3
0
ファイル: ClobAccess.java プロジェクト: elcovi/modmine
 /**
  * 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);
   }
 }
コード例 #4
0
ファイル: ClobAccess.java プロジェクト: elcovi/modmine
  /**
   * 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();
  }