From 74a78ebd7804bbeee6fc418822bed496051279a1 Mon Sep 17 00:00:00 2001 From: orbiter Date: Fri, 19 May 2006 21:23:49 +0000 Subject: [PATCH] turned back handling of map-writing into kelondro because of possible bug for testing see http://www.yacy-forum.de/viewtopic.php?p=21560#21560 please re-test git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2119 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- .../anomic/kelondro/kelondroAbstractRA.java | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/source/de/anomic/kelondro/kelondroAbstractRA.java b/source/de/anomic/kelondro/kelondroAbstractRA.java index 05c1b2d00..5660d8cb6 100644 --- a/source/de/anomic/kelondro/kelondroAbstractRA.java +++ b/source/de/anomic/kelondro/kelondroAbstractRA.java @@ -192,6 +192,37 @@ abstract class kelondroAbstractRA implements kelondroRA { } } + public void writeMap(final Map map, final String comment) throws IOException { + this.seek(0); + writeLine("# " + comment); + final Iterator iter = map.entrySet().iterator(); + Map.Entry entry; + while (iter.hasNext()) { + entry = (Map.Entry) iter.next(); + write(((String) entry.getKey()).getBytes()); + write((byte) '='); + writeLine((String) entry.getValue()); + } + writeLine("# EOF"); + } + + public Map readMap() throws IOException { + this.seek(0); + final TreeMap map = new TreeMap(); + String line; + int pos; + while ((line = readLine()) != null) { // very slow readLine???? + line = line.trim(); + if (line.equals("# EOF")) return map; + if ((line.length() == 0) || (line.charAt(0) == '#')) continue; + pos = line.indexOf("="); + if (pos < 0) continue; + map.put(line.substring(0, pos), line.substring(pos + 1)); + } + return map; + } + + /* public void writeMap(final Map map, final String comment) throws IOException { this.seek(0); final Iterator iter = map.entrySet().iterator(); @@ -214,6 +245,7 @@ abstract class kelondroAbstractRA implements kelondroRA { write(new String(sb).getBytes()); } + public Map readMap() throws IOException { this.seek(0); byte[] b = readFully(); @@ -231,7 +263,8 @@ abstract class kelondroAbstractRA implements kelondroRA { } return map; } - + */ + /** * this does not write the content to the see position * but to the very beginning of the record