From bb931c7b83552d0919bb387f5a0b276fbb5a4759 Mon Sep 17 00:00:00 2001 From: orbiter Date: Mon, 15 May 2006 21:50:22 +0000 Subject: [PATCH] fix for some improper details in kelondroDyn git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2104 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/kelondro/kelondroAbstractRA.java | 5 +++-- source/de/anomic/kelondro/kelondroDyn.java | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) 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 {