1 /* Written and copyright 2001-2003 Benjamin Kohl.
\r
2 * Distributed under the GNU General Public License; see the README file.
\r
3 * This code comes with NO WARRANTY.
\r
6 import java.io.BufferedInputStream;
\r
7 import java.io.BufferedOutputStream;
\r
8 import java.io.IOException;
\r
10 File: Jhttpp2Read.java
\r
11 reads from a Jhttpp2ClientInputStream and writes to the BufferedOutputStream
\r
13 @author Benjamin Kohl
\r
15 public class Jhttpp2Read extends Thread
\r
17 private final int BUFFER_SIZE;
\r
18 private BufferedInputStream in;
\r
19 private BufferedOutputStream out;
\r
20 private Jhttpp2HTTPSession connection;
\r
21 private Jhttpp2Server server;
\r
23 public Jhttpp2Read(Jhttpp2Server server,Jhttpp2HTTPSession connection,BufferedInputStream l_in, BufferedOutputStream l_out) {
\r
27 this.connection=connection;
\r
34 private void read() {
\r
36 byte[] buf=new byte[BUFFER_SIZE];
\r
39 bytes_read=in.read(buf);
\r
40 if (bytes_read!=-1) {
\r
41 out.write(buf,0,bytes_read);
\r
43 server.addBytesRead(bytes_read);
\r
46 if (connection.getStatus()!=connection.SC_CONNECTING_TO_HOST) // *uaaahhh*: fixes a very strange bug
\r
47 connection.getLocalSocket().close();
\r
48 // why? If we are connecting to a new host (and this thread is already running!) , the upstream
\r
49 // socket will be closed. So we get here and close our own downstream socket..... and the browser
\r
50 // displays an empty page because jhttpp2
\r
51 // closes the connection..... so close the downstream socket only when NOT connecting to a new host....
\r
53 public void close() {
\r