Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 9108 invoked from network); 6 Sep 2007 07:48:32 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Sep 2007 07:48:32 -0000 Received: (qmail 27746 invoked by uid 500); 6 Sep 2007 07:48:27 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 27723 invoked by uid 500); 6 Sep 2007 07:48:27 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 27714 invoked by uid 99); 6 Sep 2007 07:48:27 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Sep 2007 00:48:27 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Sep 2007 07:49:48 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 892AC1A9832; Thu, 6 Sep 2007 00:48:06 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r573171 - in /harmony/enhanced/classlib/trunk/modules/imageio/src: main/java/javax/imageio/stream/ImageInputStreamImpl.java test/java/javax/imageio/stream/ test/java/javax/imageio/stream/ImageInputStreamImplTest.java Date: Thu, 06 Sep 2007 07:48:05 -0000 To: commits@harmony.apache.org From: apetrenko@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20070906074806.892AC1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: apetrenko Date: Thu Sep 6 00:47:57 2007 New Revision: 573171 URL: http://svn.apache.org/viewvc?rev=573171&view=rev Log: Patch for HARMONY-4742 "[classlib][imageio] There are many unimplemented methods in javax.imageio.stream.ImageInputStreamImpl" Added: harmony/enhanced/classlib/trunk/modules/imageio/src/test/java/javax/imageio/stream/ harmony/enhanced/classlib/trunk/modules/imageio/src/test/java/javax/imageio/stream/ImageInputStreamImplTest.java (with props) Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/ImageInputStreamImpl.java Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/ImageInputStreamImpl.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/ImageInputStreamImpl.java?rev=573171&r1=573170&r2=573171&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/ImageInputStreamImpl.java (original) +++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/ImageInputStreamImpl.java Thu Sep 6 00:47:57 2007 @@ -14,328 +14,444 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @author Rustem V. Rafikov - * @version $Revision: 1.3 $ - */ + package javax.imageio.stream; import java.io.EOFException; import java.io.IOException; import java.nio.ByteOrder; +import org.apache.harmony.luni.util.Util; + public abstract class ImageInputStreamImpl implements ImageInputStream { - protected ByteOrder byteOrder = ByteOrder.BIG_ENDIAN; + protected ByteOrder byteOrder = ByteOrder.BIG_ENDIAN; - protected long streamPos = 0; - protected long flushedPos = 0; - protected int bitOffset = 0; - - private boolean closed = false; - - private final PositionStack posStack = new PositionStack(); - - public ImageInputStreamImpl() {} - - protected final void checkClosed() throws IOException { - if (closed) { - throw new IOException("stream is closed"); - } - } - - public void setByteOrder(ByteOrder byteOrder) { - this.byteOrder = byteOrder; - } - - public ByteOrder getByteOrder() { - return byteOrder; - } - - public abstract int read() throws IOException; - - public int read(byte[] b) throws IOException { - return read(b, 0, b.length); - } - - public abstract int read(byte[] b, int off, int len) throws IOException; - - public void readBytes(IIOByteBuffer buf, int len) throws IOException { - if (buf == null) { - throw new NullPointerException("buffer is NULL"); - } - - byte[] b = new byte[len]; - len = read(b, 0, b.length); - - buf.setData(b); - buf.setOffset(0); - buf.setLength(len); - } - - public boolean readBoolean() throws IOException { - int b = read(); - if (b < 0) { - throw new EOFException("EOF reached"); - } - return b != 0; - } - - public byte readByte() throws IOException { - int b = read(); - if (b < 0) { - throw new EOFException("EOF reached"); - } - return (byte) b; - } - - public int readUnsignedByte() throws IOException { - int b = read(); - if (b < 0) { - throw new EOFException("EOF reached"); - } - return b; - } - - public short readShort() throws IOException { - int b1 = read(); - int b2 = read(); - - if (b1 < 0 || b2 < 0) { - throw new EOFException("EOF reached"); - } - - return byteOrder == ByteOrder.BIG_ENDIAN ? - (short) ((b1 << 8) | (b2 & 0xff)) : - (short) ((b2 << 8) | (b1 & 0xff)); - } - - public int readUnsignedShort() throws IOException { - //-- TODO implement - throw new UnsupportedOperationException("Not implemented yet"); - } - - public char readChar() throws IOException { - //-- TODO implement - throw new UnsupportedOperationException("Not implemented yet"); - } - - public int readInt() throws IOException { - //-- TODO implement - throw new UnsupportedOperationException("Not implemented yet"); - } - - public long readUnsignedInt() throws IOException { - //-- TODO implement - throw new UnsupportedOperationException("Not implemented yet"); - } - - public long readLong() throws IOException { - //-- TODO implement - throw new UnsupportedOperationException("Not implemented yet"); - } - - public float readFloat() throws IOException { - //-- TODO implement - throw new UnsupportedOperationException("Not implemented yet"); - } - - public double readDouble() throws IOException { - //-- TODO implement - throw new UnsupportedOperationException("Not implemented yet"); - } - - public String readLine() throws IOException { - //-- TODO implement - throw new UnsupportedOperationException("Not implemented yet"); - } - - public String readUTF() throws IOException { - //-- TODO implement - throw new UnsupportedOperationException("Not implemented yet"); - } - - public void readFully(byte[] b, int off, int len) throws IOException { - //-- TODO implement - throw new UnsupportedOperationException("Not implemented yet"); - } - - public void readFully(byte[] b) throws IOException { - readFully(b, 0, b.length); - } - - public void readFully(short[] s, int off, int len) throws IOException { - //-- TODO implement - throw new UnsupportedOperationException("Not implemented yet"); - } - - public void readFully(char[] c, int off, int len) throws IOException { - //-- TODO implement - throw new UnsupportedOperationException("Not implemented yet"); - } - - public void readFully(int[] i, int off, int len) throws IOException { - //-- TODO implement - throw new UnsupportedOperationException("Not implemented yet"); - } - - public void readFully(long[] l, int off, int len) throws IOException { - //-- TODO implement - throw new UnsupportedOperationException("Not implemented yet"); - } - - public void readFully(float[] f, int off, int len) throws IOException { - //-- TODO implement - throw new UnsupportedOperationException("Not implemented yet"); - } - - public void readFully(double[] d, int off, int len) throws IOException { - //-- TODO implement - throw new UnsupportedOperationException("Not implemented yet"); - } - - public long getStreamPosition() throws IOException { - checkClosed(); - return streamPos; - } - - public int getBitOffset() throws IOException { - checkClosed(); - return bitOffset; - } - - public void setBitOffset(int bitOffset) throws IOException { - checkClosed(); - this.bitOffset = bitOffset; - } - - public int readBit() throws IOException { - //-- TODO implement - throw new UnsupportedOperationException("Not implemented yet"); - } - - public long readBits(int numBits) throws IOException { - //-- TODO implement - throw new UnsupportedOperationException("Not implemented yet"); - } - - public long length() { - return -1L; - } - - public int skipBytes(int n) throws IOException { - //-- TODO implement - throw new UnsupportedOperationException("Not implemented yet"); - } - - public long skipBytes(long n) throws IOException { - //-- TODO implement - throw new UnsupportedOperationException("Not implemented yet"); - } - - public void seek(long pos) throws IOException { - checkClosed(); - if (pos < getFlushedPosition()) { - throw new IllegalArgumentException("trying to seek before flushed pos"); - } - bitOffset = 0; - streamPos = pos; - } - - public void mark() { - try { - posStack.push(getStreamPosition()); - } catch (IOException e) { - e.printStackTrace(); - throw new RuntimeException("Stream marking error"); - } - } - - public void reset() throws IOException { - //-- TODO bit pos - if (!posStack.isEmpty()) { - long p = posStack.pop(); - if (p < flushedPos) { - throw new IOException("marked position lies in the flushed portion of the stream"); - } - seek(p); - } - } - - public void flushBefore(long pos) throws IOException { - if (pos > getStreamPosition()) { - throw new IndexOutOfBoundsException("Trying to flush outside of current position"); - } - if (pos < flushedPos) { - throw new IndexOutOfBoundsException("Trying to flush within already flushed portion"); - } - flushedPos = pos; - //-- TODO implement - } - - public void flush() throws IOException { - flushBefore(getStreamPosition()); - } - - public long getFlushedPosition() { - return flushedPos; - } - - public boolean isCached() { - return false; //def - } - - public boolean isCachedMemory() { - return false; //def - } - - public boolean isCachedFile() { - return false; //def - } - - public void close() throws IOException { - checkClosed(); - closed = true; - - } - - @Override - protected void finalize() throws Throwable { - if (!closed) { - try { - close(); - } finally { - super.finalize(); - } - } - } - - private static class PositionStack { - private static final int SIZE = 10; - - private long[] values = new long[SIZE]; - private int pos = 0; - - - void push(long v) { - if (pos >= values.length) { - ensure(pos+1); - } - values[pos++] = v; - } - - long pop() { - return values[--pos]; - } - - boolean isEmpty() { - return pos == 0; - } - - private void ensure(int size) { - long[] arr = new long[Math.max(2 * values.length, size)]; - System.arraycopy(values, 0, arr, 0, values.length); - values = arr; - } - } + protected long streamPos = 0; + protected long flushedPos = 0; + protected int bitOffset = 0; + + private boolean closed = false; + + private final PositionStack posStack = new PositionStack(); + private final byte[] buff = new byte[8]; + + public ImageInputStreamImpl() { + } + + protected final void checkClosed() throws IOException { + if (closed) { + throw new IOException("stream is closed"); + } + } + + public void setByteOrder(ByteOrder byteOrder) { + this.byteOrder = byteOrder; + } + + public ByteOrder getByteOrder() { + return byteOrder; + } + + public abstract int read() throws IOException; + + public int read(byte[] b) throws IOException { + return read(b, 0, b.length); + } + + public abstract int read(byte[] b, int off, int len) throws IOException; + + public void readBytes(IIOByteBuffer buf, int len) throws IOException { + if (buf == null) { + throw new NullPointerException("buffer is NULL"); + } + + byte[] b = new byte[len]; + len = read(b, 0, b.length); + + buf.setData(b); + buf.setOffset(0); + buf.setLength(len); + } + + public boolean readBoolean() throws IOException { + int b = read(); + if (b < 0) { + throw new EOFException("EOF reached"); + } + return b != 0; + } + + public byte readByte() throws IOException { + int b = read(); + if (b < 0) { + throw new EOFException("EOF reached"); + } + return (byte) b; + } + + public int readUnsignedByte() throws IOException { + int b = read(); + if (b < 0) { + throw new EOFException("EOF reached"); + } + return b; + } + + public short readShort() throws IOException { + if (read(buff, 0, 2) < 0) { + throw new EOFException(); + } + + return byteOrder == ByteOrder.BIG_ENDIAN ? + (short) ((buff[0] << 8) | (buff[1] & 0xff)) : + (short) ((buff[1] << 8) | (buff[0] & 0xff)); + } + + public int readUnsignedShort() throws IOException { + return ((int) readShort()) & 0xffff; + } + + public char readChar() throws IOException { + return (char) readShort(); + } + + public int readInt() throws IOException { + if (read(buff, 0, 4) < 0) { + throw new EOFException(); + } + + return byteOrder == ByteOrder.BIG_ENDIAN ? ((buff[0] & 0xff) << 24) + | ((buff[1] & 0xff) << 16) | ((buff[2] & 0xff) << 8) + | (buff[3] & 0xff) : ((buff[3] & 0xff) << 24) + | ((buff[2] & 0xff) << 16) | ((buff[1] & 0xff) << 8) + | (buff[0] & 0xff); + } + + public long readUnsignedInt() throws IOException { + return ((long) readInt()) & 0xffffffffL; + } + + public long readLong() throws IOException { + if (read(buff, 0, 8) < 0) { + throw new EOFException(); + } + + if (byteOrder == ByteOrder.BIG_ENDIAN) { + int i1 = ((buff[0] & 0xff) << 24) | ((buff[1] & 0xff) << 16) + | ((buff[2] & 0xff) << 8) | (buff[3] & 0xff); + int i2 = ((buff[4] & 0xff) << 24) | ((buff[5] & 0xff) << 16) + | ((buff[6] & 0xff) << 8) | (buff[7] & 0xff); + + return ((i1 & 0xffffffffL) << 32) | (i2 & 0xffffffffL); + } else { + int i1 = ((buff[3] & 0xff) << 24) | ((buff[2] & 0xff) << 16) + | ((buff[1] & 0xff) << 8) | (buff[0] & 0xff); + int i2 = ((buff[7] & 0xff) << 24) | ((buff[6] & 0xff) << 16) + | ((buff[5] & 0xff) << 8) | (buff[4] & 0xff); + + return ((i2 & 0xffffffffL) << 32) | (i1 & 0xffffffffL); + } + } + + public float readFloat() throws IOException { + return Float.intBitsToFloat(readInt()); + } + + public double readDouble() throws IOException { + return Double.longBitsToDouble(readLong()); + } + + public String readLine() throws IOException { + final StringBuffer line = new StringBuffer(80); + boolean isEmpty = true; + int c = -1; + + while ((c = read()) != -1) { + isEmpty = false; + if (c == '\n') { + break; + } else if (c == '\r') { + c = read(); + if ((c != '\n') && (c != -1)) { + seek(getStreamPosition() - 1); + } + break; + } + line.append((char) c); + } + + return isEmpty ? null : line.toString(); + } + + public String readUTF() throws IOException { + final int size = readUnsignedShort(); + final byte[] buf = new byte[size]; + final char[] out = new char[size]; + + readFully(buf, 0, size); + //return new DataInputStream(new ByteArrayInputStream(buff)).readUTF(); + return Util.convertUTF8WithBuf(buf, out, 0, size); + } + + public void readFully(byte[] b, int off, int len) throws IOException { + if ((off < 0) || (len < 0) || (off + len > b.length)) { + throw new IndexOutOfBoundsException(); + } + + while (len > 0) { + int i = read(b, off, len); + + if (i == -1) { + throw new EOFException(); + } + + off += i; + len -= i; + } + } + + public void readFully(byte[] b) throws IOException { + readFully(b, 0, b.length); + } + + public void readFully(short[] s, int off, int len) throws IOException { + if ((off < 0) || (len < 0) || (off + len > s.length)) { + throw new IndexOutOfBoundsException(); + } + + for (int i = 0; i < len; i++) { + s[off + i] = readShort(); + } + } + + public void readFully(char[] c, int off, int len) throws IOException { + if ((off < 0) || (len < 0) || (off + len > c.length)) { + throw new IndexOutOfBoundsException(); + } + + for (int i = 0; i < len; i++) { + c[off + i] = readChar(); + } + } + + public void readFully(int[] i, int off, int len) throws IOException { + if ((off < 0) || (len < 0) || (off + len > i.length)) { + throw new IndexOutOfBoundsException(); + } + + for (int k = 0; k < len; k++) { + i[off + k] = readInt(); + } + } + + public void readFully(long[] l, int off, int len) throws IOException { + if ((off < 0) || (len < 0) || (off + len > l.length)) { + throw new IndexOutOfBoundsException(); + } + + for (int i = 0; i < len; i++) { + l[off + i] = readLong(); + } + } + + public void readFully(float[] f, int off, int len) throws IOException { + if ((off < 0) || (len < 0) || (off + len > f.length)) { + throw new IndexOutOfBoundsException(); + } + + for (int i = 0; i < len; i++) { + f[off + i] = readFloat(); + } + } + + public void readFully(double[] d, int off, int len) throws IOException { + if ((off < 0) || (len < 0) || (off + len > d.length)) { + throw new IndexOutOfBoundsException(); + } + + for (int i = 0; i < len; i++) { + d[off + i] = readFloat(); + } + } + + public long getStreamPosition() throws IOException { + checkClosed(); + return streamPos; + } + + public int getBitOffset() throws IOException { + checkClosed(); + return bitOffset; + } + + public void setBitOffset(int bitOffset) throws IOException { + checkClosed(); + if ((bitOffset < 0) || (bitOffset > 7)) { + throw new IllegalArgumentException(); + } + this.bitOffset = bitOffset; + } + + int currentByte; + + public int readBit() throws IOException { + checkClosed(); + + int offset = bitOffset; + int currentByte = read(); + + if (currentByte == -1) { + throw new EOFException(); + } + + offset = (offset + 1) & 7; + + if (offset != 0) { + currentByte >>= 8 - offset; + seek(getStreamPosition() - 1); + } + + bitOffset = offset; + return currentByte & 1; + } + + public long readBits(int numBits) throws IOException { + checkClosed(); + + if ((numBits < 0) || (numBits > 64)) { + throw new IllegalArgumentException(); + } + + long res = 0; + + for (int i = 0; i < numBits; i++) { + res <<= 1; + res |= readBit(); + } + + return res; + } + + public long length() { + return -1L; + } + + public int skipBytes(int n) throws IOException { + return (int) skipBytes((long) n); + } + + public long skipBytes(long n) throws IOException { + seek(getStreamPosition() + n); + return n; + } + + public void seek(long pos) throws IOException { + checkClosed(); + if (pos < getFlushedPosition()) { + throw new IllegalArgumentException( + "trying to seek before flushed pos"); + } + bitOffset = 0; + streamPos = pos; + } + + public void mark() { + try { + posStack.push(getStreamPosition()); + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException("Stream marking error"); + } + } + + public void reset() throws IOException { + // -- TODO bit pos + if (!posStack.isEmpty()) { + long p = posStack.pop(); + if (p < flushedPos) { + throw new IOException( + "marked position lies in the flushed portion of the stream"); + } + seek(p); + } + } + + public void flushBefore(long pos) throws IOException { + if (pos > getStreamPosition()) { + throw new IndexOutOfBoundsException( + "Trying to flush outside of current position"); + } + if (pos < flushedPos) { + throw new IndexOutOfBoundsException( + "Trying to flush within already flushed portion"); + } + flushedPos = pos; + // -- TODO implement + } + + public void flush() throws IOException { + flushBefore(getStreamPosition()); + } + + public long getFlushedPosition() { + return flushedPos; + } + + public boolean isCached() { + return false; // def + } + + public boolean isCachedMemory() { + return false; // def + } + + public boolean isCachedFile() { + return false; // def + } + + public void close() throws IOException { + checkClosed(); + closed = true; + + } + + @Override + protected void finalize() throws Throwable { + if (!closed) { + try { + close(); + } finally { + super.finalize(); + } + } + } + + private static class PositionStack { + private static final int SIZE = 10; + + private long[] values = new long[SIZE]; + private int pos = 0; + + void push(long v) { + if (pos >= values.length) { + ensure(pos + 1); + } + values[pos++] = v; + } + + long pop() { + return values[--pos]; + } + + boolean isEmpty() { + return pos == 0; + } + + private void ensure(int size) { + long[] arr = new long[Math.max(2 * values.length, size)]; + System.arraycopy(values, 0, arr, 0, values.length); + values = arr; + } + } } Added: harmony/enhanced/classlib/trunk/modules/imageio/src/test/java/javax/imageio/stream/ImageInputStreamImplTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/test/java/javax/imageio/stream/ImageInputStreamImplTest.java?rev=573171&view=auto ============================================================================== --- harmony/enhanced/classlib/trunk/modules/imageio/src/test/java/javax/imageio/stream/ImageInputStreamImplTest.java (added) +++ harmony/enhanced/classlib/trunk/modules/imageio/src/test/java/javax/imageio/stream/ImageInputStreamImplTest.java Thu Sep 6 00:47:57 2007 @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package javax.imageio.stream; + +import java.io.IOException; +import java.nio.ByteOrder; + +import junit.framework.TestCase; + +public class ImageInputStreamImplTest extends TestCase { + + public void testReadLine() throws IOException { + final ImageInputStream in = new BasicImageInputStreamImpl( + "line1\nline2\rline3\r\nline4".getBytes()); + + assertEquals("line1", in.readLine()); + assertEquals("line2", in.readLine()); + assertEquals("line3", in.readLine()); + assertEquals("line4", in.readLine()); + } + + public void testReadBit() throws IOException { + final ImageInputStream in = new BasicImageInputStreamImpl( + new byte[] { (byte) 150 }); + + assertEquals(1, in.readBit()); + assertEquals(0, in.readBit()); + assertEquals(0, in.readBit()); + assertEquals(1, in.readBit()); + assertEquals(0, in.readBit()); + assertEquals(1, in.readBit()); + assertEquals(1, in.readBit()); + assertEquals(0, in.readBit()); + } + + public void testReadBits() throws IOException { + final ImageInputStream in = new BasicImageInputStreamImpl( + Long.MAX_VALUE); + + assertEquals(3, in.readBits(3)); + assertEquals(1023, in.readBits(10)); + in.reset(); + assertEquals(Long.MAX_VALUE, in.readBits(64)); + } + + public void testReadLong() throws IOException { + ImageInputStream in = new BasicImageInputStreamImpl(Long.MAX_VALUE); + + assertEquals(Long.MAX_VALUE, in.readLong()); + + in = new BasicImageInputStreamImpl(Long.MAX_VALUE, + ByteOrder.LITTLE_ENDIAN); + assertEquals(Long.MAX_VALUE, in.readLong()); + } + + public void testReadInt() throws IOException { + ImageInputStream in = new BasicImageInputStreamImpl(Integer.MAX_VALUE); + + in.readInt(); + assertEquals(Integer.MAX_VALUE, in.readInt()); + + in = new BasicImageInputStreamImpl(Integer.MAX_VALUE, + ByteOrder.LITTLE_ENDIAN); + assertEquals(Integer.MAX_VALUE, in.readInt()); + } + + public void testReadShort() throws IOException { + ImageInputStream in = new BasicImageInputStreamImpl(Short.MAX_VALUE); + + in.readInt(); + in.readShort(); + assertEquals(Short.MAX_VALUE, in.readShort()); + + in = new BasicImageInputStreamImpl(Short.MAX_VALUE, + ByteOrder.LITTLE_ENDIAN); + assertEquals(Short.MAX_VALUE, in.readShort()); + } + + static class BasicImageInputStreamImpl extends ImageInputStreamImpl { + final byte[] buff; + + public BasicImageInputStreamImpl(final long value) { + this(value, ByteOrder.BIG_ENDIAN); + } + + public BasicImageInputStreamImpl(final long value, final ByteOrder order) { + if (order == ByteOrder.BIG_ENDIAN) { + buff = new byte[] { (byte) (value >> 56), (byte) (value >> 48), + (byte) (value >> 40), (byte) (value >> 32), + (byte) (value >> 24), (byte) (value >> 16), + (byte) (value >> 8), (byte) (value) }; + } else { + buff = new byte[] { (byte) value, (byte) (value >> 8), + (byte) (value >> 16), (byte) (value >> 24), + (byte) (value >> 32), (byte) (value >> 40), + (byte) (value >> 48), (byte) (value >> 56) }; + } + setByteOrder(order); + } + + public BasicImageInputStreamImpl(final byte[] buff) { + this.buff = buff; + } + + @Override + public int read() throws IOException { + bitOffset = 0; + return (streamPos >= buff.length) ? -1 + : (buff[(int) streamPos++] & 0xff); + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + int i = 0; + int curByte = -1; + + for (; (i < len) && ((curByte = read()) != -1); i++) { + b[off] = (byte) curByte; + off++; + } + + return (i == 0) && (curByte == -1) ? -1 : i; + } + + @Override + public void reset() throws IOException { + super.reset(); + streamPos = 0; + bitOffset = 0; + } + } +} Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/test/java/javax/imageio/stream/ImageInputStreamImplTest.java ------------------------------------------------------------------------------ svn:eol-style = native