1 21 22 package org.apache.derby.client.am; 23 24 25 public class ClobOutputStream extends java.io.OutputStream { 26 private Clob clob_; 27 private long offset_; 28 29 public ClobOutputStream(Clob clob, long offset) throws SqlException { 30 clob_ = clob; 31 offset_ = offset; 32 33 38 if ((offset_-1) > clob_.sqlLength_) { 39 throw new IndexOutOfBoundsException (); 40 } 41 } 42 43 public void write(int b) throws java.io.IOException { 44 byte[] newByte = new byte[1]; 45 newByte[0] = (byte)b; 46 clob_.string_ = clob_.string_.substring(0, (int) offset_ - 1); 47 clob_.string_ = clob_.string_.concat(new String (newByte, "US-ASCII")); 50 clob_.asciiStream_ = new java.io.StringBufferInputStream (clob_.string_); 51 clob_.unicodeStream_ = new java.io.StringBufferInputStream (clob_.string_); 52 clob_.characterStream_ = new java.io.StringReader (clob_.string_); 53 clob_.sqlLength_ = clob_.string_.length(); 54 offset_++; 55 } 56 57 58 public void write(byte b[], int off, int len) throws java.io.IOException { 59 if (b == null) { 60 throw new NullPointerException (); 61 } else if ((off < 0) || (off > b.length) || (len < 0) || 62 ((off + len) > b.length) || ((off + len) < 0)) { 63 throw new IndexOutOfBoundsException (); 64 } else if (len == 0) { 65 return; 66 } 67 68 byte[] newByte = new byte[len]; 69 System.arraycopy(b, off, newByte, 0, len); 70 String str = new String (newByte, "US-ASCII"); 73 clob_.string_ = clob_.string_.substring(0, (int) offset_ - 1); 74 clob_.string_ = clob_.string_.concat(str); 75 clob_.asciiStream_ = new java.io.StringBufferInputStream (clob_.string_); 76 clob_.unicodeStream_ = new java.io.StringBufferInputStream (clob_.string_); 77 clob_.characterStream_ = new java.io.StringReader (clob_.string_); 78 clob_.sqlLength_ = clob_.string_.length(); 79 offset_ += len; 80 } 81 } 82 83 | Popular Tags |