1 31 32 package org.apache.commons.httpclient.server; 33 34 import java.io.InputStream ; 35 import java.io.OutputStream ; 36 37 44 class BidiStreamProxy { 45 private StreamProxy leftToRight, rightToLeft; 46 private int state = 0; 47 48 55 public BidiStreamProxy(InputStream leftIn, OutputStream leftOut, InputStream rightIn, OutputStream rightOut) { 56 leftToRight = new StreamProxy(leftIn, rightOut); 57 rightToLeft = new StreamProxy(rightIn, leftOut); 58 } 59 60 64 public synchronized void start() { 65 if (state != 0) throw new IllegalStateException ("Can not start twice"); 66 leftToRight.start(); 67 rightToLeft.start(); 68 state = 1; 69 } 70 71 75 public synchronized void abort() { 76 if (leftToRight != null) leftToRight.abort(); 77 if (rightToLeft != null) rightToLeft.abort(); 78 leftToRight = null; 79 rightToLeft = null; 80 } 81 82 87 public void block() throws InterruptedException { 88 if (state != 1) throw new IllegalStateException ("Can not block before started"); 89 leftToRight.block(); 90 rightToLeft.block(); 91 } 92 } 93 | Popular Tags |