diff --git a/htroot/WatchCrawler_p.java b/htroot/WatchCrawler_p.java index f09020a5d..597d91b2c 100644 --- a/htroot/WatchCrawler_p.java +++ b/htroot/WatchCrawler_p.java @@ -262,7 +262,7 @@ public class WatchCrawler_p { htmlFilterContentScraper scraper = new htmlFilterContentScraper(new yacyURL(file)); //OutputStream os = new htmlFilterOutputStream(null, scraper, null, false); Writer writer = new htmlFilterWriter(null,null,scraper,null,false); - serverFileUtils.write(fileString,writer); + serverFileUtils.copy(fileString, writer); writer.close(); //String headline = scraper.getHeadline(); diff --git a/htroot/xml/util/getpageinfo_p.java b/htroot/xml/util/getpageinfo_p.java index 7da620b0e..4e13a42aa 100644 --- a/htroot/xml/util/getpageinfo_p.java +++ b/htroot/xml/util/getpageinfo_p.java @@ -88,7 +88,7 @@ public class getpageinfo_p { htmlFilterContentScraper scraper = new htmlFilterContentScraper(u); //OutputStream os = new htmlFilterOutputStream(null, scraper, null, false); Writer writer = new htmlFilterWriter(null,null,scraper,null,false); - serverFileUtils.write(contentString,writer); + serverFileUtils.copy(contentString,writer); writer.close(); // put the document title diff --git a/htroot/yacy/transfer.java b/htroot/yacy/transfer.java index e7346fa22..c66b249c9 100644 --- a/htroot/yacy/transfer.java +++ b/htroot/yacy/transfer.java @@ -137,7 +137,7 @@ public final class transfer { File file = new File(path, filename); try { if (file.getCanonicalPath().toString().startsWith(path.getCanonicalPath().toString())){ - serverFileUtils.write(fileString.getBytes(), file); + serverFileUtils.copy(fileString.getBytes(), file); String md5t = serverCodings.encodeMD5Hex(file); if (md5t.equals(md5)) { prop.put("response", "ok"); diff --git a/source/de/anomic/http/httpTemplate.java b/source/de/anomic/http/httpTemplate.java index be22d5c89..393c5f465 100644 --- a/source/de/anomic/http/httpTemplate.java +++ b/source/de/anomic/http/httpTemplate.java @@ -435,7 +435,7 @@ public final class httpTemplate { } */ - serverFileUtils.write(replacement, out); + serverFileUtils.copy(replacement, out); } else { // inconsistency, simply finalize this serverFileUtils.copy(pis, out); @@ -479,7 +479,7 @@ public final class httpTemplate { byte[] tmp=new byte[2]; tmp[0]=hash; tmp[1]=(byte)bb; - serverFileUtils.write(tmp, out); + serverFileUtils.copy(tmp, out); } } //System.out.println(structure.toString()); //DEBUG diff --git a/source/de/anomic/http/httpd.java b/source/de/anomic/http/httpd.java index 81674ee58..ce8581838 100644 --- a/source/de/anomic/http/httpd.java +++ b/source/de/anomic/http/httpd.java @@ -1236,7 +1236,7 @@ public final class httpd implements serverHandler { if (! method.equals(httpHeader.METHOD_HEAD)) { // write the array to the client - serverFileUtils.write(result, respond); + serverFileUtils.copy(result, respond); } respond.flush(); } catch (Exception e) { diff --git a/source/de/anomic/http/httpdFileHandler.java b/source/de/anomic/http/httpdFileHandler.java index 5c0e82346..f73cca74f 100644 --- a/source/de/anomic/http/httpdFileHandler.java +++ b/source/de/anomic/http/httpdFileHandler.java @@ -768,7 +768,7 @@ public final class httpdFileHandler { httpVersion, 200, null, mimeType, result.length, targetDate, null, tp.getOutgoingHeader(), contentEncoding, null, nocache); - serverFileUtils.write(result, out); + serverFileUtils.copy(result, out); } } } else { // no html diff --git a/source/de/anomic/index/indexRAMRI.java b/source/de/anomic/index/indexRAMRI.java index bf1b5dae5..8acd830fc 100644 --- a/source/de/anomic/index/indexRAMRI.java +++ b/source/de/anomic/index/indexRAMRI.java @@ -178,7 +178,7 @@ public final class indexRAMRI implements indexRI { if (writeBuffer != null) { serverByteBuffer bb = writeBuffer.getBuffer(); //System.out.println("*** byteBuffer size = " + bb.length()); - serverFileUtils.write(bb.getBytes(), indexDumpFile); + serverFileUtils.copy(bb.getBytes(), indexDumpFile); writeBuffer.close(); } dumpArray.close(); diff --git a/source/de/anomic/kelondro/kelondroAttrSeq.java b/source/de/anomic/kelondro/kelondroAttrSeq.java index 5129aeb79..ef09089a8 100644 --- a/source/de/anomic/kelondro/kelondroAttrSeq.java +++ b/source/de/anomic/kelondro/kelondroAttrSeq.java @@ -204,7 +204,7 @@ public class kelondroAttrSeq { if (out.toString().endsWith(".gz")) { serverFileUtils.writeAndGZip((new String(sb)).getBytes(), out); } else { - serverFileUtils.write((new String(sb)).getBytes(), out); + serverFileUtils.copy((new String(sb)).getBytes(), out); } } diff --git a/source/de/anomic/kelondro/kelondroRowCollection.java b/source/de/anomic/kelondro/kelondroRowCollection.java index 5433cb9af..dad9ae1b8 100644 --- a/source/de/anomic/kelondro/kelondroRowCollection.java +++ b/source/de/anomic/kelondro/kelondroRowCollection.java @@ -183,7 +183,7 @@ public class kelondroRowCollection { } public void saveCollection(File file) throws IOException { - serverFileUtils.write(exportCollection(), file); + serverFileUtils.copy(exportCollection(), file); } public kelondroRow row() { diff --git a/source/de/anomic/plasma/parser/mimeType/odtDetector.java b/source/de/anomic/plasma/parser/mimeType/odtDetector.java index fecc9239d..2e9df61f2 100644 --- a/source/de/anomic/plasma/parser/mimeType/odtDetector.java +++ b/source/de/anomic/plasma/parser/mimeType/odtDetector.java @@ -81,7 +81,7 @@ public class odtDetector implements MagicDetector { File dstFile = null; try { dstFile = File.createTempFile("mimeTypeParser",".tmp"); - serverFileUtils.write(data,dstFile); + serverFileUtils.copy(data,dstFile); return process(dstFile, offset, length, bitmask, comparator, mimeType, params); } catch (IOException e) { return null; diff --git a/source/de/anomic/plasma/plasmaHTCache.java b/source/de/anomic/plasma/plasmaHTCache.java index f940bed6f..2e40c0891 100644 --- a/source/de/anomic/plasma/plasmaHTCache.java +++ b/source/de/anomic/plasma/plasmaHTCache.java @@ -373,7 +373,7 @@ public final class plasmaHTCache { try { deleteFile(file); file.getParentFile().mkdirs(); - serverFileUtils.write(array, file); + serverFileUtils.copy(array, file); } catch (FileNotFoundException e) { // this is the case of a "(Not a directory)" error, which should be prohibited // by the shallStoreCache() property. However, sometimes the error still occurs diff --git a/source/de/anomic/server/serverCore.java b/source/de/anomic/server/serverCore.java index bfdefa1aa..5027f2181 100644 --- a/source/de/anomic/server/serverCore.java +++ b/source/de/anomic/server/serverCore.java @@ -422,6 +422,9 @@ public final class serverCore extends serverAbstractThread implements serverThre // set a non-zero linger, that means that a socket.close() blocks until all data is written controlSocket.setSoLinger(true, this.timeout); + // ensure that MTU-48 is not exceeded to prevent that routers cannot handle large data packets + controlSocket.setSendBufferSize(1440); + // create session Session connection = new Session(sessionThreadGroup, controlSocket, this.timeout); this.busySessions.add(connection); diff --git a/source/de/anomic/server/serverFileUtils.java b/source/de/anomic/server/serverFileUtils.java index 4ca643b42..7ee498bfa 100644 --- a/source/de/anomic/server/serverFileUtils.java +++ b/source/de/anomic/server/serverFileUtils.java @@ -72,10 +72,10 @@ import de.anomic.tools.nxTools; public final class serverFileUtils { - private static final int DEFAULT_BUFFER_SIZE = 512; + private static final int DEFAULT_BUFFER_SIZE = 1024; // this is also the maximum chunk size public static long copy(InputStream source, OutputStream dest) throws IOException { - return copy(source,dest, -1); + return copy(source, dest, -1); } /** @@ -133,7 +133,7 @@ public final class serverFileUtils { } public static int copy(Reader source, Writer dest) throws IOException { - char[] buffer = new char[4096]; + char[] buffer = new char[DEFAULT_BUFFER_SIZE]; int count = 0; int n = 0; try { @@ -151,7 +151,7 @@ public final class serverFileUtils { public static void copy(InputStream source, File dest) throws IOException { copy(source,dest,-1); } - + /** * Copies an InputStream to a File. * @param source InputStream @@ -213,10 +213,6 @@ public final class serverFileUtils { } } - public static void copy(File source, File dest) throws IOException { - copy(source,dest,-1); - } - /** * Copies a File to a File. * @param source File @@ -227,19 +223,28 @@ public final class serverFileUtils { * @see #copyRange(File source, OutputStream dest, int start) * @see #copy(File source, OutputStream dest) */ - public static void copy(File source, File dest, long count) throws IOException { + public static void copy(File source, File dest) throws IOException { FileInputStream fis = null; FileOutputStream fos = null; try { fis = new FileInputStream(source); fos = new FileOutputStream(dest); - copy(fis, fos, count); + copy(fis, fos, -1); } finally { if (fis != null) try {fis.close();} catch (Exception e) {} if (fos != null) try {fos.close();} catch (Exception e) {} } } + public static void copy(byte[] source, OutputStream dest) throws IOException { + dest.write(source, 0, source.length); + dest.flush(); + } + + public static void copy(byte[] source, File dest) throws IOException { + copy(new ByteArrayInputStream(source), dest); + } + public static byte[] read(InputStream source) throws IOException { return read(source,-1); } @@ -297,27 +302,13 @@ public final class serverFileUtils { GZIPOutputStream zipOut = null; try { zipOut = new GZIPOutputStream(dest); - write(source, zipOut); + copy(source, zipOut); zipOut.close(); } finally { if (zipOut != null) try { zipOut.close(); } catch (Exception e) {} } } - public static void write(String source, Writer dest) throws IOException { - dest.write(source); - dest.flush(); - } - - public static void write(byte[] source, OutputStream dest) throws IOException { - dest.write(source, 0, source.length); - dest.flush(); - } - - public static void write(byte[] source, File dest) throws IOException { - copy(new ByteArrayInputStream(source), dest); - } - /** * This function determines if a byte array is gzip compressed and uncompress it * @param source properly gzip compressed byte array diff --git a/source/de/anomic/server/serverSystem.java b/source/de/anomic/server/serverSystem.java index f9d4529f1..1edac6106 100644 --- a/source/de/anomic/server/serverSystem.java +++ b/source/de/anomic/server/serverSystem.java @@ -328,7 +328,7 @@ public final class serverSystem { } public static void deployScript(File scriptFile, String theScript) throws IOException { - serverFileUtils.write(theScript.getBytes(), scriptFile); + serverFileUtils.copy(theScript.getBytes(), scriptFile); try { Runtime.getRuntime().exec("chmod 755 " + scriptFile.getAbsolutePath().replaceAll(" ", "\\ ")).waitFor(); } catch (InterruptedException e) { diff --git a/source/yacy.java b/source/yacy.java index ab04a916e..6534bbb67 100644 --- a/source/yacy.java +++ b/source/yacy.java @@ -286,7 +286,7 @@ public final class yacy { } catch (IOException e) {} final File htdocsReadme = new File(htDocsPath, "readme.txt"); - if (!(htdocsReadme.exists())) try {serverFileUtils.write(( + if (!(htdocsReadme.exists())) try {serverFileUtils.copy(( "This is your root directory for individual Web Content\r\n" + "\r\n" + "Please place your html files into the www subdirectory.\r\n" +