1 10 11 package org.mule.impl; 12 13 import org.apache.commons.io.output.ByteArrayOutputStream; 14 15 import java.io.BufferedOutputStream ; 16 import java.io.IOException ; 17 import java.io.OutputStream ; 18 import java.net.Socket ; 19 20 29 30 public class ResponseOutputStream extends BufferedOutputStream 31 { 32 private static ByteArrayOutputStream defaultStream = new ByteArrayOutputStream(); 33 34 private boolean used = false; 35 private boolean isDefault = false; 36 private Socket socket = null; 37 38 public ResponseOutputStream() 39 { 40 super(defaultStream); 41 isDefault = true; 42 } 43 44 public ResponseOutputStream(OutputStream stream) 45 { 46 super(stream); 47 } 48 49 public ResponseOutputStream(OutputStream stream, Socket socket) 50 { 51 super(stream); 52 this.socket = socket; 53 } 54 55 public void write(int b) throws IOException 56 { 57 super.write(b); 58 used = true; 59 } 60 61 public byte[] getBytes() throws IOException 62 { 63 if (isDefault) 64 { 65 flush(); 66 return defaultStream.toByteArray(); 67 } 68 return null; 69 } 70 71 public boolean isUsed() 72 { 73 return used; 74 } 75 76 public Socket getSocket() 77 { 78 return socket; 79 } 80 } 81 | Popular Tags |