1 16 package org.apache.axis2.transport.http; 17 18 19 import java.io.FilterOutputStream ; 20 import java.io.IOException ; 21 import java.io.OutputStream ; 22 23 24 28 public class ChunkedOutputStream extends FilterOutputStream { 29 30 boolean eos = false; 31 32 private ChunkedOutputStream() { 33 super(null); 34 } 35 36 public ChunkedOutputStream(OutputStream os) { 37 super(os); 38 } 39 40 public void write(int b) 41 throws IOException { 42 write(new byte[] {(byte) b}, 0, 1); 43 } 44 45 public void write(byte[] b) 46 47 throws IOException { 48 write(b, 0, b.length); 49 } 50 51 static final byte[] crlf = "\r\n".getBytes(); 52 53 public void write(byte[] b, 54 int off, 55 int len) 56 throws IOException { 57 if (len == 0) return; 58 59 out.write((Integer.toHexString(len)).getBytes()); 60 out.write(crlf); 61 out.write(b, off, len); 62 out.write(crlf); 63 } 64 65 71 72 public void eos()throws IOException { 73 synchronized (this) { 74 if (eos) return; 75 eos = true; 76 } 77 out.write("0\r\n\r\n".getBytes()); 78 out.flush(); 79 } 80 81 public void close() 82 throws IOException { 83 eos(); 84 out.close(); 85 } 86 87 } 88 | Popular Tags |