package org.jboss.resource.adapter.jdbc.remote;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.io.Serializable;
public class SerializableReader extends Reader implements Serializable
{
static final long serialVersionUID = 1244952470388397765L;
private char[] data = null;
protected char buf[];
protected int pos;
protected int mark = 0;
protected int count;
public SerializableReader(Reader reader) throws IOException
{
BufferedReader in = new BufferedReader(reader);
String line = in.readLine();
while (line != null)
{
String current = (data == null) ? "" : new String(data);
String newData = current + line;
data = newData.toCharArray();
line = in.readLine();
}
reader.close();
this.buf = this.data;
this.pos = 0;
this.count = this.buf.length;
}
public void close() throws IOException
{
}
public int read(char cbuf[], int off, int len) throws IOException
{
if (cbuf == null)
{
throw new NullPointerException();
}
else if ((off < 0) || (off > cbuf.length) || (len < 0) ||
((off + len) > cbuf.length) || ((off + len) < 0))
{
throw new IndexOutOfBoundsException();
}
if (pos >= count)
{
return -1;
}
if (pos + len > count)
{
len = count - pos;
}
if (len <= 0)
{
return 0;
}
System.arraycopy(buf, pos, cbuf, off, len);
pos += len;
return len;
}
}