KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > client > am > ClobWriter


1 /*
2
3    Derby - Class org.apache.derby.client.am.ClobWriter
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20 */

21
22 package org.apache.derby.client.am;
23
24 import org.apache.derby.shared.common.reference.SQLState;
25
26
27 public class ClobWriter extends java.io.Writer JavaDoc {
28     private Clob clob_;
29     private long offset_;
30
31     public ClobWriter() {
32     }
33
34     public ClobWriter(Clob clob, long offset) throws SqlException {
35         clob_ = clob;
36         offset_ = offset;
37
38         if (offset_ - 1 > clob_.sqlLength_) {
39             throw new SqlException(clob_.agent_.logWriter_,
40                 new ClientMessageId(SQLState.BLOB_INVALID_OFFSET),
41                 new Long JavaDoc(offset));
42         }
43     }
44
45     public void write(int c) {
46         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(clob_.string_.substring(0, (int) offset_ - 1));
47         sb.append((char)c);
48         clob_.string_ = sb.toString();
49         clob_.asciiStream_ = new java.io.StringBufferInputStream JavaDoc(clob_.string_);
50         clob_.unicodeStream_ = new java.io.StringBufferInputStream JavaDoc(clob_.string_);
51         clob_.characterStream_ = new java.io.StringReader JavaDoc(clob_.string_);
52         clob_.sqlLength_ = clob_.string_.length();
53         offset_ = clob_.sqlLength_ + 1;
54     }
55
56     public void write(char cbuf[], int off, int len) {
57         if ((off < 0) || (off > cbuf.length) || (len < 0) ||
58                 ((off + len) > cbuf.length) || ((off + len) < 0)) {
59             throw new IndexOutOfBoundsException JavaDoc();
60         } else if (len == 0) {
61             return;
62         }
63         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(clob_.string_.substring(0, (int) offset_ - 1));
64         sb.append(cbuf, off, len);
65         clob_.string_ = sb.toString();
66         clob_.asciiStream_ = new java.io.StringBufferInputStream JavaDoc(clob_.string_);
67         clob_.unicodeStream_ = new java.io.StringBufferInputStream JavaDoc(clob_.string_);
68         clob_.characterStream_ = new java.io.StringReader JavaDoc(clob_.string_);
69         clob_.sqlLength_ = clob_.string_.length();
70         offset_ = clob_.sqlLength_ + 1;
71     }
72
73
74     public void write(String JavaDoc str) {
75         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(clob_.string_.substring(0, (int) offset_ - 1));
76         sb.append(str);
77         clob_.string_ = sb.toString();
78         clob_.asciiStream_ = new java.io.StringBufferInputStream JavaDoc(clob_.string_);
79         clob_.unicodeStream_ = new java.io.StringBufferInputStream JavaDoc(clob_.string_);
80         clob_.characterStream_ = new java.io.StringReader JavaDoc(clob_.string_);
81         clob_.sqlLength_ = clob_.string_.length();
82         offset_ = clob_.sqlLength_ + 1;
83     }
84
85
86     public void write(String JavaDoc str, int off, int len) {
87         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(clob_.string_.substring(0, (int) offset_ - 1));
88         sb.append(str.substring(off, off + len));
89         clob_.string_ = sb.toString();
90         clob_.asciiStream_ = new java.io.StringBufferInputStream JavaDoc(clob_.string_);
91         clob_.unicodeStream_ = new java.io.StringBufferInputStream JavaDoc(clob_.string_);
92         clob_.characterStream_ = new java.io.StringReader JavaDoc(clob_.string_);
93         clob_.sqlLength_ = clob_.string_.length();
94         offset_ = clob_.sqlLength_ + 1;
95     }
96
97     public void flush() {
98     }
99
100     public void close() throws java.io.IOException JavaDoc {
101     }
102 }
103
104
Popular Tags