1 package org.objectweb.celtix.bus.transports.http.protocol.pipe; 2 3 import java.io.IOException ; 4 import java.io.InputStream ; 5 import java.io.OutputStream ; 6 import java.io.PipedInputStream ; 7 import java.io.PipedOutputStream ; 8 import java.net.URLConnection ; 9 import java.util.List ; 10 import java.util.Map ; 11 12 public class PipeResponse { 13 Map <String , List <String >> reqHeaders; 14 InputStream reqIn; 15 URLConnection connection; 16 17 Map <String , List <String >> headers; 18 InputStream in; 19 OutputStream pout; 20 21 public PipeResponse(URLConnection con, 22 InputStream in2, 23 Map <String , List <String >> requestHeaders) { 24 connection = con; 25 reqIn = in2; 26 reqHeaders = requestHeaders; 27 } 28 public URLConnection getURLConnection() { 29 return connection; 30 } 31 public Map <String , List <String >> getRequestHeaders() { 32 return reqHeaders; 33 } 34 public InputStream getRequestInputStream() { 35 return reqIn; 36 } 37 38 public OutputStream setResponse(Map <String , List <String >> h) throws IOException { 39 synchronized (this) { 40 PipedInputStream pin = new BiggerPipeInputStream(); 41 pout = new PipedOutputStream (pin); 42 headers = h; 43 in = pin; 44 notifyAll(); 45 return pout; 46 } 47 } 48 public OutputStream getOutputStream() { 49 return pout; 50 } 51 52 public Map <String , List <String >> getResponseHeaders(int timeout) 53 throws IOException { 54 synchronized (this) { 55 if (headers == null) { 56 try { 57 wait(timeout); 58 } catch (InterruptedException e) { 59 } 61 if (headers == null) { 62 throw new IOException ("Timeout getting response"); 63 } 64 } 65 return headers; 66 } 67 } 68 69 public InputStream getInputStream(int timeout) throws IOException { 70 getResponseHeaders(timeout); 71 return in; 72 } 73 74 75 private static class BiggerPipeInputStream extends PipedInputStream { 76 BiggerPipeInputStream() { 77 super(); 78 buffer = new byte[PIPE_SIZE * 4]; 79 } 80 } 81 } 82 83 | Popular Tags |