Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

InputStream truncates after 8192 bytes

807580Aug 18 2010 — edited Aug 20 2010
Hi

I suspect that there is an easy solution to this but I have not figured it out as of yet. The following procedure takes the contents of MESSAGE (a static byte[]) and reads it into the InputStream, where it will then be appended to some message headers, then signed and encrypted. This works fine for any MESSAGE less than or equal to 8192 bytes.

Any thoughts on how I can read beyond 8192 bytes ... the message that I want read is about 30,000 bytes and rarely would I need to go beyond this. So as you can see we are not dealing with large files here.

public int read(byte[] b, int offset, int length) throws IOException
        {
       
if (b == null)
            {
                throw new NullPointerException();
            }
            else if (
                (offset < 0)
                    || (offset > b.length)
                    || (length < 0)
                    || ((offset + length) > b.length)
                    || ((offset + length) < 0))
            {
                throw new IndexOutOfBoundsException();
            }
            else if (m_readCount >= MAX_READ_COUNT)
            {
                return -1;
            }
            else if (length == 0)
            {
                return 0;
            }

            if (m_readCount >= MAX_READ_COUNT)
            {
                return -1;
            }
            else
            {
                
	int bytesToCopy = Math.min(MESSAGE.length, length);
                System.arraycopy(MESSAGE, 0, b, offset, bytesToCopy);
                ++m_readCount;
                return bytesToCopy;
            }
        }
    }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 17 2010
Added on Aug 18 2010
13 comments
2,439 views