1 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 { 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 (offset)); 42 } 43 } 44 45 public void write(int c) { 46 StringBuffer sb = new StringBuffer (clob_.string_.substring(0, (int) offset_ - 1)); 47 sb.append((char)c); 48 clob_.string_ = sb.toString(); 49 clob_.asciiStream_ = new java.io.StringBufferInputStream (clob_.string_); 50 clob_.unicodeStream_ = new java.io.StringBufferInputStream (clob_.string_); 51 clob_.characterStream_ = new java.io.StringReader (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 (); 60 } else if (len == 0) { 61 return; 62 } 63 StringBuffer sb = new StringBuffer (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 (clob_.string_); 67 clob_.unicodeStream_ = new java.io.StringBufferInputStream (clob_.string_); 68 clob_.characterStream_ = new java.io.StringReader (clob_.string_); 69 clob_.sqlLength_ = clob_.string_.length(); 70 offset_ = clob_.sqlLength_ + 1; 71 } 72 73 74 public void write(String str) { 75 StringBuffer sb = new StringBuffer (clob_.string_.substring(0, (int) offset_ - 1)); 76 sb.append(str); 77 clob_.string_ = sb.toString(); 78 clob_.asciiStream_ = new java.io.StringBufferInputStream (clob_.string_); 79 clob_.unicodeStream_ = new java.io.StringBufferInputStream (clob_.string_); 80 clob_.characterStream_ = new java.io.StringReader (clob_.string_); 81 clob_.sqlLength_ = clob_.string_.length(); 82 offset_ = clob_.sqlLength_ + 1; 83 } 84 85 86 public void write(String str, int off, int len) { 87 StringBuffer sb = new StringBuffer (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 (clob_.string_); 91 clob_.unicodeStream_ = new java.io.StringBufferInputStream (clob_.string_); 92 clob_.characterStream_ = new java.io.StringReader (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 { 101 } 102 } 103 104 | Popular Tags |