*) Trying to solve "Too many open files bug"

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@601 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
theli 20 years ago
parent 34790acf02
commit b67f008eb8

@ -85,9 +85,16 @@ public class kelondroFileRA extends kelondroAbstractRA implements kelondroRA {
public void close() throws IOException {
RAFile.close();
RAFile = null;
}
protected void finalize() throws Throwable {
if (RAFile != null) {
this.close();
}
super.finalize();
}
// some static tools
public static void writeProperties(File f, Properties props, String comment) throws IOException {
File fp = f.getParentFile();

@ -205,8 +205,19 @@ public class kelondroNIOFileRA extends kelondroAbstractRA implements kelondroRA
bufferTail.force();
System.out.println("wrote " + name + " tail");
}
RAChannel.close();
RAFile.close();
RAChannel.close();
RAChannel = null;
RAFile.close();
RAFile = null;
}
protected void finalize() throws Throwable {
if (RAChannel != null) {
try {RAChannel.close();}catch(Exception e){}
}
if (RAFile != null) {
try {RAFile.close();}catch(Exception e){}
}
}

@ -264,34 +264,39 @@ public class kelondroStack extends kelondroRecords {
}
public int imp(File file, String separator) throws IOException {
// imports a value-separated file, returns number of records that have been read
RandomAccessFile f = new RandomAccessFile(file,"r");
String s;
StringTokenizer st;
int recs = 0;
byte[][] buffer = new byte[columns()][];
int c;
int line = 0;
while ((s = f.readLine()) != null) {
s = s.trim();
line++;
if ((s.length() > 0) && (!(s.startsWith("#")))) {
st = new StringTokenizer(s, separator);
// buffer the entry
c = 0;
while ((c < columns()) && (st.hasMoreTokens())) {
buffer[c++] = st.nextToken().trim().getBytes();
}
if ((st.hasMoreTokens()) || (c != columns())) {
System.err.println("inapropriate number of entries in line " + line);
} else {
push(buffer);
recs++;
}
}
}
return recs;
// imports a value-separated file, returns number of records that have been read
RandomAccessFile f = null;
try {
f = new RandomAccessFile(file,"r");
String s;
StringTokenizer st;
int recs = 0;
byte[][] buffer = new byte[columns()][];
int c;
int line = 0;
while ((s = f.readLine()) != null) {
s = s.trim();
line++;
if ((s.length() > 0) && (!(s.startsWith("#")))) {
st = new StringTokenizer(s, separator);
// buffer the entry
c = 0;
while ((c < columns()) && (st.hasMoreTokens())) {
buffer[c++] = st.nextToken().trim().getBytes();
}
if ((st.hasMoreTokens()) || (c != columns())) {
System.err.println("inapropriate number of entries in line " + line);
} else {
push(buffer);
recs++;
}
}
}
return recs;
} finally {
if (f!=null) try{f.close();}catch(Exception e){}
}
}
public String hp(Handle h) {
@ -349,17 +354,23 @@ public class kelondroStack extends kelondroRecords {
ret = (i + " records imported").getBytes();
} else if (args[0].equals("-s")) {
String db = args[2];
BufferedReader f = new BufferedReader(new FileReader(args[1]));
String m;
while (true) {
m = f.readLine();
if (m == null) break;
if ((m.length() > 1) && (!m.startsWith("#"))) {
m = m + " " + db;
cmd(line2args(m));
}
}
ret = null;
BufferedReader f = null;
try {
f = new BufferedReader(new FileReader(args[1]));
String m;
while (true) {
m = f.readLine();
if (m == null) break;
if ((m.length() > 1) && (!m.startsWith("#"))) {
m = m + " " + db;
cmd(line2args(m));
}
}
ret = null;
} finally {
if (f != null) try {f.close();}catch(Exception e) {}
}
} else if (args[0].equals("-g")) {
kelondroStack fm = new kelondroStack(new File(args[2]), 0x100000);
byte[][] ret2 = fm.pop(Integer.parseInt(args[1]));

@ -1216,17 +1216,22 @@ public class kelondroTree extends kelondroRecords implements Comparator {
ret = (i + " records imported").getBytes();
} else if (args[0].equals("-s")) {
String db = args[2];
BufferedReader f = new BufferedReader(new FileReader(args[1]));
String m;
while (true) {
m = f.readLine();
if (m == null) break;
if ((m.length() > 1) && (!m.startsWith("#"))) {
m = m + " " + db;
cmd(line2args(m));
}
}
ret = null;
BufferedReader f = null;
try {
f = new BufferedReader(new FileReader(args[1]));
String m;
while (true) {
m = f.readLine();
if (m == null) break;
if ((m.length() > 1) && (!m.startsWith("#"))) {
m = m + " " + db;
cmd(line2args(m));
}
}
ret = null;
} finally {
if (f != null) try {f.close();}catch(Exception e){}
}
} else if (args[0].equals("-g")) {
kelondroTree fm = new kelondroTree(new File(args[1]), 0x100000);
byte[][] ret2 = fm.get(args[2].getBytes());

Loading…
Cancel
Save