KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > storage > raf > RecordsFileInspector


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

24 package org.objectweb.jalisto.se.storage.raf;
25
26
27 import org.objectweb.jalisto.se.api.JalistoProperties;
28 import org.objectweb.jalisto.se.impl.JalistoPropertiesImpl;
29
30 import java.io.PrintWriter JavaDoc;
31 import java.util.*;
32
33 public class RecordsFileInspector {
34     public void inspectRecordsFile(PrintWriter JavaDoc out, RecordsFile rf)
35             throws Exception JavaDoc {
36         out.println("RecordsFile with " + rf.getNumRecords());
37         out.println("keys :");
38
39         Iterator iterator = rf.enumerateKeys();
40         List keys = new LinkedList();
41         while (iterator.hasNext()) {
42             String JavaDoc key = iterator.next().toString();
43             keys.add(key);
44         }
45         Collections.sort(keys);
46
47         for (int i = 0; i < keys.size(); i++) {
48             String JavaDoc key = (String JavaDoc) keys.get(i);
49             RecordReader reader = rf.readRecord(key);
50             Object JavaDoc o = reader.readObject();
51             out.println(key + " : " + String.valueOf(o));
52             reader.reset();
53         }
54     }
55
56     public static void main(String JavaDoc[] args) {
57         try {
58             JalistoProperties prop;
59
60             if (args.length < 1) {
61                 prop = new JalistoPropertiesImpl("");
62             } else {
63                 prop = new JalistoPropertiesImpl(args[0]);
64             }
65
66             RecordsFile rf = new RecordsFile(prop.getSystemDbFilePath(), "rw");
67             rf.initExistingStorage(prop.getKeyLength(), prop.getAdditionalSpace());
68             PrintWriter JavaDoc out = new PrintWriter JavaDoc(System.out);
69             (new RecordsFileInspector()).inspectRecordsFile(out, rf);
70             out.flush();
71         } catch (Exception JavaDoc e) {
72             e.printStackTrace();
73         }
74     }
75 }
76
Popular Tags