diff --git a/twelvemonkeys-imageio/core/src/main/java/com/twelvemonkeys/imageio/stream/BufferedImageInputStream.java b/twelvemonkeys-imageio/core/src/main/java/com/twelvemonkeys/imageio/stream/BufferedImageInputStream.java index a396734c..0b958056 100644 --- a/twelvemonkeys-imageio/core/src/main/java/com/twelvemonkeys/imageio/stream/BufferedImageInputStream.java +++ b/twelvemonkeys-imageio/core/src/main/java/com/twelvemonkeys/imageio/stream/BufferedImageInputStream.java @@ -53,6 +53,7 @@ public final class BufferedImageInputStream extends ImageInputStreamImpl impleme if (!isBufferValid()) { fillBuffer(); } + if (mBufferLength <= 0) { return -1; } @@ -67,7 +68,6 @@ public final class BufferedImageInputStream extends ImageInputStreamImpl impleme public int read(final byte[] pBuffer, final int pOffset, final int pLength) throws IOException { bitOffset = 0; - // TODO: Consider fixing the bypass buffer code... if (!isBufferValid()) { // Bypass cache if cache is empty for reads longer than buffer if (pLength >= mBuffer.length) { @@ -82,20 +82,13 @@ public final class BufferedImageInputStream extends ImageInputStreamImpl impleme } private int readDirect(final byte[] pBuffer, final int pOffset, final int pLength) throws IOException { -// System.err.println("BEFORE streamPos: " + streamPos); -// System.err.println("BEFORE mStream.getStreamPosition(): " + mStream.getStreamPosition()); - + // TODO: Figure out why reading more than the buffer length causes alignment issues... int read = mStream.read(pBuffer, pOffset, Math.min(mBuffer.length, pLength)); if (read > 0) { streamPos += read; } -// System.err.println("AFTER streamPos: " + streamPos); -// System.err.println("AFTER mStream.getStreamPosition(): " + mStream.getStreamPosition()); -// System.err.println(); - - mBufferStart = mStream.getStreamPosition(); mBufferLength = 0; @@ -123,7 +116,7 @@ public final class BufferedImageInputStream extends ImageInputStreamImpl impleme @Override public void seek(long pPosition) throws IOException { - // TODO: Could probably be optimized to not invalidate buffer if new pos is within current buffer + // TODO: Could probably be optimized to not invalidate buffer if new position is within current buffer mStream.seek(pPosition); mBufferLength = 0; // Will invalidate buffer streamPos = mStream.getStreamPosition(); diff --git a/twelvemonkeys-imageio/core/src/main/java/com/twelvemonkeys/imageio/stream/URLImageInputStreamSpi.java b/twelvemonkeys-imageio/core/src/main/java/com/twelvemonkeys/imageio/stream/URLImageInputStreamSpi.java old mode 100755 new mode 100644 index 7518bc0a..64c1ae6e --- a/twelvemonkeys-imageio/core/src/main/java/com/twelvemonkeys/imageio/stream/URLImageInputStreamSpi.java +++ b/twelvemonkeys-imageio/core/src/main/java/com/twelvemonkeys/imageio/stream/URLImageInputStreamSpi.java @@ -37,9 +37,9 @@ public class URLImageInputStreamSpi extends ImageInputStreamSpi { if ("file".equals(url.getProtocol())) { try { return new BufferedImageInputStream(new FileImageInputStream(new File(url.toURI()))); -// return new FileImageInputStream(new File(url.toURI())); } catch (URISyntaxException ignore) { + // This should never happen, but if it does, we'll fall back to using the stream ignore.printStackTrace(); } }