001: /*
002:
003: Derby - Class org.apache.derby.client.am.ClobWriter
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.client.am;
023:
024: import org.apache.derby.shared.common.reference.SQLState;
025:
026: public class ClobWriter extends java.io.Writer {
027: private Clob clob_;
028: private long offset_;
029:
030: public ClobWriter() {
031: }
032:
033: public ClobWriter(Clob clob, long offset) throws SqlException {
034: clob_ = clob;
035: offset_ = offset;
036:
037: if (offset_ - 1 > clob_.sqlLength_) {
038: throw new SqlException(clob_.agent_.logWriter_,
039: new ClientMessageId(SQLState.BLOB_INVALID_OFFSET),
040: new Long(offset));
041: }
042: }
043:
044: public void write(int c) {
045: StringBuffer sb = new StringBuffer(clob_.string_.substring(0,
046: (int) offset_ - 1));
047: sb.append((char) c);
048: clob_.string_ = sb.toString();
049: clob_.asciiStream_ = new java.io.StringBufferInputStream(
050: clob_.string_);
051: clob_.unicodeStream_ = new java.io.StringBufferInputStream(
052: clob_.string_);
053: clob_.characterStream_ = new java.io.StringReader(clob_.string_);
054: clob_.sqlLength_ = clob_.string_.length();
055: offset_ = clob_.sqlLength_ + 1;
056: }
057:
058: public void write(char cbuf[], int off, int len) {
059: if ((off < 0) || (off > cbuf.length) || (len < 0)
060: || ((off + len) > cbuf.length) || ((off + len) < 0)) {
061: throw new IndexOutOfBoundsException();
062: } else if (len == 0) {
063: return;
064: }
065: StringBuffer sb = new StringBuffer(clob_.string_.substring(0,
066: (int) offset_ - 1));
067: sb.append(cbuf, off, len);
068: clob_.string_ = sb.toString();
069: clob_.asciiStream_ = new java.io.StringBufferInputStream(
070: clob_.string_);
071: clob_.unicodeStream_ = new java.io.StringBufferInputStream(
072: clob_.string_);
073: clob_.characterStream_ = new java.io.StringReader(clob_.string_);
074: clob_.sqlLength_ = clob_.string_.length();
075: offset_ = clob_.sqlLength_ + 1;
076: }
077:
078: public void write(String str) {
079: StringBuffer sb = new StringBuffer(clob_.string_.substring(0,
080: (int) offset_ - 1));
081: sb.append(str);
082: clob_.string_ = sb.toString();
083: clob_.asciiStream_ = new java.io.StringBufferInputStream(
084: clob_.string_);
085: clob_.unicodeStream_ = new java.io.StringBufferInputStream(
086: clob_.string_);
087: clob_.characterStream_ = new java.io.StringReader(clob_.string_);
088: clob_.sqlLength_ = clob_.string_.length();
089: offset_ = clob_.sqlLength_ + 1;
090: }
091:
092: public void write(String str, int off, int len) {
093: StringBuffer sb = new StringBuffer(clob_.string_.substring(0,
094: (int) offset_ - 1));
095: sb.append(str.substring(off, off + len));
096: clob_.string_ = sb.toString();
097: clob_.asciiStream_ = new java.io.StringBufferInputStream(
098: clob_.string_);
099: clob_.unicodeStream_ = new java.io.StringBufferInputStream(
100: clob_.string_);
101: clob_.characterStream_ = new java.io.StringReader(clob_.string_);
102: clob_.sqlLength_ = clob_.string_.length();
103: offset_ = clob_.sqlLength_ + 1;
104: }
105:
106: public void flush() {
107: }
108:
109: public void close() throws java.io.IOException {
110: }
111: }
|