KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > raw > data > ByteHolder


1 /*
2
3    Derby - Class org.apache.derby.impl.store.raw.data.ByteHolder
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.store.raw.data;
23
24 import org.apache.derby.iapi.services.sanity.SanityManager;
25
26 import java.io.IOException JavaDoc;
27 import java.io.InputStream JavaDoc;
28 import java.io.OutputStream JavaDoc;
29 import java.util.Vector JavaDoc;
30
31 /**
32   Holder for a growing sequence of bytes. The ByteHolder supports a
33   writing phase in which a caller appends bytes to the ByteHolder.
34   Later the caller may read the bytes out of the ByteHolder in
35   the order they were written.
36   */

37 public interface ByteHolder
38 {
39     /**
40       Write a byte to this ByteHolder.
41
42       <P>The ByteHolder must be in writing mode to call this.
43       */

44     public void write(int b)
45          throws IOException JavaDoc;
46     /**
47       Write len bytes of data starting at 'offset' to this ByteHolder.
48
49       <P>The ByteHolder must be in writing mode to call this.
50       */

51     public void write(byte[] data, int offset, int len)
52          throws IOException JavaDoc;
53
54     /**
55       Write up to count bytes from an input stream to this
56       ByteHolder. This may write fewer bytes if it encounters
57       an end of file on the input stream.
58
59       @return the number of bytes written.
60       @exception IOException thrown when reading in causes an
61       error.
62       */

63     public long write(InputStream JavaDoc in, long count)
64          throws IOException JavaDoc;
65
66     /**
67       Clear the bytes from the ByteHolder and place it in writing
68       mode. This may not free the memory the ByteHolder uses to
69       store data.
70       */

71     public void clear()
72          throws IOException JavaDoc;
73
74     /**
75       Place a ByteHolder in reading mode. After this call,
76       reads scan bytes sequentially in the order they were
77       written to the ByteHolder starting from the first byte.
78       When the ByteHolder is already in readmode this simply
79       arranges for reads to start at the beginning of the
80       sequence of saved bytes.
81       */

82     public void startReading()
83         throws IOException JavaDoc;
84
85     /**
86       Read a byte from this ByteHolder.
87
88       <P>The ByteHolder must be in reading mode to call this.
89
90       @return The byte or -1 if there are no bytes available.
91       */

92     public int read()
93          throws IOException JavaDoc;
94
95     /**
96       Read up to 'len' bytes from this ByteHolder and store them in
97       an array at offset 'off'.
98
99       <P>The ByteHolder must be in reading mode to call this.
100
101       @return the number of bytes read or -1 if the this ByteHolder
102       has no more bytes.
103       */

104     public int read(byte b[],
105                     int off,
106                     int len)
107          throws IOException JavaDoc;
108
109     /**
110       Read from the ByteHolder.
111       <p>
112       Read up to 'len' bytes from this ByteHolder and write them to
113       the OutputStream
114
115       <P>The ByteHolder must be in reading mode to call this.
116
117       @return the number of bytes read or -1 if the this ByteHolder
118       has no more bytes.
119       */

120     public int read(OutputStream JavaDoc out,
121                     int len)
122          throws IOException JavaDoc;
123
124     /**
125       shift the remaining unread bytes to the beginning of the byte holder
126       */

127     public int shiftToFront()
128         throws IOException JavaDoc;
129
130     /**
131       Return the number of bytes that can be read from this ByteHolder
132       without blocking on an IO.
133       */

134     public int available()
135          throws IOException JavaDoc;
136
137     /**
138       Return the number of bytes that have been saved to this byte holder.
139       This result is different from available() as it is unaffected by the
140       current read position on the ByteHolder.
141       */

142     public int numBytesSaved()
143          throws IOException JavaDoc;
144
145     /**
146       Skip over the specified number of bytes in a ByteHolder.
147       */

148     public long skip(long count)
149          throws IOException JavaDoc;
150
151     /**
152       Return true if this is in writing mode.
153       */

154     public boolean writingMode();
155 }
156
Popular Tags