KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > output2 > Storage


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * Storage.java
21  *
22  * Created on May 14, 2004, 1:40 PM
23  */

24
25 package org.netbeans.core.output2;
26
27 import java.io.IOException JavaDoc;
28 import java.nio.ByteBuffer JavaDoc;
29
30 /**
31  * Storage abstraction for output writer - plan is to eventually do both
32  * heap-based and mapped file based storages.
33  *
34  * @author Tim Boudreau, Jesse Glick
35  */

36 interface Storage {
37     /**
38      * Get a ByteBuffer for reading over the storage, starting at the specified byte position and containing the
39      * specified number of bytes
40      *
41      * @param start The start byte
42      * @param length How many bytes
43      * @return A byte buffer
44      * @throws IOException if there is a problem reading or allocating the buffer
45      */

46     public ByteBuffer JavaDoc getReadBuffer (int start, int length) throws IOException JavaDoc;
47     /**
48      * Get a buffer for <strong>appending</strong> <code>length</code> bytes to the stored data. Note that
49      * writing into the returned buffer does not automatically write to the file - the returned buffer should
50      * be passed to <code>write(ByteBuffer b)</code> to be saved once it has been filled.
51      *
52      * @param length The number of bytes to write
53      * @return
54      * @throws IOException
55      */

56     public ByteBuffer JavaDoc getWriteBuffer (int length) throws IOException JavaDoc;
57     /**
58      * Write a ByteBuffer (presumably obtained from getWriteBuffer()) to persistent storage. The buffer
59      * may be underfilled; data will be written to the <code>limit</code> of the ByteBuffer, disregarding any
60      * additional capacity.
61      *
62      * @param buf A ByteBuffer with data to write
63      * @param addNewLine true if the storage should append a newline after writing the buffer
64      * @return The byte position of the <strong>start</strong> of data written
65      * @throws IOException if there is a problem writing the data
66      */

67     public int write (ByteBuffer JavaDoc buf, boolean addNewLine) throws IOException JavaDoc;
68
69     /**
70      * Dispose of this storage, deleting all associated resources, files, data storage, etc. This should only
71      * be called after it is absolutely certain that nothing will try to write further data to the storage.
72      *
73      */

74     public void dispose ();
75
76     /**
77      * The number of bytes currently occupied by written data
78      *
79      * @return A byte count
80      */

81     public int size();
82
83     /**
84      * For storages that implement a lazy writing scheme, force any pending data to be written to the storage.
85      *
86      * @throws IOException If there is a problem writing the data
87      */

88     public void flush() throws IOException JavaDoc;
89
90     /**
91      * Close the storage for <strong>writing</strong> disposing of any resources used for writing to the storage,
92      * but leaving it in a state where it may be read, calling <code>flush()</code> if necessary. Subsequent calls
93      * to write methods may reopen the storage for writing as needed.
94      *
95      * @throws IOException If there is a problem writing to the persistent storage
96      */

97     public void close() throws IOException JavaDoc;
98
99     /**
100      * Determine if close() has been called on this storage. Primarily used for cases where the gui should
101      * display some status information if a process is still writing to the storage.
102      *
103      * @return true if the storage has been closed
104      */

105     public boolean isClosed();
106 }
107
Popular Tags