/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* An abstract class implementing the <code>ImageInputStream</code> interface.
* This class is designed to reduce the number of methods that must
* be implemented by subclasses.
*
* <p> In particular, this class handles most or all of the details of
* closing, and disposing.
*/
private boolean isClosed = false;
// Length of the buffer used for readFully(type[], int, int)
/**
* Byte buffer used for readFully(type[], int, int). Note that this
* array is also used for bulk reads in readShort(), readInt(), etc, so
* it should be large enough to hold a primitive value (i.e. >= 8 bytes).
* Also note that this array is package protected, so that it can be
* used by ImageOutputStreamImpl in a similar manner.
*/
/**
* The byte order of the stream as an instance of the enumeration
* class <code>java.nio.ByteOrder</code>, where
* <code>ByteOrder.BIG_ENDIAN</code> indicates network byte order
* and <code>ByteOrder.LITTLE_ENDIAN</code> indicates the reverse
* order. By default, the value is
* <code>ByteOrder.BIG_ENDIAN</code>.
*/
/**
* The current read position within the stream. Subclasses are
* responsible for keeping this value current from any method they
* override that alters the read position.
*/
protected long streamPos;
/**
* The current bit offset within the stream. Subclasses are
* responsible for keeping this value current from any method they
* override that alters the bit offset.
*/
protected int bitOffset;
/**
* The position prior to which data may be discarded. Seeking
* to a smaller position is not allowed. <code>flushedPos</code>
* will always be >= 0.
*/
/**
* Constructs an <code>ImageInputStreamImpl</code>.
*/
public ImageInputStreamImpl() {
}
/**
* Throws an <code>IOException</code> if the stream has been closed.
* Subclasses may call this method from any of their methods that
* require the stream not to be closed.
*
* @exception IOException if the stream is closed.
*/
if (isClosed) {
throw new IOException("closed");
}
}
}
return byteOrder;
}
/**
* Reads a single byte from the stream and returns it as an
* <code>int</code> between 0 and 255. If EOF is reached,
* <code>-1</code> is returned.
*
* <p> Subclasses must provide an implementation for this method.
* The subclass implementation should update the stream position
* before exiting.
*
* <p> The bit offset within the stream must be reset to zero before
* the read occurs.
*
* @return the value of the next byte in the stream, or <code>-1</code>
* if EOF is reached.
*
* @exception IOException if the stream has been closed.
*/
/**
* A convenience method that calls <code>read(b, 0, b.length)</code>.
*
* <p> The bit offset within the stream is reset to zero before
* the read occurs.
*
* @return the number of bytes actually read, or <code>-1</code>
* to indicate EOF.
*
* @exception NullPointerException if <code>b</code> is
* <code>null</code>.
* @exception IOException if an I/O error occurs.
*/
}
/**
* Reads up to <code>len</code> bytes from the stream, and stores
* them into <code>b</code> starting at index <code>off</code>.
* If no bytes can be read because the end of the stream has been
* reached, <code>-1</code> is returned.
*
* <p> The bit offset within the stream must be reset to zero before
* the read occurs.
*
* <p> Subclasses must provide an implementation for this method.
* The subclass implementation should update the stream position
* before exiting.
*
* @param b an array of bytes to be written to.
* @param off the starting position within <code>b</code> to write to.
* @param len the maximum number of bytes to read.
*
* @return the number of bytes actually read, or <code>-1</code>
* to indicate EOF.
*
* @exception IndexOutOfBoundsException if <code>off</code> is
* negative, <code>len</code> is negative, or <code>off +
* len</code> is greater than <code>b.length</code>.
* @exception NullPointerException if <code>b</code> is
* <code>null</code>.
* @exception IOException if an I/O error occurs.
*/
if (len < 0) {
throw new IndexOutOfBoundsException("len < 0!");
}
throw new NullPointerException("buf == null!");
}
}
if (ch < 0) {
throw new EOFException();
}
return (ch != 0);
}
if (ch < 0) {
throw new EOFException();
}
return (byte)ch;
}
if (ch < 0) {
throw new EOFException();
}
return ch;
}
throw new EOFException();
}
return (short)
} else {
return (short)
}
}
return ((int)readShort()) & 0xffff;
}
return (char)readShort();
}
throw new EOFException();
}
return
} else {
return
}
}
return ((long)readInt()) & 0xffffffffL;
}
// REMIND: Once 6277756 is fixed, we should do a bulk read of all 8
// bytes here as we do in readShort() and readInt() for even better
// performance (see 6347575 for details).
} else {
}
}
}
}
int c = -1;
boolean eol = false;
while (!eol) {
switch (c = read()) {
case -1:
case '\n':
eol = true;
break;
case '\r':
eol = true;
long cur = getStreamPosition();
if ((read()) != '\n') {
}
break;
default:
break;
}
}
return null;
}
}
this.bitOffset = 0;
// Fix 4494369: method ImageInputStreamImpl.readUTF()
// does not work as specified (it should always assume
// network byte order).
try {
} catch (IOException e) {
// Restore the old byte order even if an exception occurs
throw e;
}
return ret;
}
// Fix 4430357 - if off + len < 0, overflow occurred
throw new IndexOutOfBoundsException
("off < 0 || len < 0 || off + len > b.length!");
}
while (len > 0) {
if (nbytes == -1) {
throw new EOFException();
}
}
}
}
// Fix 4430357 - if off + len < 0, overflow occurred
throw new IndexOutOfBoundsException
("off < 0 || len < 0 || off + len > s.length!");
}
while (len > 0) {
}
}
// Fix 4430357 - if off + len < 0, overflow occurred
throw new IndexOutOfBoundsException
("off < 0 || len < 0 || off + len > c.length!");
}
while (len > 0) {
}
}
// Fix 4430357 - if off + len < 0, overflow occurred
throw new IndexOutOfBoundsException
("off < 0 || len < 0 || off + len > i.length!");
}
while (len > 0) {
}
}
// Fix 4430357 - if off + len < 0, overflow occurred
throw new IndexOutOfBoundsException
("off < 0 || len < 0 || off + len > l.length!");
}
while (len > 0) {
}
}
// Fix 4430357 - if off + len < 0, overflow occurred
throw new IndexOutOfBoundsException
("off < 0 || len < 0 || off + len > f.length!");
}
while (len > 0) {
}
}
// Fix 4430357 - if off + len < 0, overflow occurred
throw new IndexOutOfBoundsException
("off < 0 || len < 0 || off + len > d.length!");
}
while (len > 0) {
}
}
int boff = 0;
for (int j = 0; j < len; j++) {
boff += 2;
}
} else {
for (int j = 0; j < len; j++) {
boff += 2;
}
}
}
int boff = 0;
for (int j = 0; j < len; j++) {
boff += 2;
}
} else {
for (int j = 0; j < len; j++) {
boff += 2;
}
}
}
int boff = 0;
for (int j = 0; j < len; j++) {
boff += 4;
}
} else {
for (int j = 0; j < len; j++) {
boff += 4;
}
}
}
int boff = 0;
for (int j = 0; j < len; j++) {
boff += 8;
}
} else {
for (int j = 0; j < len; j++) {
boff += 8;
}
}
}
int boff = 0;
for (int j = 0; j < len; j++) {
boff += 4;
}
} else {
for (int j = 0; j < len; j++) {
boff += 4;
}
}
}
int boff = 0;
for (int j = 0; j < len; j++) {
boff += 8;
}
} else {
for (int j = 0; j < len; j++) {
boff += 8;
}
}
}
checkClosed();
return streamPos;
}
checkClosed();
return bitOffset;
}
checkClosed();
throw new IllegalArgumentException("bitOffset must be betwwen 0 and 7!");
}
}
checkClosed();
// Compute final bit offset before we call read() and seek()
if (val == -1) {
throw new EOFException();
}
if (newBitOffset != 0) {
// Move byte position back if in the middle of a byte
// Shift the bit to be read to the rightmost position
}
this.bitOffset = newBitOffset;
return val & 0x1;
}
checkClosed();
throw new IllegalArgumentException();
}
if (numBits == 0) {
return 0L;
}
// Have to read additional bits on the left equal to the bit offset
// Compute final bit offset before we call read() and seek()
// Read a byte at a time, accumulate
long accum = 0L;
while (bitsToRead > 0) {
if (val == -1) {
throw new EOFException();
}
accum <<= 8;
bitsToRead -= 8;
}
// Move byte position back if in the middle of a byte
if (newBitOffset != 0) {
}
this.bitOffset = newBitOffset;
// Shift away unwanted bits on the right.
// Mask out unwanted bits on the left
return accum;
}
/**
* Returns <code>-1L</code> to indicate that the stream has unknown
* length. Subclasses must override this method to provide actual
* length information.
*
* @return -1L to indicate unknown length.
*/
public long length() {
return -1L;
}
/**
* Advances the current stream position by calling
* <code>seek(getStreamPosition() + n)</code>.
*
* <p> The bit offset is reset to zero.
*
* @param n the number of bytes to seek forward.
*
* @return an <code>int</code> representing the number of bytes
* skipped.
*
* @exception IOException if <code>getStreamPosition</code>
* throws an <code>IOException</code> when computing either
* the starting or ending position.
*/
long pos = getStreamPosition();
return (int)(getStreamPosition() - pos);
}
/**
* Advances the current stream position by calling
* <code>seek(getStreamPosition() + n)</code>.
*
* <p> The bit offset is reset to zero.
*
* @param n the number of bytes to seek forward.
*
* @return a <code>long</code> representing the number of bytes
* skipped.
*
* @exception IOException if <code>getStreamPosition</code>
* throws an <code>IOException</code> when computing either
* the starting or ending position.
*/
long pos = getStreamPosition();
return getStreamPosition() - pos;
}
checkClosed();
// This test also covers pos < 0
if (pos < flushedPos) {
throw new IndexOutOfBoundsException("pos < flushedPos!");
}
this.bitOffset = 0;
}
/**
* Pushes the current stream position onto a stack of marked
* positions.
*/
public void mark() {
try {
} catch (IOException e) {
}
}
/**
* Resets the current stream byte and bit positions from the stack
* of marked positions.
*
* <p> An <code>IOException</code> will be thrown if the previous
* marked position lies in the discarded portion of the stream.
*
* @exception IOException if an I/O error occurs.
*/
if (markByteStack.empty()) {
return;
}
if (pos < flushedPos) {
throw new IIOException
("Previous marked position has been discarded!");
}
}
checkClosed();
if (pos < flushedPos) {
throw new IndexOutOfBoundsException("pos < flushedPos!");
}
if (pos > getStreamPosition()) {
throw new IndexOutOfBoundsException("pos > getStreamPosition()!");
}
// Invariant: flushedPos >= 0
flushedPos = pos;
}
}
public long getFlushedPosition() {
return flushedPos;
}
/**
* Default implementation returns false. Subclasses should
* override this if they cache data.
*/
public boolean isCached() {
return false;
}
/**
* Default implementation returns false. Subclasses should
* override this if they cache data in main memory.
*/
public boolean isCachedMemory() {
return false;
}
/**
* Default implementation returns false. Subclasses should
* override this if they cache data in a temporary file.
*/
public boolean isCachedFile() {
return false;
}
checkClosed();
isClosed = true;
}
/**
* Finalizes this object prior to garbage collection. The
* <code>close</code> method is called to close any open input
* source. This method should not be called from application
* code.
*
* @exception Throwable if an error occurs during superclass
* finalization.
*/
if (!isClosed) {
try {
close();
} catch (IOException e) {
}
}
super.finalize();
}
}