public void truncate(long length) throws SQLException {
   checkValidation();
   if (length < 0) {
     throw HarmonySerialBlob.makeSQLException(
         SQLState.BLOB_NONPOSITIVE_LENGTH, new Object[] {new Long(length)});
   }
   if (length > len) {
     throw HarmonySerialBlob.makeSQLException(
         SQLState.BLOB_LENGTH_TOO_LONG, new Object[] {new Long(length)});
   }
   char[] truncatedBuffer = new char[(int) length];
   System.arraycopy(buf, 0, truncatedBuffer, 0, (int) length);
   buf = truncatedBuffer;
   len = length;
 }
 public String getSubString(long pos, int length) throws SQLException {
   checkValidation();
   if (length < 0) {
     throw HarmonySerialBlob.makeSQLException(
         SQLState.BLOB_NONPOSITIVE_LENGTH, new Object[] {new Integer(length)});
   }
   if (pos < 1 || pos > len || pos + length > len + 1) {
     throw HarmonySerialBlob.makeSQLException(
         SQLState.BLOB_BAD_POSITION, new Object[] {new Long(pos)});
   }
   try {
     return new String(buf, (int) (pos - 1), length);
   } catch (StringIndexOutOfBoundsException e) {
     throw new SQLException();
   }
 }
 public int setString(long pos, String str, int offset, int length) throws SQLException {
   checkValidation();
   if (pos < 1) {
     throw HarmonySerialBlob.makeSQLException(
         SQLState.BLOB_BAD_POSITION, new Object[] {new Long(pos)});
   }
   if (length < 0) {
     throw HarmonySerialBlob.makeSQLException(SQLState.BLOB_NONPOSITIVE_LENGTH, null);
   }
   if (pos > (len - length + 1)) {
     throw HarmonySerialBlob.makeSQLException(SQLState.BLOB_POSITION_TOO_LARGE, null);
   }
   if (offset < 0 || offset > (str.length() - length)) {
     throw HarmonySerialBlob.makeSQLException(SQLState.BLOB_INVALID_OFFSET, null);
   }
   if (length > len + offset) {
     throw HarmonySerialBlob.makeSQLException(SQLState.BLOB_INVALID_OFFSET, null);
   }
   str.getChars(offset, offset + length, buf, (int) pos - 1);
   return length;
 }
 private void checkValidation() throws SQLException {
   if (len == -1) {
     throw HarmonySerialBlob.makeSQLException(SQLState.LOB_OBJECT_INVALID, null);
   }
 }