KickJava   Java API By Example, From Geeks To Geeks.

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


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 RecordWriter {
29
30     public RecordWriter(String JavaDoc key) {
31         this.key = key;
32         out = DbByteArrayOutputStream.getInstance();
33     }
34
35     /**
36      * Returns the number of bytes in the data.
37      */

38     public int getDataLength() {
39         return out.size();
40     }
41
42     public void setKey(String JavaDoc key) {
43         this.key = key;
44     }
45
46     public String JavaDoc getKey() {
47         return key;
48     }
49
50     public ObjectOutputStream getObjectOutputStream() throws IOException {
51         if (objOut == null) {
52             objOut = new ObjectOutputStream(out);
53         }
54         return objOut;
55     }
56
57     public OutputStream getOutputStream() {
58         return out;
59     }
60
61     public DbByteArrayOutputStream getOut() {
62         return out;
63     }
64
65     public void writeObject(Object JavaDoc o) throws IOException {
66         getObjectOutputStream().writeObject(o);
67         getObjectOutputStream().flush();
68     }
69
70     public void writeDatas(byte[] datas) throws IOException {
71         out.writeDatas(datas);
72     }
73
74     /**
75      * Writes the data out to the stream without re-allocating the buffer.
76      */

77     public void writeTo(DataOutput str) throws IOException {
78         out.writeTo(str);
79     }
80
81     public void reset() {
82         out.reset();
83     }
84
85     private DbByteArrayOutputStream out;
86     private ObjectOutputStream objOut;
87     private String JavaDoc key;
88 }
89
Popular Tags