yacy_search_server/source/net/yacy/server/http/AugmentedHtmlStream.java
Michael Peter Christen 5f0ab25382 removed the option to prevent removal of & parts inside of the
MultiProtocolURI during normalform computation because that should
always be done and also be done during initialization of the
MultiProtocolURI Object. The new normalform method takes only one
argument which should be 'true' unless you know exactly what you are
doing.
2012-10-10 11:46:22 +02:00

65 lines
1.9 KiB
Java

package net.yacy.server.http;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.Charset;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.interaction.AugmentHtmlStream;
import net.yacy.kelondro.data.meta.DigestURI;
public class AugmentedHtmlStream extends FilterOutputStream {
private final Writer out;
private final ByteArrayOutputStream buffer;
private final Charset charset;
private final DigestURI url;
private final String urls;
private final RequestHeader requestHeader;
public AugmentedHtmlStream(OutputStream out, Charset charset, DigestURI url, RequestHeader requestHeader) {
super(out);
this.out = new BufferedWriter(new OutputStreamWriter(out, charset));
this.buffer = new ByteArrayOutputStream();
this.charset = charset;
this.url = url;
this.urls = this.url.toNormalform(false);
this.requestHeader = requestHeader;
}
@Override
public void write(int b) throws IOException {
this.buffer.write(b);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
this.buffer.write(b, off, len);
}
@Override
public void close() throws IOException {
StringBuffer b = new StringBuffer(this.buffer.toString(this.charset.name()));
b = process(b);
this.out.write(b.toString());
this.out.close();
}
public StringBuffer process(StringBuffer data) {
if (this.urls.contains("currentyacypeer/")) {
return data;
}
return AugmentHtmlStream.process(data, this.url, this.requestHeader);
}
public static boolean supportsMime(String mime) {
// System.out.println("mime" +mime);
return mime.split(";")[0].equals("text/html");
}
}