01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.catalina.tribes.tipis;
18:
19: import java.io.IOException;
20:
21: /**
22: * Example usage:
23: * <code><pre>
24: * byte[] data = new byte[1024];
25: * Streamable st = ....;
26: * while ( !st.eof() ) {
27: * int length = st.read(data,0,data.length);
28: * String s = new String(data,0,length);
29: * System.out.println(s);
30: * }
31: * </pre></code>
32: * @author Filip Hanik
33: * @version 1.0
34: */
35: public interface Streamable {
36:
37: /**
38: * returns true if the stream has reached its end
39: * @return boolean
40: */
41: public boolean eof();
42:
43: /**
44: * write data into the byte array starting at offset, maximum bytes read are (data.length-offset)
45: * @param data byte[] - the array to read data into
46: * @param offset int - start position for writing data
47: * @return int - the number of bytes written into the data buffer
48: */
49: public int write(byte[] data, int offset, int length)
50: throws IOException;
51:
52: /**
53: * read data into the byte array starting at offset
54: * @param data byte[] - the array to read data into
55: * @param offset int - start position for writing data
56: * @param length - the desired read length
57: * @return int - the number of bytes read from the data buffer
58: */
59: public int read(byte[] data, int offset, int length)
60: throws IOException;
61:
62: }
|