Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
- fixed POST in proxy - prepared http connection tracking - refactoring (mainly moving StreamTools to serverFileUtils)
danielrd96e2badc73b
diff --git a/htroot/Connections_p.html b/htroot/Connections_p.htmlindex 47e3abd93..7565e85df 100644--- a/htroot/Connections_p.html+++ b/htroot/Connections_p.html@@ -36,7 +36,7 @@</table><h3>Outgoing Connections</h3>- <p><strong>Currently not available!</strong></p>+ <p><strong>Details currently not available!</strong></p><p>Showing #[clientActive]# active outgoing connections:</p><table border="0" cellpadding="2" cellspacing="1"><tr class="TableHeader" valign="bottom">diff --git a/htroot/Connections_p.java b/htroot/Connections_p.javaindex 4357114e0..879425bf4 100644--- a/htroot/Connections_p.java+++ b/htroot/Connections_p.java@@ -51,6 +51,8 @@ import java.net.InetAddress;import java.net.URLEncoder;import java.util.Properties;+import de.anomic.http.HttpConnectionInfo;+import de.anomic.http.JakartaCommonsHttpClient;import de.anomic.http.httpHeader;import de.anomic.http.httpd;import de.anomic.plasma.plasmaSwitchboard;@@ -227,24 +229,21 @@ public final class Connections_p {prop.putNum("numActivePending", numActivePending);// client sessions- // FIXME track connections of JakartaCommons Connection Manager-// httpc[] a = httpc.allConnections();+ HttpConnectionInfo[] a = JakartaCommonsHttpClient.allConnections();+ // TODO sorting// Arrays.sort(a, httpc.connectionTimeComparatorInstance);int c = 0;-// for (int i = 0; i < a.length; i++) {-// httpc clientConnection = a[i];-// if (clientConnection != null) {-// prop.put("clientList_" + c + "_clientProtocol", (clientConnection.ssl) ? "HTTPS" : "HTTP");-// prop.putNum("clientList_" + c + "_clientLifetime", System.currentTimeMillis() - clientConnection.initTime);-// prop.putNum("clientList_" + c + "_clientIdletime", System.currentTimeMillis() - clientConnection.lastIO);-// prop.put("clientList_" + c + "_clientTargetHost", clientConnection.adressed_host + ":" + clientConnection.adressed_port);-// prop.putHTML("clientList_" + c + "_clientCommand", (clientConnection.command == null) ? "-" : clientConnection.command);-// prop.put("clientList_" + c + "_clientID", clientConnection.hashCode());-// c++;-// }-// }+ for (HttpConnectionInfo conInfo: a) {+ prop.put("clientList_" + c + "_clientProtocol", conInfo.getProtocol());+ prop.putNum("clientList_" + c + "_clientLifetime", conInfo.getLifetime());+ prop.putNum("clientList_" + c + "_clientIdletime", conInfo.getIdletime());+ prop.put("clientList_" + c + "_clientTargetHost", conInfo.getTargetHost());+ prop.putHTML("clientList_" + c + "_clientCommand", conInfo.getCommand());+ prop.put("clientList_" + c + "_clientID", conInfo.getID());+ c++;+ }prop.put("clientList", c);- prop.put("clientActive", c);+ prop.put("clientActive", JakartaCommonsHttpClient.connectionCount());// return rewrite values for templatesreturn prop;diff --git a/source/de/anomic/htmlFilter/htmlFilterWriter.java b/source/de/anomic/htmlFilter/htmlFilterWriter.javaindex 967998b69..e0e43cbf5 100644--- a/source/de/anomic/htmlFilter/htmlFilterWriter.java+++ b/source/de/anomic/htmlFilter/htmlFilterWriter.java@@ -314,7 +314,7 @@ public final class htmlFilterWriter extends Writer {}public void write(int c) throws IOException {-// System.out.println((char) b);+// System.out.println((char) c);if ((binaryUnsuspect) && (binaryHint((char)c))) {binaryUnsuspect = false;if (passbyIfBinarySuspect) finalize();@@ -489,10 +489,10 @@ public final class htmlFilterWriter extends Writer {// if (transformer != null) {transformer.close(); transformer = null;}}- private static boolean binaryHint(char c) {+ private static boolean binaryHint(final char c) {// space, punctiation and symbols, letters and digits (ASCII/latin)//if (c >= 31 && c < 128) return false;- if(c >= 31) return false;+ if(c > 31) return false;// 8 = backspace// 9 = horizontal tab// 10 = new line (line feed)diff --git a/source/de/anomic/http/HttpConnectionInfo.java b/source/de/anomic/http/HttpConnectionInfo.javanew file mode 100644index 000000000..5f5459655--- /dev/null+++ b/source/de/anomic/http/HttpConnectionInfo.java@@ -0,0 +1,114 @@+// HttpConnectionInfo.java+// (C) 2008 by Daniel Raap; [email protected]+// first published 07.04.2008 on http://yacy.net+//+// This is a part of YaCy, a peer-to-peer based web search engine+//+// $LastChangedDate: 2008-03-14 01:16:04 +0100 (Fr, 14 Mrz 2008) $+// $LastChangedRevision: 4558 $+// $LastChangedBy: orbiter $+//+// LICENSE+//+// This program is free software; you can redistribute it and/or modify+// it under the terms of the GNU General Public License as published by+// the Free Software Foundation; either version 2 of the License, or+// (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU General Public License for more details.+//+// You should have received a copy of the GNU General Public License+// along with this program; if not, write to the Free Software+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA++package de.anomic.http;++import org.apache.commons.httpclient.HttpConnection;++/**+ * Information about a connection+ *+ * @author daniel+ * @since 07.04.2008+ */+public class HttpConnectionInfo {+ private final String protocol;+ private final String targetHost;+ private final String command;+ private final int id;+ private final long initTime;++ /**+ * constructor using org.apache.commons.httpclient.HttpConnection+ *+ * @param connection+ */+ public HttpConnectionInfo(final HttpConnection connection) {+ this(connection.getProtocol().toString(), ((connection.getPort() == 80) ? connection.getHost()+ : connection.getHost() + ":" + connection.getPort()), "unknown command", connection.hashCode(),+ System.currentTimeMillis());+ }++ /**+ * constructor setting all data+ *+ * @param protocol+ * @param targetHost+ * @param command+ * @param id+ * @param initTime+ */+ public HttpConnectionInfo(final String protocol, final String targetHost, final String command, final int id,+ final long initTime) {+ this.protocol = protocol;+ this.targetHost = targetHost;+ this.command = command;+ this.id = id;+ this.initTime = initTime;+ }++ /**+ * @return+ */+ public String getProtocol() {+ return protocol;+ }++ /**+ * @return+ */+ public long getLifetime() {+ return System.currentTimeMillis() - initTime;+ }++ /**+ * @return+ */+ public int getIdletime() {+ return 0;+ }++ /**+ * @return+ */+ public String getCommand() {+ return command;+ }++ /**+ * @return+ */+ public String getTargetHost() {+ return targetHost;+ }++ /**+ * @return+ */+ public int getID() {+ return id;+ }+}diff --git a/source/de/anomic/http/HttpResponse.java b/source/de/anomic/http/HttpResponse.javaindex a1d2cbd6a..dbb3e5d94 100644--- a/source/de/anomic/http/HttpResponse.java+++ b/source/de/anomic/http/HttpResponse.java@@ -32,7 +32,7 @@ import java.io.OutputStreamWriter;import java.io.UnsupportedEncodingException;import java.io.Writer;-import de.anomic.tools.StreamTools;+import de.anomic.server.serverFileUtils;/*** @author daniel@@ -108,12 +108,12 @@ public interface HttpResponse {if (hfos instanceof OutputStream) {OutputStream[] streams = (byteStream == null ? new OutputStream[] { (OutputStream) hfos }: new OutputStream[] { (OutputStream) hfos, byteStream });- StreamTools.copyToStreams(data, streams);+ serverFileUtils.copyToStreams(data, streams);} else if (hfos instanceof Saver) {String charSet = httpHeader.getCharSet(res.getResponseHeader());Writer[] writers = (byteStream == null ? new Writer[] { (Writer) hfos } : new Writer[] { (Writer) hfos,new OutputStreamWriter(byteStream, charSet) });- StreamTools.copyToWriters(data, writers, charSet);+ serverFileUtils.copyToWriters(data, writers, charSet);} else {throw new IOException("cannot save data: hfos-type ("+ hfos.getClass().toString() +") not supported!");}diff --git a/source/de/anomic/http/JakartaCommonsHttpClient.java b/source/de/anomic/http/JakartaCommonsHttpClient.javaindex 70d093905..d8ae9ae8a 100644--- a/source/de/anomic/http/JakartaCommonsHttpClient.java+++ b/source/de/anomic/http/JakartaCommonsHttpClient.java@@ -54,11 +54,12 @@ import org.apache.commons.httpclient.methods.multipart.StringPart;import org.apache.commons.httpclient.params.HttpClientParams;import org.apache.commons.httpclient.params.HttpMethodParams;import org.apache.commons.httpclient.protocol.Protocol;+import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;import org.apache.commons.httpclient.util.DateUtil;import de.anomic.kelondro.kelondroBase64Order;+import de.anomic.server.serverFileUtils;import de.anomic.server.logging.serverLog;-import de.anomic.tools.StreamTools;import de.anomic.yacy.yacyVersion;/**@@ -90,7 +91,7 @@ public class JakartaCommonsHttpClient extends de.anomic.http.HttpClient {// TODO should this be configurable?// accept self-signed or untrusted certificates- Protocol.registerProtocol("https", new Protocol("https", new EasySSLProtocolSocketFactory(), 443));+ Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443));}private final Map<HttpMethod, InputStream> openStreams = new HashMap<HttpMethod, InputStream>();@@ -227,7 +228,7 @@ public class JakartaCommonsHttpClient extends de.anomic.http.HttpClient {if (file.isFile() && file.canRead()) {// read filefinal ByteArrayOutputStream fileData = new ByteArrayOutputStream();- StreamTools.copyToStreams(new FileInputStream(file), new OutputStream[] { fileData });+ serverFileUtils.copyToStreams(new FileInputStream(file), new OutputStream[] { fileData });value = fileData.toByteArray();}}@@ -506,4 +507,22 @@ public class JakartaCommonsHttpClient extends de.anomic.http.HttpClient {public static String getCurrentUserAgent() {return (String) apacheHttpClient.getParams().getParameter(HttpClientParams.USER_AGENT);}++ /**+ * a list of all connections (not yet implemented)+ *+ * @return+ */+ public static HttpConnectionInfo[] allConnections() {+ return new HttpConnectionInfo[0];+ }++ /**+ * number of active connections+ *+ * @return+ */+ public static int connectionCount() {+ return conManager.getConnectionsInPool();+ }}\ No newline at end of filediff --git a/source/de/anomic/http/httpHeader.java b/source/de/anomic/http/httpHeader.javaindex fe7662273..47f058c28 100644--- a/source/de/anomic/http/httpHeader.java+++ b/source/de/anomic/http/httpHeader.java@@ -952,7 +952,7 @@ public final class httpHeader extends TreeMap<String, String> implements Map<Str* @param header* @return*/- static String getCharSet(httpHeader header) {+ static String getCharSet(final httpHeader header) {String charSet = header.getCharacterEncoding();if (charSet == null) {charSet = DEFAULT_CHARSET;diff --git a/source/de/anomic/http/httpdProxyHandler.java b/source/de/anomic/http/httpdProxyHandler.javaindex cdc669750..2d4d231f8 100644--- a/source/de/anomic/http/httpdProxyHandler.java+++ b/source/de/anomic/http/httpdProxyHandler.java@@ -63,6 +63,7 @@package de.anomic.http;import java.io.BufferedReader;+import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.File;import java.io.FileOutputStream;@@ -71,7 +72,6 @@ import java.io.InputStream;import java.io.InputStreamReader;import java.io.OutputStream;import java.io.PrintWriter;-import java.io.PushbackInputStream;import java.io.Writer;import java.net.BindException;import java.net.ConnectException;@@ -514,13 +514,13 @@ public final class httpdProxyHandler {prepareRequestHeader(requestHeader, httpVer);- // generate request-url- final String connectHost = (yAddress == null) ? host +":"+ port : yAddress;- final String getUrl = "http://"+ connectHost + remotePath;-// setup HTTP-clientfinal HttpClient client = HttpFactory.newClient(requestHeader, timeout);+ final String connectHost = hostPart(host, port, yAddress);+ final String getUrl = "http://"+ connectHost + remotePath;+ client.setProxy(getProxyConfig(connectHost));+// send requesttry {res = client.GET(getUrl);@@ -585,7 +585,7 @@ public final class httpdProxyHandler {// make a transformertheLogger.logFine("create transformer for URL " + url);//hfos = new htmlFilterOutputStream((gzippedOut != null) ? gzippedOut : ((chunkedOut != null)? chunkedOut : respond), null, transformer, (ext.length() == 0));- String charSet = httpHeader.getCharSet(responseHeader);+ final String charSet = httpHeader.getCharSet(responseHeader);hfos = new htmlFilterWriter((gzippedOut != null) ? gzippedOut : ((chunkedOut != null)? chunkedOut : respond),charSet, null, transformer, (ext.length() == 0));} else {// simply pass through without parsing@@ -931,19 +931,15 @@ public final class httpdProxyHandler {prepareRequestHeader(requestHeader, httpVer);// setup HTTP-client- HttpClient client = HttpFactory.newClient();- client.setTimeout(timeout);-- // set header for connection- client.setHeader(requestHeader);+ HttpClient client = HttpFactory.newClient(requestHeader, timeout);- // send request- final String connectHost = (yAddress == null) ? host +":"+ port : yAddress;- client.setProxy(getProxyConfig(connectHost));+ // generate request-url+ final String connectHost = hostPart(host, port, yAddress);final String getUrl = "http://"+ connectHost + remotePath;+ client.setProxy(getProxyConfig(connectHost));+ // send requesttry {- // sending the http-HEAD request to the serverres = client.HEAD(getUrl);// determine if it's an internal error of the httpc@@ -967,8 +963,22 @@ public final class httpdProxyHandler {handleProxyException(e,conProp,respond,url);}}++ /**+ * @param host+ * @param port+ * @param yAddress+ * @return+ */+ private static String hostPart(String host, int port, String yAddress) {+ final String connectHost = (yAddress == null) ? host +":"+ port : yAddress;+ return connectHost;+ }- public static void doPost(Properties conProp, httpHeader requestHeader, OutputStream respond, PushbackInputStream body) throws IOException {+ public static void doPost(Properties conProp, httpHeader requestHeader, OutputStream respond, InputStream body) throws IOException {+ assert conProp != null : "precondition violated: conProp != null";+ assert requestHeader != null : "precondition violated: requestHeader != null";+ assert body != null : "precondition violated: body != null";yacyURL url = null;try {// remembering the starting time of the request@@ -1029,14 +1039,27 @@ public final class httpdProxyHandler {// set header for connectionclient.setHeader(requestHeader);- // send request- final String connectHost = (yAddress == null) ? host +":"+ port : yAddress;+ final String connectHost = hostPart(host, port, yAddress);client.setProxy(getProxyConfig(connectHost));final String getUrl = "http://"+ connectHost + remotePath;++ // check input+ if(body == null) {+ theLogger.logSevere("no body to POST!");+ }+ // from old httpc:+ // "if there is a body to the call, we would have a CONTENT-LENGTH tag in the requestHeader"+ // it seems that it is a HTTP/1.1 connection which stays open (the inputStream) and endlessly waits for+ // input so we have to end it to do the request+ final long requestLength = requestHeader.contentLength();+ if(requestLength > -1) {+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();+ serverFileUtils.copy(body, buffer, requestLength);+ body = new ByteArrayInputStream(buffer.toByteArray());+ }HttpResponse res = null;try {// sending the request- // TODO is the input stream required and valid HTTP-data?res = client.POST(getUrl, body);// determine if it's an internal error of the httpc@@ -1133,7 +1156,7 @@ public final class httpdProxyHandler {private static void addXForwardedForHeader(Properties conProp, httpHeader requestHeader) {// setting the X-Forwarded-For Headerif (switchboard.getConfigBool("proxy.sendXForwardedForHeader", true)) {- requestHeader.put(httpHeader.X_FORWARDED_FOR,conProp.getProperty(httpHeader.CONNECTION_PROP_CLIENTIP));+ requestHeader.put(httpHeader.X_FORWARDED_FOR, conProp.getProperty(httpHeader.CONNECTION_PROP_CLIENTIP));}}diff --git a/source/de/anomic/server/serverFileUtils.java b/source/de/anomic/server/serverFileUtils.javaindex 7ee498bfa..75be2a2b2 100644--- a/source/de/anomic/server/serverFileUtils.java+++ b/source/de/anomic/server/serverFileUtils.java@@ -40,8 +40,10 @@package de.anomic.server;+import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.BufferedReader;+import java.io.BufferedWriter;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.File;@@ -79,17 +81,19 @@ public final class serverFileUtils {}/**- * Copies an InputStream to an OutputStream.- * @param source InputStream- * @param dest OutputStream- * @param count the total amount of bytes to copy- * @return Total number of bytes copied.- *- * @see #copy(InputStream source, File dest)- * @see #copyRange(File source, OutputStream dest, int start)- * @see #copy(File source, OutputStream dest)- * @see #copy(File source, File dest)- */+ * Copies an InputStream to an OutputStream.+ *+ * @param source InputStream+ * @param dest OutputStream+ * @param count the total amount of bytes to copy+ * @return Total number of bytes copied.+ * @throws IOException+ *+ * @see #copy(InputStream source, File dest)+ * @see #copyRange(File source, OutputStream dest, int start)+ * @see #copy(File source, OutputStream dest)+ * @see #copy(File source, File dest)+ */public static long copy(InputStream source, OutputStream dest, long count) throws IOException {byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];int chunkSize = (int) ((count > 0) ? Math.min(count, DEFAULT_BUFFER_SIZE) : DEFAULT_BUFFER_SIZE);@@ -153,15 +157,17 @@ public final class serverFileUtils {}/**- * Copies an InputStream to a File.- * @param source InputStream- * @param dest File- * @param the amount of bytes to copy- * @see #copy(InputStream source, OutputStream dest)- * @see #copyRange(File source, OutputStream dest, int start)- * @see #copy(File source, OutputStream dest)- * @see #copy(File source, File dest)- */+ * Copies an InputStream to a File.+ *+ * @param source InputStream+ * @param dest File+ * @param count the amount of bytes to copy+ * @throws IOException+ * @see #copy(InputStream source, OutputStream dest)+ * @see #copyRange(File source, OutputStream dest, int start)+ * @see #copy(File source, OutputStream dest)+ * @see #copy(File source, File dest)+ */public static void copy(InputStream source, File dest, long count) throws IOException {FileOutputStream fos = null;try {@@ -173,15 +179,16 @@ public final class serverFileUtils {}/**- * Copies a part of a File to an OutputStream.- * @param source File- * @param dest OutputStream- * @param start Number of bytes to skip from the beginning of the File- * @see #copy(InputStream source, OutputStream dest)- * @see #copy(InputStream source, File dest)- * @see #copy(File source, OutputStream dest)- * @see #copy(File source, File dest)- */+ * Copies a part of a File to an OutputStream.+ * @param source File+ * @param dest OutputStream+ * @param start Number of bytes to skip from the beginning of the File+ * @throws IOException+ * @see #copy(InputStream source, OutputStream dest)+ * @see #copy(InputStream source, File dest)+ * @see #copy(File source, OutputStream dest)+ * @see #copy(File source, File dest)+ */public static void copyRange(File source, OutputStream dest, int start) throws IOException {InputStream fis = null;try {@@ -195,14 +202,15 @@ public final class serverFileUtils {}/**- * Copies a File to an OutputStream.- * @param source File- * @param dest OutputStream- * @see #copy(InputStream source, OutputStream dest)- * @see #copy(InputStream source, File dest)- * @see #copyRange(File source, OutputStream dest, int start)- * @see #copy(File source, File dest)- */+ * Copies a File to an OutputStream.+ * @param source File+ * @param dest OutputStream+ * @throws IOException+ * @see #copy(InputStream source, OutputStream dest)+ * @see #copy(InputStream source, File dest)+ * @see #copyRange(File source, OutputStream dest, int start)+ * @see #copy(File source, File dest)+ */public static void copy(File source, OutputStream dest) throws IOException {InputStream fis = null;try {@@ -214,15 +222,16 @@ public final class serverFileUtils {}/**- * Copies a File to a File.- * @param source File- * @param dest File- * @param count the amount of bytes to copy- * @see #copy(InputStream source, OutputStream dest)- * @see #copy(InputStream source, File dest)- * @see #copyRange(File source, OutputStream dest, int start)- * @see #copy(File source, OutputStream dest)- */+ * Copies a File to a File.+ * @param source File+ * @param dest File+ * @param count the amount of bytes to copy+ * @throws IOException+ * @see #copy(InputStream source, OutputStream dest)+ * @see #copy(InputStream source, File dest)+ * @see #copyRange(File source, OutputStream dest, int start)+ * @see #copy(File source, OutputStream dest)+ */public static void copy(File source, File dest) throws IOException {FileInputStream fis = null;FileOutputStream fos = null;@@ -500,4 +509,75 @@ public final class serverFileUtils {e.printStackTrace();}}++ /**+ * copies the input stream to all output streams (byte per byte)+ * @param in+ * @param outs+ * @return+ * @throws IOException+ */+ public static int copyToStreams(InputStream in, final OutputStream[] outs) throws IOException {+ if(!(in instanceof BufferedInputStream)) {+ // add buffer+ in = new BufferedInputStream(in);+ }++ // check if buffer is used+ int i = 0;+ for(final OutputStream output: outs) {+ if (!(output instanceof BufferedOutputStream)) {+ // add buffer+ outs[i] = new BufferedOutputStream(output);+ }+ i++;+ }++ int count = 0;+ // copy bytes+ int b;+ while((b = in.read()) != -1) {+ count++;+ for(final OutputStream out: outs) {+ out.write(b);+ }+ }+ return count;+ }++ /**+ * copies the input stream to all writers (byte per byte)+ * @param data+ * @param writers+ * @param charSet+ * @return+ * @throws IOException+ */+ public static int copyToWriters(final InputStream data, final Writer[] writers, final String charSet) throws IOException {+ // the docs say: "For top efficiency, consider wrapping an InputStreamReader within a BufferedReader."+ final BufferedReader sourceReader = new BufferedReader(new InputStreamReader(data, charSet));++ // check if buffer is used. From the documentation:+ // "For top efficiency, consider wrapping an OutputStreamWriter within a BufferedWriter so as to avoid frequent+ // converter invocations"+ int i = 0;+ for(final Writer writer: writers) {+ if (!(writer instanceof BufferedWriter)) {+ // add buffer+ writers[i] = new BufferedWriter(writer);+ }+ i++;+ }++ int count = 0;+ // copy bytes+ int b;+ while((b = sourceReader.read()) != -1) {+ count++;+ for(final Writer writer: writers) {+ writer.write(b);+ }+ }+ return count;+ }}diff --git a/source/de/anomic/tools/StreamTools.java b/source/de/anomic/tools/StreamTools.javadeleted file mode 100644index e86970b09..000000000--- a/source/de/anomic/tools/StreamTools.java+++ /dev/null@@ -1,114 +0,0 @@-// LowLevelTools.java-// (C) 2008 by Daniel Raap; [email protected]-// first published 2.4.2008 on http://yacy.net-//-// This is a part of YaCy, a peer-to-peer based web search engine-//-// $LastChangedDate: 2008-03-14 01:16:04 +0100 (Fr, 14 Mrz 2008) $-// $LastChangedRevision: 4558 $-// $LastChangedBy: orbiter $-//-// LICENSE-//-// This program is free software; you can redistribute it and/or modify-// it under the terms of the GNU General Public License as published by-// the Free Software Foundation; either version 2 of the License, or-// (at your option) any later version.-//-// This program is distributed in the hope that it will be useful,-// but WITHOUT ANY WARRANTY; without even the implied warranty of-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-// GNU General Public License for more details.-//-// You should have received a copy of the GNU General Public License-// along with this program; if not, write to the Free Software-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.tools;--import java.io.BufferedInputStream;-import java.io.BufferedOutputStream;-import java.io.BufferedReader;-import java.io.BufferedWriter;-import java.io.IOException;-import java.io.InputStream;-import java.io.InputStreamReader;-import java.io.OutputStream;-import java.io.Writer;--/**- * @author danielr- *- */-public class StreamTools {- /**- * copies the input stream to all output streams (byte per byte)- * @param in- * @param outs- * @return- * @throws IOException- */- public static int copyToStreams(InputStream in, final OutputStream[] outs) throws IOException {- if(!(in instanceof BufferedInputStream)) {- // add buffer- in = new BufferedInputStream(in);- }-- // check if buffer is used- int i = 0;- for(final OutputStream output: outs) {- if (!(output instanceof BufferedOutputStream)) {- // add buffer- outs[i] = new BufferedOutputStream(output);- }- i++;- }-- int count = 0;- // copy bytes- int b;- while((b = in.read()) != -1) {- count++;- for(final OutputStream out: outs) {- out.write(b);- }- }- return count;- }-- /**- * copies the input stream to all writers (byte per byte)- * @param data- * @param writers- * @param charSet- * @return- * @throws IOException- */- public static int copyToWriters(final InputStream data, final Writer[] writers, final String charSet) throws IOException {- // the docs say: "For top efficiency, consider wrapping an InputStreamReader within a BufferedReader."- final BufferedReader sourceReader = new BufferedReader(new InputStreamReader(data, charSet));-- // check if buffer is used. From the documentation:- // "For top efficiency, consider wrapping an OutputStreamWriter within a BufferedWriter so as to avoid frequent- // converter invocations"- int i = 0;- for(final Writer writer: writers) {- if (!(writer instanceof BufferedWriter)) {- // add buffer- writers[i] = new BufferedWriter(writer);- }- i++;- }-- int count = 0;- // copy bytes- int b;- while((b = sourceReader.read()) != -1) {- count++;- for(final Writer writer: writers) {- writer.write(b);- }- }- return count;- }--}diff --git a/source/de/anomic/yacy/yacyClient.java b/source/de/anomic/yacy/yacyClient.javaindex 92087b757..d0b9d21e5 100644--- a/source/de/anomic/yacy/yacyClient.java+++ b/source/de/anomic/yacy/yacyClient.java@@ -83,11 +83,6 @@ import de.anomic.xml.rssReader;public final class yacyClient {- /**- *- */- private static final String GZIP_POST_BODY = "GZIP_POST_BODY";-public static int publishMySeed(String address, String otherHash) {// this is called to enrich the seed information by// - own address (if peer is behind a nat/router)@@ -911,7 +906,7 @@ public final class yacyClient {// enabling gzip compression for post request bodyif ((gzipBody) && (targetSeed.getVersion() >= yacyVersion.YACY_SUPPORTS_GZIP_POST_REQUESTS)) {- post.put(GZIP_POST_BODY,"true");+ // TODO generate gzip-Header (and stream?)}post.put("wordc", Integer.toString(indexes.length));@@ -968,7 +963,7 @@ public final class yacyClient {// enabling gzip compression for post request bodyif ((gzipBody) && (targetSeed.getVersion() >= yacyVersion.YACY_SUPPORTS_GZIP_POST_REQUESTS)) {- post.put(GZIP_POST_BODY,"true");+ // TODO generate gzip-Header (and stream?)}String resource = "";