1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.jvm
.mle
;
12 import cc
.squirreljme
.jvm
.mle
.brackets
.JarPackageBracket
;
13 import cc
.squirreljme
.runtime
.cldc
.annotation
.Api
;
14 import java
.io
.IOException
;
15 import java
.io
.InputStream
;
18 * This is an input stream over the raw representation of a
19 * {@link JarPackageBracket} which might not be in the form of a JAR or any
20 * actual readable data.
25 public class RawJarPackageBracketInputStream
28 /** The given library. */
29 protected final JarPackageBracket jar
;
31 /** The size of the JAR. */
32 protected final int jarSize
;
34 /** Single byte read, as only bulk read is supported. */
35 private final byte[] _singleByte
=
38 /** The current read position. */
42 * Initializes the input stream to read the raw JAR.
44 * @param __jar The JAR to read raw data from.
45 * @throws IOException If reading from the given JAR in its
46 * raw data form is not possible.
47 * @throws NullPointerException On null arguments.
51 public RawJarPackageBracketInputStream(JarPackageBracket __jar
)
52 throws IOException
, NullPointerException
58 * Initializes the input stream to read the raw JAR.
60 * @param __jar The JAR to read raw data from.
61 * @param __offset The initial read offset.
62 * @throws IndexOutOfBoundsException If the offset is out of bounds.
63 * @throws IOException If reading from the given JAR in its
64 * raw data form is not possible.
65 * @throws NullPointerException On null arguments.
69 public RawJarPackageBracketInputStream(JarPackageBracket __jar
,
71 throws IndexOutOfBoundsException
, IOException
, NullPointerException
74 throw new NullPointerException("NARG");
76 // {@squirreljme.error ZZ3u The specified JAR cannot be accessed
77 // directly. (The JAR path)}
78 int jarSize
= JarPackageShelf
.rawSize(__jar
);
80 throw new IOException("ZZ3u " +
81 JarPackageShelf
.libraryPath(__jar
));
83 // {@squirreljme.error ZZ4j Invalid offset into direct JAR.}
84 if (__offset
< 0 || __offset
> jarSize
)
85 throw new IndexOutOfBoundsException("ZZ4j");
89 this.jarSize
= jarSize
;
90 this._readPos
= __offset
;
98 public int available()
101 return this.jarSize
- this._readPos
;
112 // Keep trying to read a single byte
113 byte[] singleByte
= this._singleByte
;
117 int read
= this.read(singleByte
, 0, 1);
123 // Use the given byte assuming it was read
125 return singleByte
[0] & 0xFF;
134 public int read(byte[] __b
, int __o
, int __l
)
135 throws IndexOutOfBoundsException
, IOException
, NullPointerException
138 throw new NullPointerException("NARG");
139 if (__o
< 0 || __l
< 0 || (__o
+ __l
) < 0 || (__o
+ __l
) > __b
.length
)
140 throw new IndexOutOfBoundsException("IOOB");
142 // Read in the JAR data
143 int readPos
= this._readPos
;
144 int count
= JarPackageShelf
.rawData(this.jar
, readPos
, __b
, __o
, __l
);
149 this._readPos
= this.jarSize
;
153 // Count up what we read
154 this._readPos
= readPos
+ count
;
156 // And use our count!