01: package it.unimi.dsi.fastutil.io;
02:
03: /*
04: * fastutil: Fast & compact type-specific collections for Java
05: *
06: * Copyright (C) 2006-2008 Sebastiano Vigna
07: *
08: * This library is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU Lesser General Public
10: * License as published by the Free Software Foundation; either
11: * version 2.1 of the License, or (at your option) any later version.
12: *
13: * This library is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16: * Lesser General Public License for more details.
17: *
18: * You should have received a copy of the GNU Lesser General Public
19: * License along with this library; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21: *
22: */
23:
24: import java.io.IOException;
25: import java.io.InputStream;
26:
27: /** An {@link java.io.InputStream} that provides eager access to its length,
28: * and keeps track of the current position (e.g., the number of bytes read so far).
29: *
30: * <P>This class adds two methods, both specified as optional. This apparently bizarre
31: * behaviour is necessary because of wrapper classes which use reflection
32: * to support those methods (see, e.g., {@link FastBufferedInputStream}).
33: *
34: * @since 5.0.4
35: */
36:
37: public abstract class MeasurableInputStream extends InputStream {
38:
39: /** Returns the overall length of this input stream (optional operation). In most cases, this will require the input
40: * stream to perform some extra action, possibly changing the state of the input stream itself (typically, reading
41: * all the bytes up to the end).
42: * Implementing classes should always document what state will the input stream be in
43: * after calling this method, and which kind of exception could be thrown.
44: */
45: public abstract long length() throws IOException;
46:
47: /** Returns the current position in this input stream (optional operation).
48: *
49: * <p>Usually, the position is just the number of bytes read
50: * since the stream was opened, but in the case of a
51: * {@link it.unimi.dsi.fastutil.io.RepositionableStream} it
52: * represent the current position.
53: */
54: public abstract long position() throws IOException;
55: }
|