diff --git a/source/de/anomic/kelondro/kelondroAbstractRA.java b/source/de/anomic/kelondro/kelondroAbstractRA.java index a9405976c..694558422 100644 --- a/source/de/anomic/kelondro/kelondroAbstractRA.java +++ b/source/de/anomic/kelondro/kelondroAbstractRA.java @@ -44,6 +44,7 @@ package de.anomic.kelondro; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Enumeration; import java.util.Iterator; @@ -80,7 +81,7 @@ abstract class kelondroAbstractRA implements kelondroRA { len -= r; } } - /* + public byte[] readFully() throws IOException { ByteArrayOutputStream dest = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; @@ -94,7 +95,7 @@ abstract class kelondroAbstractRA implements kelondroRA { dest.close(); return dest.toByteArray(); } - */ + public byte readByte() throws IOException { final int ch = this.read(); if (ch < 0) throw new IOException(); diff --git a/source/de/anomic/kelondro/kelondroDyn.java b/source/de/anomic/kelondro/kelondroDyn.java index 86a40c7d7..706415760 100644 --- a/source/de/anomic/kelondro/kelondroDyn.java +++ b/source/de/anomic/kelondro/kelondroDyn.java @@ -349,11 +349,13 @@ public class kelondroDyn extends kelondroTree { } public int read(byte[] b, int off, int len) throws IOException { - byte[] buf = getDyn(filekey, seekpos, len); - if (buf == null) return 0; - System.arraycopy(buf, 0, b, off, len); - seekpos += len; - return len; + int l = Math.min(b.length - off, len); + byte[] buf = getDyn(filekey, seekpos, l); + if (buf == null) return -1; + l = Math.min(buf.length, l); + System.arraycopy(buf, 0, b, off, l); + seekpos += l; + return l; } public void write(byte[] b, int off, int len) throws IOException {