1 22 package org.jboss.resource.adapter.jdbc.remote; 23 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.io.Serializable ; 27 import java.util.ArrayList ; 28 import java.util.List ; 29 import java.util.Iterator ; 30 31 35 public class SerializableInputStream extends InputStream implements Serializable 36 { 37 38 static final long serialVersionUID = 3364193722688048342L; 39 40 private byte[] data = null; 41 42 protected byte buf[]; 43 protected int pos; 44 protected int mark = 0; 45 protected int count; 46 47 48 public SerializableInputStream(InputStream ins) throws IOException 49 { 50 List byteList = new ArrayList (); 51 int dat = ins.read(); 52 while (dat != -1) 53 { 54 byteList.add(new Byte ((byte)dat)); 55 dat = ins.read(); 56 } 57 58 data = new byte[byteList.size()]; 59 int counter = 0; 60 Iterator itr = byteList.iterator(); 61 while(itr.hasNext()) 62 { 63 data[counter++] = ((Byte )itr.next()).byteValue(); 64 } 65 ins.close(); 66 this.buf = this.data; 67 this.pos = 0; 68 this.count = this.buf.length; 69 70 } 71 72 86 public synchronized int available() 87 { 88 return count - pos; 89 } 90 91 100 public void close() throws IOException 101 { 102 System.err.println("close()"); 103 } 104 105 150 public synchronized void reset() throws IOException 151 { 152 System.err.println("reset()"); 153 } 154 155 167 public boolean markSupported() 168 { 169 System.err.println("markSupported()"); 170 return false; 171 } 172 173 197 public synchronized void mark(int readlimit) 198 { 199 System.err.println("mark(int readlimit)"); 200 } 201 202 220 public long skip(long n) throws IOException 221 { 222 System.err.println("skip(long n)"); 223 return 0; 224 } 225 226 263 public int read(byte b[]) throws IOException 264 { 265 System.err.println("read(byte b[])"); 266 return read(b, 0, data.length); 267 } 268 269 330 public synchronized int read(byte b[], int off, int len) 331 { 332 if (b == null) 333 { 334 throw new NullPointerException (); 335 } 336 else if ((off < 0) || (off > b.length) || (len < 0) || 337 ((off + len) > b.length) || ((off + len) < 0)) 338 { 339 throw new IndexOutOfBoundsException (); 340 } 341 if (pos >= count) 342 { 343 return -1; 344 } 345 if (pos + len > count) 346 { 347 len = count - pos; 348 } 349 if (len <= 0) 350 { 351 return 0; 352 } 353 System.arraycopy(buf, pos, b, off, len); 354 pos += len; 355 return len; 356 } 357 358 371 public synchronized int read() 372 { 373 return (pos < count) ? (buf[pos++] & 0xff) : -1; 374 } 375 } 376 | Popular Tags |