KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mckoi > store > AreaWriter


1 /**
2  * com.mckoi.store.AreaWriter 07 Jun 2003
3  *
4  * Mckoi SQL Database ( http://www.mckoi.com/database )
5  * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * Version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License Version 2 for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * Version 2 along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  * Change Log:
21  *
22  *
23  */

24
25 package com.mckoi.store;
26
27 import java.io.OutputStream JavaDoc;
28 import java.io.IOException JavaDoc;
29
30 /**
31  * The interface used for setting up an area initially in a store. This method
32  * is intended to optimize the area creation process. Typically an area is
33  * created at a specified size and filled with data. This area should be
34  * used as follows;
35  * <p><pre>
36  * AreaWriter writer = store.createArea(16);
37  * writer.putInt(3);
38  * writer.putLong(100030);
39  * writer.putByte(1);
40  * writer.putShort(0);
41  * writer.putByte(2);
42  * writer.finish();
43  * </pre></p>
44  * When the 'finish' method is called, the AreaWriter object is invalidated and
45  * the area can then be accessed in the store by the 'getArea' method.
46  * <p>
47  * Note that an area may only be written sequentially using this object. This
48  * is by design and allows for the area initialization process to be optimized.
49  *
50  * @author Tobias Downer
51  */

52
53 public interface AreaWriter {
54
55   /**
56    * Returns the unique identifier that represents this area in the store.
57    */

58   long getID();
59
60   /**
61    * Returns an OutputStream that can be used to write to this area. This
62    * stream is backed by this area writer, so if 10 bytes area written to the
63    * output stream then the writer position is also incremented by 10 bytes.
64    */

65   OutputStream JavaDoc getOutputStream();
66   
67   /**
68    * Returns the size of this area.
69    */

70   int capacity();
71
72   /**
73    * Finishes the area writer object. This must be called when the area is
74    * completely initialized. After this method is called the object is
75    * invalidated and the area can be accessed in the store.
76    */

77   void finish() throws IOException JavaDoc;
78
79   // ---------- Various put methods ----------
80

81   void put(byte b) throws IOException JavaDoc;
82
83   void put(byte[] buf, int off, int len) throws IOException JavaDoc;
84   
85   void put(byte[] buf) throws IOException JavaDoc;
86
87   void putShort(short s) throws IOException JavaDoc;
88
89   void putInt(int i) throws IOException JavaDoc;
90
91   void putLong(long l) throws IOException JavaDoc;
92
93   void putChar(char c) throws IOException JavaDoc;
94
95 }
96
97
Popular Tags