1 22 package org.jboss.resource.adapter.jdbc.remote; 23 24 import java.io.BufferedReader ; 25 import java.io.IOException ; 26 import java.io.Reader ; 27 import java.io.Serializable ; 28 29 33 public class SerializableReader extends Reader implements Serializable 34 { 35 36 static final long serialVersionUID = 1244952470388397765L; 37 private char[] data = null; 38 39 protected char buf[]; 40 protected int pos; 41 protected int mark = 0; 42 protected int count; 43 44 public SerializableReader(Reader reader) throws IOException 45 { 46 BufferedReader in = new BufferedReader (reader); 47 String line = in.readLine(); 48 while (line != null) 49 { 50 String current = (data == null) ? "" : new String (data); 51 String newData = current + line; 52 data = newData.toCharArray(); 53 line = in.readLine(); 54 } 55 56 reader.close(); 57 58 this.buf = this.data; 59 this.pos = 0; 60 this.count = this.buf.length; 61 62 } 63 64 71 public void close() throws IOException 72 { 73 } 75 76 88 public int read(char cbuf[], int off, int len) throws IOException 89 { 90 if (cbuf == null) 91 { 92 throw new NullPointerException (); 93 } 94 else if ((off < 0) || (off > cbuf.length) || (len < 0) || 95 ((off + len) > cbuf.length) || ((off + len) < 0)) 96 { 97 throw new IndexOutOfBoundsException (); 98 } 99 100 if (pos >= count) 101 { 102 return -1; 103 } 104 if (pos + len > count) 105 { 106 len = count - pos; 107 } 108 if (len <= 0) 109 { 110 return 0; 111 } 112 System.arraycopy(buf, pos, cbuf, off, len); 113 pos += len; 114 return len; 115 } 116 117 } | Popular Tags |