removed call to class.finalize() because of deprecation in java 9

next: removal of finalize() implementation
after testing with assert false
pull/419/head
Michael Peter Christen 4 years ago
parent 9ef4503672
commit 9e13d77de4

@ -152,7 +152,6 @@ public class Handler implements IInArchive {
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
close(); close();
super.finalize();
} }
public void close() throws IOException { public void close() throws IOException {

@ -131,9 +131,8 @@ public class NoticedURL {
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
if ((this.coreStack != null) || (this.limitStack != null) || (this.remoteStack != null)) { if ((this.coreStack != null) || (this.limitStack != null) || (this.remoteStack != null)) {
ConcurrentLog.warn("plasmaCrawlNURL", "NURL stack closed by finalizer"); ConcurrentLog.warn("plasmaCrawlNURL", "NURL stack closed by finalizer");
close(); this.close();
} }
super.finalize();
} }
public int size() { public int size() {
@ -149,7 +148,7 @@ public class NoticedURL {
} }
public boolean isEmpty() { public boolean isEmpty() {
if (!isEmptyLocal()) return false; if (!this.isEmptyLocal()) return false;
if (this.remoteStack != null && !this.remoteStack.isEmpty()) return false; if (this.remoteStack != null && !this.remoteStack.isEmpty()) return false;
return true; return true;
} }
@ -299,9 +298,9 @@ public class NoticedURL {
protected void shift(final StackType fromStack, final StackType toStack, final CrawlSwitchboard cs, final RobotsTxt robots) { protected void shift(final StackType fromStack, final StackType toStack, final CrawlSwitchboard cs, final RobotsTxt robots) {
try { try {
final Request entry = pop(fromStack, false, cs, robots); final Request entry = this.pop(fromStack, false, cs, robots);
if (entry != null) { if (entry != null) {
final String warning = push(toStack, entry, null, robots); final String warning = this.push(toStack, entry, null, robots);
if (warning != null) { if (warning != null) {
ConcurrentLog.warn("NoticedURL", "shift from " + fromStack + " to " + toStack + ": " + warning); ConcurrentLog.warn("NoticedURL", "shift from " + fromStack + " to " + toStack + ": " + warning);
} }

@ -51,7 +51,7 @@ public final class CachedFileReader extends AbstractReader implements Reader {
@Override @Override
public final synchronized long available() throws IOException { public final synchronized long available() throws IOException {
return this.length() - RAFile.getFilePointer(); return this.length() - this.RAFile.getFilePointer();
} }
@Override @Override
@ -61,28 +61,28 @@ public final class CachedFileReader extends AbstractReader implements Reader {
@Override @Override
public final synchronized void readFully(final byte[] b, final int off, int len) throws IOException { public final synchronized void readFully(final byte[] b, final int off, int len) throws IOException {
long seek = RAFile.getFilePointer(); final long seek = this.RAFile.getFilePointer();
if (cache != null && cachelen - seek >= len) { if (this.cache != null && this.cachelen - seek >= len) {
// read from cache // read from cache
System.arraycopy(cache, (int) (seek), b, off, len); System.arraycopy(this.cache, (int) (seek), b, off, len);
RAFile.seek(seek + len); this.RAFile.seek(seek + len);
return; return;
} }
// cannot use the cache // cannot use the cache
RAFile.readFully(b, off, len); this.RAFile.readFully(b, off, len);
return; return;
} }
@Override @Override
public final synchronized void seek(final long pos) throws IOException { public final synchronized void seek(final long pos) throws IOException {
RAFile.seek(pos); this.RAFile.seek(pos);
} }
@Override @Override
public final synchronized void close() { public final synchronized void close() {
if (RAFile != null) try { if (this.RAFile != null) try {
try{RAFile.getChannel().close();} catch (final IOException e) {} try{this.RAFile.getChannel().close();} catch (final IOException e) {}
RAFile.close(); this.RAFile.close();
} catch (final IOException e) { } catch (final IOException e) {
ConcurrentLog.logException(e); ConcurrentLog.logException(e);
} }
@ -92,7 +92,6 @@ public final class CachedFileReader extends AbstractReader implements Reader {
@Override @Override
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
this.close(); this.close();
super.finalize();
} }
} }

@ -50,27 +50,27 @@ public final class CachedFileWriter extends AbstractWriter implements Writer {
@Override @Override
public final synchronized long length() throws IOException { public final synchronized long length() throws IOException {
checkReopen(); this.checkReopen();
return this.RAFile.length(); return this.RAFile.length();
} }
@Override @Override
public final synchronized void setLength(long length) throws IOException { public final synchronized void setLength(long length) throws IOException {
checkReopen(); this.checkReopen();
this.cachelen = 0; this.cachelen = 0;
this.RAFile.setLength(length); this.RAFile.setLength(length);
} }
@Override @Override
public final synchronized long available() throws IOException { public final synchronized long available() throws IOException {
checkReopen(); this.checkReopen();
return this.length() - this.RAFile.getFilePointer(); return this.length() - this.RAFile.getFilePointer();
} }
@Override @Override
public final synchronized void readFully(final byte[] b, final int off, int len) throws IOException { public final synchronized void readFully(final byte[] b, final int off, int len) throws IOException {
checkReopen(); this.checkReopen();
long seek = this.RAFile.getFilePointer(); final long seek = this.RAFile.getFilePointer();
if (this.cache != null && this.cachestart <= seek && this.cachelen - seek + this.cachestart >= len) { if (this.cache != null && this.cachestart <= seek && this.cachelen - seek + this.cachestart >= len) {
// read from cache // read from cache
//System.out.println("*** DEBUG FileRA " + this.file.getName() + ": CACHE HIT at " + seek); //System.out.println("*** DEBUG FileRA " + this.file.getName() + ": CACHE HIT at " + seek);
@ -84,7 +84,7 @@ public final class CachedFileWriter extends AbstractWriter implements Writer {
return; return;
} }
// we fill the cache here // we fill the cache here
long available = this.RAFile.length() - seek; final long available = this.RAFile.length() - seek;
if (available == -seek) return; // we don't know how this happens but we just silently ignore it by now TODO:fixme if (available == -seek) return; // we don't know how this happens but we just silently ignore it by now TODO:fixme
//System.out.println("*** available = " + available); //System.out.println("*** available = " + available);
if (available < len) throw new IOException("EOF in " + this.file.getName() + ", available = " + available + ", requested = " + len + ", this.RAFile.length() = " + this.RAFile.length() + ", seek = " + seek); if (available < len) throw new IOException("EOF in " + this.file.getName() + ", available = " + available + ", requested = " + len + ", this.RAFile.length() = " + this.RAFile.length() + ", seek = " + seek);
@ -95,7 +95,7 @@ public final class CachedFileWriter extends AbstractWriter implements Writer {
this.cachelen += len; this.cachelen += len;
} else { } else {
// fill the cache as much as possible // fill the cache as much as possible
int m = (int) Math.min(available, this.cache.length); final int m = (int) Math.min(available, this.cache.length);
this.RAFile.readFully(this.cache, 0, m); this.RAFile.readFully(this.cache, 0, m);
this.cachestart = seek; this.cachestart = seek;
this.cachelen = m; this.cachelen = m;
@ -108,17 +108,17 @@ public final class CachedFileWriter extends AbstractWriter implements Writer {
@Override @Override
public final synchronized void write(final byte[] b, final int off, final int len) throws IOException { public final synchronized void write(final byte[] b, final int off, final int len) throws IOException {
checkReopen(); this.checkReopen();
//assert len > 0; //assert len > 0;
// write to file // write to file
if (this.cache.length > 512) { if (this.cache.length > 512) {
// the large cache is only useful during an initialization phase // the large cache is only useful during an initialization phase
byte[] newcache = new byte[512]; final byte[] newcache = new byte[512];
System.arraycopy(this.cache, 0, newcache, 0, newcache.length); System.arraycopy(this.cache, 0, newcache, 0, newcache.length);
this.cache = newcache; this.cache = newcache;
if (this.cachelen > this.cache.length) this.cachelen = this.cache.length; if (this.cachelen > this.cache.length) this.cachelen = this.cache.length;
} }
long seekpos = this.RAFile.getFilePointer(); final long seekpos = this.RAFile.getFilePointer();
if (this.cachelen + len <= this.cache.length && this.cachestart + this.cachelen == seekpos) { if (this.cachelen + len <= this.cache.length && this.cachestart + this.cachelen == seekpos) {
// append to cache // append to cache
System.arraycopy(b, off, this.cache, this.cachelen, len); System.arraycopy(b, off, this.cache, this.cachelen, len);
@ -139,7 +139,7 @@ public final class CachedFileWriter extends AbstractWriter implements Writer {
@Override @Override
public final synchronized void seek(final long pos) throws IOException { public final synchronized void seek(final long pos) throws IOException {
checkReopen(); this.checkReopen();
this.RAFile.seek(pos); this.RAFile.seek(pos);
} }
@ -173,7 +173,6 @@ public final class CachedFileWriter extends AbstractWriter implements Writer {
@Override @Override
protected final void finalize() throws Throwable { protected final void finalize() throws Throwable {
this.close(); this.close();
super.finalize();
} }
} }

@ -120,22 +120,22 @@ public final class RandomAccessIO {
public final synchronized void writeSpace(long pos, int spaceCount) throws IOException { public final synchronized void writeSpace(long pos, int spaceCount) throws IOException {
if (spaceCount < 512) { if (spaceCount < 512) {
write(pos, space(spaceCount)); this.write(pos, space(spaceCount));
return; return;
} }
byte[] b = space(512); final byte[] b = space(512);
while (spaceCount > b.length) { while (spaceCount > b.length) {
write(pos, b); this.write(pos, b);
pos += b.length; pos += b.length;
spaceCount -= b.length; spaceCount -= b.length;
} }
if (spaceCount > 0) { if (spaceCount > 0) {
write(pos, space(spaceCount)); this.write(pos, space(spaceCount));
} }
} }
private final static byte[] space(int count) { private final static byte[] space(int count) {
byte[] s = new byte[count]; final byte[] s = new byte[count];
while (count-- > 0) s[count] = 0; while (count-- > 0) s[count] = 0;
return s; return s;
} }
@ -147,7 +147,6 @@ public final class RandomAccessIO {
@Override @Override
protected final void finalize() throws Throwable { protected final void finalize() throws Throwable {
if (this.ra != null) this.close(); if (this.ra != null) this.close();
super.finalize();
} }
public final void deleteOnExit() { public final void deleteOnExit() {

Loading…
Cancel
Save