3030 */
3131public class BaseNCodecInputStream extends FilterInputStream {
3232
33- private final boolean doEncode ;
34-
3533 private final BaseNCodec baseNCodec ;
3634
35+ private final boolean doEncode ;
36+
3737 private final byte [] singleByte = new byte [1 ];
3838
3939 protected BaseNCodecInputStream (InputStream in , BaseNCodec baseNCodec , boolean doEncode ) {
@@ -42,6 +42,31 @@ protected BaseNCodecInputStream(InputStream in, BaseNCodec baseNCodec, boolean d
4242 this .baseNCodec = baseNCodec ;
4343 }
4444
45+ /**
46+ * {@inheritDoc}
47+ *
48+ * @return <code>0</code> if the {@link InputStream} has reached <code>EOF</code>,
49+ * <code>1</code> otherwise
50+ */
51+ public int available () throws IOException {
52+ // Note: the logic is similar to the InflaterInputStream:
53+ // as long as we have not reached EOF, indicate that there is more
54+ // data available. As we do not know for sure how much data is left,
55+ // just return 1 as a safe guess.
56+
57+ // use the EOF flag of the underlying codec instance
58+ return baseNCodec .eof ? 0 : 1 ;
59+ }
60+
61+ /**
62+ * {@inheritDoc}
63+ *
64+ * @return false
65+ */
66+ @ Override
67+ public boolean markSupported () {
68+ return false ; // not an easy job to support marks
69+ }
4570 /**
4671 * Reads one <code>byte</code> from this input stream.
4772 *
@@ -124,15 +149,6 @@ public int read(byte b[], int offset, int len) throws IOException {
124149 return readLen ;
125150 }
126151 }
127- /**
128- * {@inheritDoc}
129- *
130- * @return false
131- */
132- @ Override
133- public boolean markSupported () {
134- return false ; // not an easy job to support marks
135- }
136152
137153 /**
138154 * {@inheritDoc}
@@ -142,7 +158,7 @@ public boolean markSupported() {
142158 @ Override
143159 public long skip (long n ) throws IOException {
144160 if (n < 0 ) {
145- throw new IllegalArgumentException ("Negative skip length" );
161+ throw new IllegalArgumentException ("Negative skip length: " + n );
146162 }
147163
148164 // skip in chunks of 512 bytes
@@ -164,24 +180,4 @@ public long skip(long n) throws IOException {
164180
165181 return total ;
166182 }
167-
168- /**
169- * {@inheritDoc}
170- *
171- * @return <code>0</code> if the {@link InputStream} has reached <code>EOF</code>,
172- * <code>1</code> otherwise
173- */
174- public int available () throws IOException {
175- // Note: the logic is similar to the InflaterInputStream:
176- // as long as we have not reached EOF, indicate that there is more
177- // data available. As we do not know for sure how much data is left,
178- // just return 1 as a safe guess.
179-
180- // use the EOF flag of the underlying codec instance
181- if (baseNCodec .eof ) {
182- return 0 ;
183- } else {
184- return 1 ;
185- }
186- }
187183}
0 commit comments