final GrowablePipedInputStream gpis2 = new GrowablePipedInputStream(vs);
final GrowablePipedOutputStream gpos2 = new GrowablePipedOutputStream(gpis2);
final int size = 128 * 1024;
final byte[] bytesOut1 = new byte[size];
final byte[] bytesOut2 = new byte[size];
final ShrinkableByteArrayOutputStream bytesIn1 = new ShrinkableByteArrayOutputStream();
final ShrinkableByteArrayOutputStream bytesIn2 = new ShrinkableByteArrayOutputStream();
for (int i = 0; i < size; i++)
{
bytesOut1[i] = (byte) i;
bytesOut2[i] = (byte) (i+1);
}
vs.register(gpis1, new Integer(1));
vs.register(gpis2, new Integer(2));
class ThreadIn extends Thread
{
Exception e;
public void run()
{
Map readyMap;
log.info("starting run()");
try
{
while ((readyMap = vs.select()) != null)
{
log.debug("readyMap != null");
Iterator it = readyMap.keySet().iterator();
while (it.hasNext())
{
InputStream is = (InputStream) it.next();
if (is.available() == 0)
{
it.remove();
continue;
}
Integer attachment = (Integer) readyMap.get(is);
ShrinkableByteArrayOutputStream bytesIn;
if (attachment.intValue() == 1)
bytesIn = bytesIn1;
else
bytesIn = bytesIn2;
try
{
int available = is.available();
log.debug("available: " + available);
log.debug("stream: " + attachment);
for (int i = 0; i < available; i++)
bytesIn.write((byte) is.read());
}
catch (IOException e)
{
this.e = e;
}