1 /*
2 * WKB4J - WKB reader for geographical mapping toolkits
3 * (C) 2002,2003, David Garnier, dgarnier@users.sourceforge.net
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation,
8 * version 2.1 of the License.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * or visit the web to http://www.gnu.org.
19 *
20 */
21
22 package org.wkb4j.engine;
23
24 import java.io.ByteArrayInputStream;
25
26 /***
27 * <code>ResetableByteArrayInputStream</code> is a <code>ByteArrayInputStream</code> where
28 * the internal buffer can be reinitialized with a new input buffer, removing the need for destroying
29 * and recreating a different <code>ByteArrayInputStream</code> for each input buffer. It is especially useful
30 * if several other InputStreams are layered on top of it.
31 * @author David Garnier
32 * <br>Creation date: 3 juil. 2002 00:08:32
33 * @version $Revision: 1.4 $ $Date: 2003/06/14 22:31:26 $
34 */
35
36 public class ResetableByteArrayInputStream extends ByteArrayInputStream {
37
38 /***
39 * Creates a <code>ResetableByteArrayInputStream</code>
40 * so that it uses <code>buf</code> as its
41 * buffer array.
42 * The buffer array is not copied.
43 * The initial value of <code>pos</code>
44 * is <code>0</code> and the initial value
45 * of <code>count</code> is the length of
46 * <code>buf</code>.
47 *
48 * @param buf the input buffer.
49 */
50 public ResetableByteArrayInputStream(byte[] buf) {
51 super(buf);
52 }
53
54 /***
55 * Creates <code>ResetableByteArrayInputStream</code>
56 * that uses <code>buf</code> as its
57 * buffer array. The initial value of <code>pos</code>
58 * is <code>offset</code> and the initial value
59 * of <code>count</code> is <code>offset+len</code>.
60 * The buffer array is not copied. The buffer's mark is
61 * set to the specified offset.
62 *
63 * @param buf the input buffer.
64 * @param offset the offset in the buffer of the first byte to read.
65 * @param length the maximum number of bytes to read from the buffer.
66 */
67 public ResetableByteArrayInputStream(byte[] buf, int offset, int length) {
68 super(buf, offset, length);
69 }
70
71 /*** Reset an ResetableByteArrayInputStream to its prime state. When this method return,
72 * this ResetableByteArrayInputStream is in exactly the same state as if it was just instantiated with the same
73 * arguments.
74 * @param buf the input buffer.
75 * @param offset the offset in the buffer of the first byte to read.
76 * @param length the maximum number of bytes to read from the buffer.
77 * */
78 public final void reset(byte[] newBuf) {
79 buf = newBuf;
80 count = newBuf.length;
81 mark = 0;
82 pos = 0;
83 }
84
85 /*** Reset an ResetableByteArrayInputStream to its prime state. When this method return,
86 * this ResetableByteArrayInputStream is in exactly the same state as if it was just instantiated with the same
87 * arguments.
88 *
89 * @param buf the input buffer.
90 * @param offset the offset in the buffer of the first byte to read.
91 * @param length the maximum number of bytes to read from the buffer.
92 * */
93 public final void reset(byte[] newBuf, int offset, int length) {
94 buf = newBuf;
95 count = Math.min(length + offset, buf.length);
96 mark = 0;
97 pos = offset;
98 }
99
100 /***
101 * This method was subclassed here because in is synchronized in the default implementation and we don't need that.
102 * <br/>See the general contract for read in ByteArrayInputStream.*/
103 public final int read() {
104 return (pos < count) ? (buf[pos++] & 0xff) : -1;
105 }
106
107 }
This page was automatically generated by Maven