1 16 package org.apache.axis.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 static final byte[] LAST_TOKEN = "0\r\n\r\n".getBytes(); 53 54 public void write(byte[] b, 55 int off, 56 int len) 57 throws IOException { 58 if (len == 0) return; 59 60 out.write((Integer.toHexString(len)).getBytes()); 61 out.write(CRLF); 62 out.write(b, off, len); 63 out.write(CRLF); 64 } 65 66 72 73 public void eos()throws IOException { 74 synchronized (this) { 75 if (eos) return; 76 eos = true; 77 } 78 out.write(LAST_TOKEN); 79 out.flush(); 80 } 81 82 public void close() 83 throws IOException { 84 eos(); 85 out.close(); 86 } 87 88 } 89 | Popular Tags |