code cleanup and code simplifcation

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6161 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 16 years ago
parent 160031758d
commit 409538e17a

@ -148,12 +148,7 @@ public class ViewFile {
// trying to load the resource body // trying to load the resource body
resource = plasmaHTCache.getResourceContentStream(url); resource = plasmaHTCache.getResourceContentStream(url);
resourceLength = plasmaHTCache.getResourceContentLength(url); resourceLength = plasmaHTCache.getResourceContentLength(url);
try { responseHeader = plasmaHTCache.loadResponseHeader(url);
responseHeader = plasmaHTCache.loadResponseHeader(url);
} catch (IllegalAccessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// if the resource body was not cached we try to load it from web // if the resource body was not cached we try to load it from web
if (resource == null) { if (resource == null) {

@ -71,7 +71,7 @@ public final class CrawlSwitchboard {
final yacySeedDB peers, final yacySeedDB peers,
final String networkName, final String networkName,
final Log log, final Log log,
final File queuesRoot) throws IOException { final File queuesRoot) {
log.logInfo("Initializing Word Index for the network '" + networkName + "', word hash cache size is " + Word.hashCacheSize + "."); log.logInfo("Initializing Word Index for the network '" + networkName + "', word hash cache size is " + Word.hashCacheSize + ".");

@ -41,7 +41,7 @@ public abstract class abstractWikiParser implements wikiParser {
return transform(content, "UTF-8"); return transform(content, "UTF-8");
} }
public String transform(final byte[] content, final String encoding, final String publicAddress) throws UnsupportedEncodingException { public String transform(final byte[] content, final String encoding, final String publicAddress) {
final ByteArrayInputStream bais = new ByteArrayInputStream(content); final ByteArrayInputStream bais = new ByteArrayInputStream(content);
try { try {
return transform( return transform(

@ -192,16 +192,13 @@ public class knwikiParser implements wikiParser {
public static final String escapeNewLine = "@"; public static final String escapeNewLine = "@";
private String text; private String text;
private final boolean escaped;
private final boolean nl; private final boolean nl;
public Text(final String text, final boolean escaped, final boolean newLineBefore) { public Text(final String text, final boolean escaped, final boolean newLineBefore) {
this.text = text; this.text = text;
this.escaped = escaped;
this.nl = newLineBefore; this.nl = newLineBefore;
} }
public String setTextPlain(final String text) { return this.text = text; }
public String setText(final String text) { public String setText(final String text) {
if (this.nl) if (this.nl)
this.text = text.substring(escapeNewLine.length()); this.text = text.substring(escapeNewLine.length());
@ -218,8 +215,6 @@ public class knwikiParser implements wikiParser {
} }
public String toString() { return this.text; } public String toString() { return this.text; }
public boolean isEscaped() { return this.escaped; }
public boolean isNewLineBefore() { return this.nl; }
static Text[] split2Texts(final String text, final String escapeBegin, final String escapeEnd) { static Text[] split2Texts(final String text, final String escapeBegin, final String escapeEnd) {
if (text == null) return null; if (text == null) return null;

@ -52,7 +52,7 @@ public class httpdBoundedSizeOutputStream extends httpdByteCountOutputStream {
super.write(b); super.write(b);
} }
public void write(final byte[] b, final int off, final int len) throws IOException { public synchronized void write(final byte[] b, final int off, final int len) throws IOException {
if (this.byteCount + len > this.maxSize) { if (this.byteCount + len > this.maxSize) {
// write out the rest until we reach the limit // write out the rest until we reach the limit
final long rest = this.maxSize-this.byteCount; final long rest = this.maxSize-this.byteCount;
@ -64,7 +64,7 @@ public class httpdBoundedSizeOutputStream extends httpdByteCountOutputStream {
super.write(b, off, len); super.write(b, off, len);
} }
public void write(final int b) throws IOException { public synchronized void write(final int b) throws IOException {
if (this.byteCount + 1 > this.maxSize) { if (this.byteCount + 1 > this.maxSize) {
// throw an exception // throw an exception
throw new httpdLimitExceededException("Limit exceeded",this.maxSize); throw new httpdLimitExceededException("Limit exceeded",this.maxSize);

@ -205,7 +205,7 @@ public class Compressor implements BLOB {
return (b == null) ? 0 : b.length; return (b == null) ? 0 : b.length;
} }
private int removeFromQueues(byte[] key) throws IOException { private int removeFromQueues(byte[] key) {
byte[] b = buffer.remove(new String(key)); byte[] b = buffer.remove(new String(key));
if (b != null) return b.length; if (b != null) return b.length;
return 0; return 0;

@ -317,7 +317,7 @@ public final class Heap extends HeapModifier implements BLOB {
if (entry.getValue().intValue() == reclen) { if (entry.getValue().intValue() == reclen) {
// we found an entry that has exactly the size that we need! // we found an entry that has exactly the size that we need!
// we use that entry and stop looking for a larger entry // we use that entry and stop looking for a larger entry
file.seek(entry.getKey()); file.seek(entry.getKey().longValue());
final int reclenf = file.readInt(); final int reclenf = file.readInt();
assert reclenf == reclen; assert reclenf == reclen;
file.write(key); file.write(key);
@ -419,7 +419,7 @@ public final class Heap extends HeapModifier implements BLOB {
return super.keys(up, firstKey); return super.keys(up, firstKey);
} }
public synchronized long length() throws IOException { public synchronized long length() {
return super.length() + this.buffersize; return super.length() + this.buffersize;
} }

@ -368,7 +368,7 @@ public class HeapReader {
return this.index.keys(up, firstKey); return this.index.keys(up, firstKey);
} }
public long length() throws IOException { public long length() {
return this.heapFile.length(); return this.heapFile.length();
} }

@ -92,7 +92,7 @@ public abstract class AbstractRandomAccess implements RandomAccessInterface {
this.write(int2array(v)); this.write(int2array(v));
} }
public final static byte[] int2array(final int v) throws IOException { public final static byte[] int2array(final int v) {
byte[] b = new byte[4]; byte[] b = new byte[4];
b[0] = (byte) ((v >>> 24) & 0xFF); b[0] = (byte) ((v >>> 24) & 0xFF);
b[1] = (byte) ((v >>> 16) & 0xFF); b[1] = (byte) ((v >>> 16) & 0xFF);

@ -1,82 +0,0 @@
// kelondroFileRA.java
// -----------------------
// part of The Kelondro Database
// (C) by Michael Peter Christen; mc@yacy.net
// first published on http://www.anomic.de
// Frankfurt, Germany, 2004
// last major change: 05.02.2004
//
// 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.kelondro.io;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public final class ChannelRandomAccess extends AbstractRandomAccess implements RandomAccessInterface {
private FileChannel channel;
private RandomAccessFile raf;
public ChannelRandomAccess(final File file) throws IOException, FileNotFoundException {
this.name = file.getName();
this.file = file;
this.raf = new RandomAccessFile(file, "rw");
this.channel = raf.getChannel();
}
public long length() throws IOException {
return channel.size();
}
public void setLength(long length) throws IOException {
channel.truncate(length);
}
public long available() throws IOException {
return channel.size() - channel.position();
}
public final void readFully(final byte[] b, final int off, final int len) throws IOException {
ByteBuffer bb = ByteBuffer.wrap(b);
channel.read(bb);
}
public void write(final byte[] b, final int off, final int len) throws IOException {
ByteBuffer bb = ByteBuffer.wrap(b, off, len);
channel.write(bb);
}
public void seek(final long pos) throws IOException {
channel.position(pos);
}
public void close() throws IOException {
channel.close();
raf.close();
}
protected void finalize() throws Throwable {
if (channel != null) {
this.close();
}
super.finalize();
}
}

@ -41,7 +41,6 @@ import java.util.logging.Logger;
import de.anomic.kelondro.index.Column; import de.anomic.kelondro.index.Column;
import de.anomic.kelondro.index.Row; import de.anomic.kelondro.index.Row;
import de.anomic.kelondro.index.Row.EntryIndex; import de.anomic.kelondro.index.Row.EntryIndex;
import de.anomic.kelondro.io.ChannelRandomAccess;
import de.anomic.kelondro.io.FileRandomAccess; import de.anomic.kelondro.io.FileRandomAccess;
import de.anomic.kelondro.io.IOChunksInterface; import de.anomic.kelondro.io.IOChunksInterface;
import de.anomic.kelondro.io.RandomAccessInterface; import de.anomic.kelondro.io.RandomAccessInterface;
@ -53,8 +52,6 @@ import de.anomic.kelondro.util.kelondroException;
import de.anomic.yacy.logging.Log; import de.anomic.yacy.logging.Log;
public class Records { public class Records {
private static final boolean useChannel = false;
// static seek pointers // static seek pointers
private static int LEN_DESCR = 60; private static int LEN_DESCR = 60;
@ -354,7 +351,7 @@ public class Records {
public static int staticsize(final File file) { public static int staticsize(final File file) {
if (!(file.exists())) return 0; if (!(file.exists())) return 0;
try { try {
final RandomAccessInterface ra = (useChannel) ? new ChannelRandomAccess(new File(file.getCanonicalPath())) : new FileRandomAccess(new File(file.getCanonicalPath())); final RandomAccessInterface ra = new FileRandomAccess(new File(file.getCanonicalPath()));
final IOChunksInterface entryFile = new RandomAccessIOChunks(ra, ra.name()); final IOChunksInterface entryFile = new RandomAccessIOChunks(ra, ra.name());
final int used = entryFile.readInt(POS_USEDC); // works only if consistency with file size is given final int used = entryFile.readInt(POS_USEDC); // works only if consistency with file size is given
@ -388,7 +385,7 @@ public class Records {
if (file.exists()) { if (file.exists()) {
// opens an existing tree // opens an existing tree
this.filename = file.getCanonicalPath(); this.filename = file.getCanonicalPath();
RandomAccessInterface raf = (useChannel) ? new ChannelRandomAccess(new File(this.filename)) : new FileRandomAccess(new File(this.filename)); RandomAccessInterface raf = new FileRandomAccess(new File(this.filename));
//kelondroRA raf = new kelondroBufferedRA(new kelondroFileRA(this.filename), 1024, 100); //kelondroRA raf = new kelondroBufferedRA(new kelondroFileRA(this.filename), 1024, 100);
//kelondroRA raf = new kelondroCachedRA(new kelondroFileRA(this.filename), 5000000, 1000); //kelondroRA raf = new kelondroCachedRA(new kelondroFileRA(this.filename), 5000000, 1000);
//kelondroRA raf = new kelondroNIOFileRA(this.filename, (file.length() < 4000000), 10000); //kelondroRA raf = new kelondroNIOFileRA(this.filename, (file.length() < 4000000), 10000);
@ -396,7 +393,7 @@ public class Records {
initExistingFile(raf); initExistingFile(raf);
} else { } else {
this.filename = file.getCanonicalPath(); this.filename = file.getCanonicalPath();
final RandomAccessInterface raf = (useChannel) ? new ChannelRandomAccess(new File(this.filename)) : new FileRandomAccess(new File(this.filename)); final RandomAccessInterface raf = new FileRandomAccess(new File(this.filename));
// kelondroRA raf = new kelondroBufferedRA(new kelondroFileRA(this.filename), 1024, 100); // kelondroRA raf = new kelondroBufferedRA(new kelondroFileRA(this.filename), 1024, 100);
// kelondroRA raf = new kelondroNIOFileRA(this.filename, false, 10000); // kelondroRA raf = new kelondroNIOFileRA(this.filename, false, 10000);
initNewFile(raf, FHandles, txtProps); initNewFile(raf, FHandles, txtProps);
@ -420,7 +417,7 @@ public class Records {
assert f != null; assert f != null;
this.entryFile.close(); this.entryFile.close();
FileUtils.deletedelete(f); FileUtils.deletedelete(f);
ra = (useChannel) ? new ChannelRandomAccess(f) : new FileRandomAccess(f); ra = new FileRandomAccess(f);
initNewFile(ra, this.HANDLES.length, this.TXTPROPS.length); initNewFile(ra, this.HANDLES.length, this.TXTPROPS.length);
} }

@ -225,7 +225,7 @@ public class SQLTable implements ObjectIndex {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public synchronized void addUnique(final List<Row.Entry> rows) throws IOException { public synchronized void addUnique(final List<Row.Entry> rows) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

@ -646,7 +646,7 @@ public class Table implements ObjectIndex {
byte[] fk; byte[] fk;
int c; int c;
public rowIterator(final boolean up, final byte[] firstKey) throws IOException { public rowIterator(final boolean up, final byte[] firstKey) {
this.up = up; this.up = up;
this.fk = firstKey; this.fk = firstKey;
this.i = index.keys(up, firstKey); this.i = index.keys(up, firstKey);
@ -654,12 +654,7 @@ public class Table implements ObjectIndex {
} }
public CloneableIterator<Entry> clone(final Object modifier) { public CloneableIterator<Entry> clone(final Object modifier) {
try { return new rowIterator(up, fk);
return new rowIterator(up, fk);
} catch (final IOException e) {
e.printStackTrace();
return null;
}
} }
public boolean hasNext() { public boolean hasNext() {

@ -495,7 +495,7 @@ public class ReferenceContainer<ReferenceType extends Reference> extends RowSet
return pivot; return pivot;
} }
public String toString() { public synchronized String toString() {
return "C[" + new String(termHash) + "] has " + this.size() + " entries"; return "C[" + new String(termHash) + "] has " + this.size() + " entries";
} }

@ -241,7 +241,7 @@ public final class plasmaHTCache {
* @throws <b>UnsupportedProtocolException</b> if the protocol is not supported and therefore the * @throws <b>UnsupportedProtocolException</b> if the protocol is not supported and therefore the
* info object couldn't be created * info object couldn't be created
*/ */
public static httpResponseHeader loadResponseHeader(final yacyURL url) throws IllegalAccessException { public static httpResponseHeader loadResponseHeader(final yacyURL url) {
// loading data from database // loading data from database
Map<String, String> hdb; Map<String, String> hdb;

@ -48,13 +48,13 @@ public class serverInstantBlockingThread<J extends serverProcessorJob> extends s
// define execution class // define execution class
this.jobExecMethod = execMethod(env, jobExec); this.jobExecMethod = execMethod(env, jobExec);
this.environment = (env instanceof Class) ? null : env; this.environment = (env instanceof Class<?>) ? null : env;
this.setName(jobExecMethod.getClass().getName() + "." + jobExecMethod.getName() + "." + handleCounter++); this.setName(jobExecMethod.getClass().getName() + "." + jobExecMethod.getName() + "." + handleCounter++);
this.handle = Long.valueOf(System.currentTimeMillis() + this.getName().hashCode()); this.handle = Long.valueOf(System.currentTimeMillis() + this.getName().hashCode());
} }
protected static Method execMethod(final Object env, final String jobExec) { protected static Method execMethod(final Object env, final String jobExec) {
final Class<?> theClass = (env instanceof Class) ? (Class<?>) env : env.getClass(); final Class<?> theClass = (env instanceof Class<?>) ? (Class<?>) env : env.getClass();
try { try {
final Method[] methods = theClass.getMethods(); final Method[] methods = theClass.getMethods();
for (int i = 0; i < methods.length; i++) { for (int i = 0; i < methods.length; i++) {

@ -40,7 +40,7 @@ public final class serverInstantBusyThread extends serverAbstractBusyThread impl
// jobExec is the name of a method of the object 'env' that executes the one-step-run // jobExec is the name of a method of the object 'env' that executes the one-step-run
// jobCount is the name of a method that returns the size of the job // jobCount is the name of a method that returns the size of the job
// freemem is the name of a method that tries to free memory and returns void // freemem is the name of a method that tries to free memory and returns void
final Class<?> theClass = (env instanceof Class) ? (Class<?>) env : env.getClass(); final Class<?> theClass = (env instanceof Class<?>) ? (Class<?>) env : env.getClass();
try { try {
this.jobExecMethod = theClass.getMethod(jobExec, new Class[0]); this.jobExecMethod = theClass.getMethod(jobExec, new Class[0]);
} catch (final NoSuchMethodException e) { } catch (final NoSuchMethodException e) {
@ -64,7 +64,7 @@ public final class serverInstantBusyThread extends serverAbstractBusyThread impl
} catch (final NoSuchMethodException e) { } catch (final NoSuchMethodException e) {
throw new RuntimeException("serverInstantThread, wrong declaration of freemem: " + e.getMessage()); throw new RuntimeException("serverInstantThread, wrong declaration of freemem: " + e.getMessage());
} }
this.environment = (env instanceof Class) ? null : env; this.environment = (env instanceof Class<?>) ? null : env;
this.setName(theClass.getName() + "." + jobExec); this.setName(theClass.getName() + "." + jobExec);
this.handle = Long.valueOf(System.currentTimeMillis() + this.getName().hashCode()); this.handle = Long.valueOf(System.currentTimeMillis() + this.getName().hashCode());
} }

@ -150,7 +150,7 @@ public final class ConsoleOutErrHandler extends Handler {
this.stdErrHandler.close(); this.stdErrHandler.close();
} }
public void setLevel(final Level newLevel) throws SecurityException { public synchronized void setLevel(final Level newLevel) throws SecurityException {
super.setLevel(newLevel); super.setLevel(newLevel);
} }

@ -38,12 +38,12 @@ public final class ConsoleOutHandler extends StreamHandler {
setOutputStream(System.out); setOutputStream(System.out);
} }
public void publish(final LogRecord record) { public synchronized void publish(final LogRecord record) {
super.publish(record); super.publish(record);
flush(); flush();
} }
public void close() { public synchronized void close() {
flush(); flush();
} }
} }

@ -36,7 +36,7 @@ public final class MiniLogFormatter extends SimpleFormatter {
super(); super();
} }
public String format(final LogRecord record) { public synchronized String format(final LogRecord record) {
final StringBuilder buffer = this.buffer; final StringBuilder buffer = this.buffer;
buffer.setLength(0); buffer.setLength(0);

@ -50,7 +50,7 @@ public class SimpleLogFormatter extends SimpleFormatter {
super(); super();
} }
public String format(final LogRecord record) { public synchronized String format(final LogRecord record) {
final StringBuffer buffer = this.buffer; final StringBuffer buffer = this.buffer;
buffer.setLength(0); buffer.setLength(0);

@ -30,7 +30,6 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.lang.ref.SoftReference; import java.lang.ref.SoftReference;
import java.lang.reflect.Method;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
@ -240,7 +239,6 @@ public final class yacySeedDB implements httpdAlternativeDomainNames {
return this.sizeConnected() <= dhtActivityMagic; return this.sizeConnected() <= dhtActivityMagic;
} }
@SuppressWarnings("unchecked")
private synchronized MapDataMining openSeedTable(final File seedDBFile) { private synchronized MapDataMining openSeedTable(final File seedDBFile) {
final File parentDir = new File(seedDBFile.getParent()); final File parentDir = new File(seedDBFile.getParent());
if (!parentDir.exists()) { if (!parentDir.exists()) {

Loading…
Cancel
Save