1 55 package org.jboss.axis.transport.http; 56 57 58 import java.io.FilterOutputStream ; 59 import java.io.IOException ; 60 import java.io.OutputStream ; 61 62 63 66 public class ChunkedOutputStream extends FilterOutputStream 67 { 68 69 boolean eos = false; 70 71 private ChunkedOutputStream() 72 { 73 super(null); 74 } 75 76 public ChunkedOutputStream(OutputStream os) 77 { 78 super(os); 79 } 80 81 public void write(int b) 82 throws IOException 83 { 84 write(new byte[]{(byte)b}, 0, 1); 85 } 86 87 public void write(byte[] b) 88 89 throws IOException 90 { 91 write(b, 0, b.length); 92 } 93 94 static final byte[] crlf = "\r\n".getBytes(); 95 96 public void write(byte[] b, 97 int off, 98 int len) 99 throws IOException 100 { 101 if (len == 0) return; 102 103 out.write((Integer.toHexString(len)).getBytes()); 104 out.write(crlf); 105 out.write(b, off, len); 106 out.write(crlf); 107 } 108 109 115 116 public void eos() throws IOException 117 { 118 synchronized (this) 119 { 120 if (eos) return; 121 eos = true; 122 } 123 out.write("0\r\n\r\n".getBytes()); 124 out.flush(); 125 } 126 127 public void close() 128 throws IOException 129 { 130 eos(); 131 out.close(); 132 } 133 134 } 135 | Popular Tags |