1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
public class InputPhoto extends InputStream implements Serializable{
private byte[] data = null;
protected byte buf[];
protected int pos;
protected int mark = 0;
protected int count;
public InputPhoto(InputStream ins) throws IOException
{
List byteList = new ArrayList();
int dat = ins.read();
while (dat != -1)
{
byteList.add(new Byte((byte)dat));
dat = ins.read();
}
data = new byte[byteList.size()];
int counter = 0;
Iterator itr = byteList.iterator();
while(itr.hasNext())
{
data[counter++] = ((Byte)itr.next()).byteValue();
}
ins.close();
this.buf = this.data;
this.pos = 0;
this.count = this.buf.length;
}
public int read(byte b[]) throws IOException
{
System.err.println("read(byte b[])");
return read(b, 0, data.length);
}
public synchronized int read(byte b[], int off, int len)
{
if (b == null)
{
throw new NullPointerException();
}
else if ((off < 0) || (off > b.length) || (len < 0) ||((off + len) > b.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, b, off, len);
pos += len;
return len;
}
public synchronized int read()
{
return (pos < count) ? (buf[pos++] & 0xff) : -1;
}
public long skip(long n) throws IOException
{
System.err.println("skip(long n)");
return 0;
}
public synchronized void mark(int readlimit)
{
System.err.println("mark(int readlimit)");
}
public boolean markSupported()
{
System.err.println("markSupported()");
return false;
}
public synchronized void reset() throws IOException
{
System.err.println("reset()");
}
public void close() throws IOException
{
System.err.println("close()");
}
public synchronized int available()
{
return count - pos;
}
} |