1 21 22 package org.apache.derby.client.am; 23 24 25 public class BlobOutputStream extends java.io.OutputStream { 26 private Blob blob_; 27 private long offset_; 28 29 public BlobOutputStream(Blob blob, long offset) { 30 blob_ = blob; 31 offset_ = offset; 32 33 37 if ((offset_-1) > (blob_.binaryString_.length - blob_.dataOffset_)) { 38 throw new IndexOutOfBoundsException (); 39 } 40 } 41 42 public void write(int b) throws java.io.IOException { 43 44 byte[] newbuf = new byte[(int) offset_ + blob_.dataOffset_]; 45 System.arraycopy(blob_.binaryString_, 0, newbuf, 0, (int) offset_ - 1 + blob_.dataOffset_); 46 blob_.binaryString_ = newbuf; 47 blob_.binaryString_[(int) offset_ + blob_.dataOffset_ - 1] = (byte) b; 48 blob_.binaryStream_ = new java.io.ByteArrayInputStream (blob_.binaryString_); 49 blob_.sqlLength_ = blob_.binaryString_.length - blob_.dataOffset_; 50 offset_++; 51 } 52 53 public void write(byte b[], int off, int len) throws java.io.IOException { 54 if (b == null) { 55 throw new NullPointerException (); 56 } else if ((off < 0) || (off > b.length) || (len < 0) || 57 ((off + len) > b.length) || ((off + len) < 0)) { 58 throw new IndexOutOfBoundsException (); 59 } else if (len == 0) { 60 return; 61 } 62 byte[] newbuf = new byte[(int) offset_ - 1 + len + blob_.dataOffset_]; 63 System.arraycopy(blob_.binaryString_, 0, newbuf, 0, (int) offset_ - 1 + blob_.dataOffset_); 64 blob_.binaryString_ = newbuf; 65 for (int i = 0; i < len; i++, offset_++) { 66 blob_.binaryString_[(int) offset_ + blob_.dataOffset_ - 1] = b[off + i]; 67 } 68 blob_.binaryStream_ = new java.io.ByteArrayInputStream (blob_.binaryString_); 69 blob_.sqlLength_ = blob_.binaryString_.length - blob_.dataOffset_; 70 } 71 } 72 73 | Popular Tags |