mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-21 00:00:13 +02:00
7b0b72dd23
- implementation of outgoing chunked transfer encoding (httpChunkedOutputStream.java) - byte counting for proxy access logging / global traffic count (httpdByteCount(In|Out)putStream.java git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@241 6c8d7289-2bf4-0310-a012-ef5d649a1542
61 lines
1.8 KiB
Java
61 lines
1.8 KiB
Java
package de.anomic.http;
|
|
|
|
import java.io.FilterOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.OutputStream;
|
|
|
|
final class httpChunkedOutputStream extends FilterOutputStream
|
|
{
|
|
private boolean finished = false;
|
|
private static final byte[] crlf = {(byte)13,(byte)10};
|
|
|
|
public httpChunkedOutputStream(OutputStream out) {
|
|
super(out);
|
|
}
|
|
|
|
public void close() throws IOException {
|
|
if (!this.finished) this.finish();
|
|
this.out.close();
|
|
}
|
|
|
|
public void finish() throws IOException {
|
|
if (!this.finished) {
|
|
this.out.write("0\r\n\r\n".getBytes());
|
|
this.out.flush();
|
|
this.finished = true;
|
|
}
|
|
}
|
|
|
|
public void write(byte[] b) throws IOException {
|
|
if (this.finished) throw new IOException("ChunkedOutputStream already finalized.");
|
|
if (b.length == 0) return;
|
|
|
|
this.out.write(Integer.toHexString(b.length).getBytes());
|
|
this.out.write(crlf);
|
|
this.out.write(b);
|
|
this.out.write(crlf);
|
|
this.out.flush();
|
|
}
|
|
|
|
public void write(byte[] b, int off, int len) throws IOException {
|
|
if (this.finished) throw new IOException("ChunkedOutputStream already finalized.");
|
|
if (len == 0) return;
|
|
|
|
this.out.write(Integer.toHexString(len).getBytes());
|
|
this.out.write(crlf);
|
|
this.out.write(b, off, len);
|
|
this.out.write(crlf);
|
|
this.out.flush();
|
|
}
|
|
|
|
public void write(int b) throws IOException {
|
|
if (this.finished) throw new IOException("ChunkedOutputStream already finalized.");
|
|
|
|
this.out.write("1".getBytes());
|
|
this.out.write(crlf);
|
|
this.out.write(b);
|
|
this.out.write(crlf);
|
|
this.out.flush();
|
|
}
|
|
}
|