2
Copyright (C) 2006, 2007 Jeroen Frijters
4
This software is provided 'as-is', without any express or implied
5
warranty. In no event will the authors be held liable for any damages
6
arising from the use of this software.
8
Permission is granted to anyone to use this software for any purpose,
9
including commercial applications, and to alter it and redistribute it
10
freely, subject to the following restrictions:
12
1. The origin of this software must not be misrepresented; you must not
13
claim that you wrote the original software. If you use this software
14
in a product, an acknowledgment in the product documentation would be
15
appreciated but is not required.
16
2. Altered source versions must be plainly marked as such, and must not be
17
misrepresented as being the original software.
18
3. This notice may not be removed or altered from any source distribution.
27
public final class InputStreamWrapper extends java.io.InputStream
29
private cli.System.IO.Stream stream;
30
private long markPosition = -1;
31
private boolean atEOF;
33
public InputStreamWrapper(cli.System.IO.Stream stream)
38
public int read() throws java.io.IOException
42
if (false) throw new cli.System.IO.IOException();
43
if (false) throw new cli.System.ObjectDisposedException(null);
44
int i = stream.ReadByte();
51
catch (cli.System.IO.IOException x)
53
java.io.IOException ex = new java.io.IOException();
57
catch (cli.System.ObjectDisposedException x)
59
java.io.IOException ex = new java.io.IOException();
65
public int read(byte[] b) throws java.io.IOException
67
return read(b, 0, b.length);
70
public int read(byte[] b, int off, int len) throws java.io.IOException
74
throw new NullPointerException();
76
if (off < 0 || len < 0 || b.length - off < len)
78
throw new IndexOutOfBoundsException();
86
if (false) throw new cli.System.IO.IOException();
87
if (false) throw new cli.System.ObjectDisposedException(null);
88
int count = stream.Read(b, off, len);
96
catch (cli.System.IO.IOException x)
98
java.io.IOException ex = new java.io.IOException();
102
catch (cli.System.ObjectDisposedException x)
104
java.io.IOException ex = new java.io.IOException();
110
public long skip(long n) throws java.io.IOException
116
else if (stream.get_CanSeek())
120
if (false) throw new cli.System.IO.IOException();
121
if (false) throw new cli.System.ObjectDisposedException(null);
122
long pos = stream.get_Position();
123
n = Math.min(n, Math.max(0, stream.get_Length() - pos));
124
stream.set_Position(pos + n);
127
catch (cli.System.IO.IOException x)
129
java.io.IOException ex = new java.io.IOException();
133
catch (cli.System.ObjectDisposedException x)
135
java.io.IOException ex = new java.io.IOException();
142
return super.skip(n);
146
public int available() throws java.io.IOException
148
if (stream.get_CanSeek())
152
if (false) throw new cli.System.IO.IOException();
153
if (false) throw new cli.System.ObjectDisposedException(null);
154
long val = stream.get_Length() - stream.get_Position();
155
return (int)Math.min(Math.max(val, 0), Integer.MAX_VALUE);
157
catch (cli.System.IO.IOException x)
159
java.io.IOException ex = new java.io.IOException();
163
catch (cli.System.ObjectDisposedException x)
165
java.io.IOException ex = new java.io.IOException();
172
// It turns out that it's important that available() return non-zero when
173
// data is still available, because BufferedInputStream uses the non-zero
174
// return value as a cue to continue reading.
175
// As suggested by Mark Reinhold, we emulate InflaterInputStream's behavior
176
// and return 0 after we've reached EOF and otherwise 1.
177
return atEOF ? 0 : 1;
181
public void close() throws java.io.IOException
186
public void mark(int readlimit)
188
if (stream.get_CanSeek())
192
if (false) throw new cli.System.IO.IOException();
193
if (false) throw new cli.System.ObjectDisposedException(null);
194
markPosition = stream.get_Position();
196
catch (cli.System.IO.IOException x)
199
catch (cli.System.ObjectDisposedException x)
205
public void reset() throws java.io.IOException
207
if (!stream.get_CanSeek())
209
throw new java.io.IOException("mark/reset not supported");
211
if (markPosition == -1)
213
throw new java.io.IOException("no mark available");
217
if (false) throw new cli.System.IO.IOException();
218
if (false) throw new cli.System.ObjectDisposedException(null);
219
stream.set_Position(markPosition);
221
catch (cli.System.IO.IOException x)
223
java.io.IOException ex = new java.io.IOException();
227
catch (cli.System.ObjectDisposedException x)
229
java.io.IOException ex = new java.io.IOException();
235
public boolean markSupported()
237
return stream.get_CanSeek();