- next try to fix the networking problem:

set the maximum transfer size to less than MTU=1500-52: buffer size <= 1448
- some refactoring of transfer methods (naming)

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4558 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 17 years ago
parent f63bd26268
commit fa1090113d

@ -262,7 +262,7 @@ public class WatchCrawler_p {
htmlFilterContentScraper scraper = new htmlFilterContentScraper(new yacyURL(file)); htmlFilterContentScraper scraper = new htmlFilterContentScraper(new yacyURL(file));
//OutputStream os = new htmlFilterOutputStream(null, scraper, null, false); //OutputStream os = new htmlFilterOutputStream(null, scraper, null, false);
Writer writer = new htmlFilterWriter(null,null,scraper,null,false); Writer writer = new htmlFilterWriter(null,null,scraper,null,false);
serverFileUtils.write(fileString,writer); serverFileUtils.copy(fileString, writer);
writer.close(); writer.close();
//String headline = scraper.getHeadline(); //String headline = scraper.getHeadline();

@ -88,7 +88,7 @@ public class getpageinfo_p {
htmlFilterContentScraper scraper = new htmlFilterContentScraper(u); htmlFilterContentScraper scraper = new htmlFilterContentScraper(u);
//OutputStream os = new htmlFilterOutputStream(null, scraper, null, false); //OutputStream os = new htmlFilterOutputStream(null, scraper, null, false);
Writer writer = new htmlFilterWriter(null,null,scraper,null,false); Writer writer = new htmlFilterWriter(null,null,scraper,null,false);
serverFileUtils.write(contentString,writer); serverFileUtils.copy(contentString,writer);
writer.close(); writer.close();
// put the document title // put the document title

@ -137,7 +137,7 @@ public final class transfer {
File file = new File(path, filename); File file = new File(path, filename);
try { try {
if (file.getCanonicalPath().toString().startsWith(path.getCanonicalPath().toString())){ if (file.getCanonicalPath().toString().startsWith(path.getCanonicalPath().toString())){
serverFileUtils.write(fileString.getBytes(), file); serverFileUtils.copy(fileString.getBytes(), file);
String md5t = serverCodings.encodeMD5Hex(file); String md5t = serverCodings.encodeMD5Hex(file);
if (md5t.equals(md5)) { if (md5t.equals(md5)) {
prop.put("response", "ok"); prop.put("response", "ok");

@ -435,7 +435,7 @@ public final class httpTemplate {
} }
*/ */
serverFileUtils.write(replacement, out); serverFileUtils.copy(replacement, out);
} else { } else {
// inconsistency, simply finalize this // inconsistency, simply finalize this
serverFileUtils.copy(pis, out); serverFileUtils.copy(pis, out);
@ -479,7 +479,7 @@ public final class httpTemplate {
byte[] tmp=new byte[2]; byte[] tmp=new byte[2];
tmp[0]=hash; tmp[0]=hash;
tmp[1]=(byte)bb; tmp[1]=(byte)bb;
serverFileUtils.write(tmp, out); serverFileUtils.copy(tmp, out);
} }
} }
//System.out.println(structure.toString()); //DEBUG //System.out.println(structure.toString()); //DEBUG

@ -1236,7 +1236,7 @@ public final class httpd implements serverHandler {
if (! method.equals(httpHeader.METHOD_HEAD)) { if (! method.equals(httpHeader.METHOD_HEAD)) {
// write the array to the client // write the array to the client
serverFileUtils.write(result, respond); serverFileUtils.copy(result, respond);
} }
respond.flush(); respond.flush();
} catch (Exception e) { } catch (Exception e) {

@ -768,7 +768,7 @@ public final class httpdFileHandler {
httpVersion, 200, null, mimeType, result.length, httpVersion, 200, null, mimeType, result.length,
targetDate, null, tp.getOutgoingHeader(), targetDate, null, tp.getOutgoingHeader(),
contentEncoding, null, nocache); contentEncoding, null, nocache);
serverFileUtils.write(result, out); serverFileUtils.copy(result, out);
} }
} }
} else { // no html } else { // no html

@ -178,7 +178,7 @@ public final class indexRAMRI implements indexRI {
if (writeBuffer != null) { if (writeBuffer != null) {
serverByteBuffer bb = writeBuffer.getBuffer(); serverByteBuffer bb = writeBuffer.getBuffer();
//System.out.println("*** byteBuffer size = " + bb.length()); //System.out.println("*** byteBuffer size = " + bb.length());
serverFileUtils.write(bb.getBytes(), indexDumpFile); serverFileUtils.copy(bb.getBytes(), indexDumpFile);
writeBuffer.close(); writeBuffer.close();
} }
dumpArray.close(); dumpArray.close();

@ -204,7 +204,7 @@ public class kelondroAttrSeq {
if (out.toString().endsWith(".gz")) { if (out.toString().endsWith(".gz")) {
serverFileUtils.writeAndGZip((new String(sb)).getBytes(), out); serverFileUtils.writeAndGZip((new String(sb)).getBytes(), out);
} else { } else {
serverFileUtils.write((new String(sb)).getBytes(), out); serverFileUtils.copy((new String(sb)).getBytes(), out);
} }
} }

@ -183,7 +183,7 @@ public class kelondroRowCollection {
} }
public void saveCollection(File file) throws IOException { public void saveCollection(File file) throws IOException {
serverFileUtils.write(exportCollection(), file); serverFileUtils.copy(exportCollection(), file);
} }
public kelondroRow row() { public kelondroRow row() {

@ -81,7 +81,7 @@ public class odtDetector implements MagicDetector {
File dstFile = null; File dstFile = null;
try { try {
dstFile = File.createTempFile("mimeTypeParser",".tmp"); dstFile = File.createTempFile("mimeTypeParser",".tmp");
serverFileUtils.write(data,dstFile); serverFileUtils.copy(data,dstFile);
return process(dstFile, offset, length, bitmask, comparator, mimeType, params); return process(dstFile, offset, length, bitmask, comparator, mimeType, params);
} catch (IOException e) { } catch (IOException e) {
return null; return null;

@ -373,7 +373,7 @@ public final class plasmaHTCache {
try { try {
deleteFile(file); deleteFile(file);
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
serverFileUtils.write(array, file); serverFileUtils.copy(array, file);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
// this is the case of a "(Not a directory)" error, which should be prohibited // this is the case of a "(Not a directory)" error, which should be prohibited
// by the shallStoreCache() property. However, sometimes the error still occurs // by the shallStoreCache() property. However, sometimes the error still occurs

@ -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 // set a non-zero linger, that means that a socket.close() blocks until all data is written
controlSocket.setSoLinger(true, this.timeout); 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 // create session
Session connection = new Session(sessionThreadGroup, controlSocket, this.timeout); Session connection = new Session(sessionThreadGroup, controlSocket, this.timeout);
this.busySessions.add(connection); this.busySessions.add(connection);

@ -72,10 +72,10 @@ import de.anomic.tools.nxTools;
public final class serverFileUtils { 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 { 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 { 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 count = 0;
int n = 0; int n = 0;
try { try {
@ -151,7 +151,7 @@ public final class serverFileUtils {
public static void copy(InputStream source, File dest) throws IOException { public static void copy(InputStream source, File dest) throws IOException {
copy(source,dest,-1); copy(source,dest,-1);
} }
/** /**
* Copies an InputStream to a File. * Copies an InputStream to a File.
* @param source InputStream * @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. * Copies a File to a File.
* @param source File * @param source File
@ -227,19 +223,28 @@ public final class serverFileUtils {
* @see #copyRange(File source, OutputStream dest, int start) * @see #copyRange(File source, OutputStream dest, int start)
* @see #copy(File source, OutputStream dest) * @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; FileInputStream fis = null;
FileOutputStream fos = null; FileOutputStream fos = null;
try { try {
fis = new FileInputStream(source); fis = new FileInputStream(source);
fos = new FileOutputStream(dest); fos = new FileOutputStream(dest);
copy(fis, fos, count); copy(fis, fos, -1);
} finally { } finally {
if (fis != null) try {fis.close();} catch (Exception e) {} if (fis != null) try {fis.close();} catch (Exception e) {}
if (fos != null) try {fos.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 { public static byte[] read(InputStream source) throws IOException {
return read(source,-1); return read(source,-1);
} }
@ -297,27 +302,13 @@ public final class serverFileUtils {
GZIPOutputStream zipOut = null; GZIPOutputStream zipOut = null;
try { try {
zipOut = new GZIPOutputStream(dest); zipOut = new GZIPOutputStream(dest);
write(source, zipOut); copy(source, zipOut);
zipOut.close(); zipOut.close();
} finally { } finally {
if (zipOut != null) try { zipOut.close(); } catch (Exception e) {} 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 * This function determines if a byte array is gzip compressed and uncompress it
* @param source properly gzip compressed byte array * @param source properly gzip compressed byte array

@ -328,7 +328,7 @@ public final class serverSystem {
} }
public static void deployScript(File scriptFile, String theScript) throws IOException { public static void deployScript(File scriptFile, String theScript) throws IOException {
serverFileUtils.write(theScript.getBytes(), scriptFile); serverFileUtils.copy(theScript.getBytes(), scriptFile);
try { try {
Runtime.getRuntime().exec("chmod 755 " + scriptFile.getAbsolutePath().replaceAll(" ", "\\ ")).waitFor(); Runtime.getRuntime().exec("chmod 755 " + scriptFile.getAbsolutePath().replaceAll(" ", "\\ ")).waitFor();
} catch (InterruptedException e) { } catch (InterruptedException e) {

@ -286,7 +286,7 @@ public final class yacy {
} catch (IOException e) {} } catch (IOException e) {}
final File htdocsReadme = new File(htDocsPath, "readme.txt"); 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" + "This is your root directory for individual Web Content\r\n" +
"\r\n" + "\r\n" +
"Please place your html files into the www subdirectory.\r\n" + "Please place your html files into the www subdirectory.\r\n" +

Loading…
Cancel
Save