KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.io.*;
27
28 public class RecordReader {
29
30     public RecordReader(String JavaDoc key, byte[] data) {
31         this.key = key;
32         this.data = data;
33         in = DbByteArrayInputStream.getInstance(data);
34     }
35
36     public byte[] getData() {
37         return data;
38     }
39
40     public InputStream getInputStream() {
41         return in;
42     }
43
44     public String JavaDoc getKey() {
45         return key;
46     }
47
48     public ObjectInputStream getObjectInputStream() throws IOException {
49         if (objIn == null) {
50             objIn = new ObjectInputStream(in);
51         }
52
53         return objIn;
54     }
55
56     /**
57      * Reads the next object in the record using an ObjectInputStream.
58      */

59     public Object JavaDoc readObject()
60             throws IOException, ClassNotFoundException JavaDoc {
61         return getObjectInputStream().readObject();
62     }
63
64     public void reset() {
65         in.reset();
66     }
67
68     ByteArrayInputStream in;
69     ObjectInputStream objIn;
70     String JavaDoc key;
71     byte[] data;
72 }
73
Popular Tags