01: /**
02: * com.mckoi.store.AreaWriter 07 Jun 2003
03: *
04: * Mckoi SQL Database ( http://www.mckoi.com/database )
05: * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * 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: */package com.mckoi.store;
24:
25: import java.io.OutputStream;
26: import java.io.IOException;
27:
28: /**
29: * The interface used for setting up an area initially in a store. This method
30: * is intended to optimize the area creation process. Typically an area is
31: * created at a specified size and filled with data. This area should be
32: * used as follows;
33: * <p><pre>
34: * AreaWriter writer = store.createArea(16);
35: * writer.putInt(3);
36: * writer.putLong(100030);
37: * writer.putByte(1);
38: * writer.putShort(0);
39: * writer.putByte(2);
40: * writer.finish();
41: * </pre></p>
42: * When the 'finish' method is called, the AreaWriter object is invalidated and
43: * the area can then be accessed in the store by the 'getArea' method.
44: * <p>
45: * Note that an area may only be written sequentially using this object. This
46: * is by design and allows for the area initialization process to be optimized.
47: *
48: * @author Tobias Downer
49: */
50:
51: public interface AreaWriter {
52:
53: /**
54: * Returns the unique identifier that represents this area in the store.
55: */
56: long getID();
57:
58: /**
59: * Returns an OutputStream that can be used to write to this area. This
60: * stream is backed by this area writer, so if 10 bytes area written to the
61: * output stream then the writer position is also incremented by 10 bytes.
62: */
63: OutputStream getOutputStream();
64:
65: /**
66: * Returns the size of this area.
67: */
68: int capacity();
69:
70: /**
71: * Finishes the area writer object. This must be called when the area is
72: * completely initialized. After this method is called the object is
73: * invalidated and the area can be accessed in the store.
74: */
75: void finish() throws IOException;
76:
77: // ---------- Various put methods ----------
78:
79: void put(byte b) throws IOException;
80:
81: void put(byte[] buf, int off, int len) throws IOException;
82:
83: void put(byte[] buf) throws IOException;
84:
85: void putShort(short s) throws IOException;
86:
87: void putInt(int i) throws IOException;
88:
89: void putLong(long l) throws IOException;
90:
91: void putChar(char c) throws IOException;
92:
93: }
|