db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Junjie Peng (JIRA)" <j...@apache.org>
Subject [jira] Updated: (DERBY-3770) Create a utility class for skipping data in an InputStream
Date Wed, 27 Aug 2008 08:45:44 GMT

     [ https://issues.apache.org/jira/browse/DERBY-3770?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

Junjie Peng updated DERBY-3770:

    Attachment: derby-3770-4.stat

Hi, Mamta and Daniel. Thanks for your advices.  I have done some improvement.

1.) Delete StreamUtil, move the methods to InputStreamUtil, and move the test class to suitable

2.) Rename SKIP_BUFFER_SIZE to SKIP_FRAGMENT_SIZE to keep clear.

3.) Use "        if (skippedNow == 0)"  in skipPersistent().

4.) About skipByte(InputStream,long):
		Skip a number of bytes in the stream. Note that this version takes and returns
		a long instead of the int used by skipBytes.

		@exception IOException if an I/O error occurs.
		@exception EOFException if the end of the stream is reached

		@see DataInput#skipBytes
	public static long skipBytes(InputStream in, long n) throws IOException {

		while (n > 0) {
			//System.out.println(" skip n = " + n);
			long delta = in.skip(n);
			//System.out.println(" skipped = " + delta);
			if (delta < 0)
				throw new EOFException();
			n -= delta;

		return n;
This method doesn't work well. First, for "long delta = in.skip(n); ", delat won't to be negative,
so we can not judge EOFException with "if (delta < 0)". The method skipPersistent() is
fittest to judge EOF has arrived.
So, I deleted skipBytes(), and replace it with skipFully() where skipBytes() is used.

5.) Daniel said "skipPersistent() states that if a fewer number of bytes is skipped then it
is guaranteed that eof has been reached, but skipFully() does not take advantage of this,
instead it will always perform an extra call to skipPersistent(). " Howeve, skipPersistent()
is useful to skipFully(), it can guarante that requested num of bytes will be skipped most
probably. If we use the common skip() method, we can not judge enough bytes has been skipped
fully even having not EOFEception.

Please check the new patch, thanks!

> Create a utility class for skipping data in an InputStream
> ----------------------------------------------------------
>                 Key: DERBY-3770
>                 URL: https://issues.apache.org/jira/browse/DERBY-3770
>             Project: Derby
>          Issue Type: Improvement
>          Components: Miscellaneous
>    Affects Versions:
>            Reporter: Kristian Waagan
>            Assignee: Junjie Peng
>            Priority: Minor
>         Attachments: derby-3770-1.patch, derby-3770-1.stat, derby-3770-2.patch, derby-3770-2.stat,
derby-3770-3.patch, derby-3770-3.stat, derby-3770-4.patch, derby-3770-4.patch, derby-3770-4.stat,
> The contract of InputStream.skip is somewhat difficult, some would even say broken.
> See http://java.sun.com/javase/6/docs/api/java/io/InputStream.html#skip(long))
> A utility class should be created to ensure that we use the same skip procedure throughout
the Derby code base.
> Suggested functionality:
>  - long skipFully(InputStream) : skips until EOF, returns number of bytes skipped
>  - void skipFully(InputStream,long) : skips requested number of bytes, throws EOFException
if there is too few bytes in the stream
> I know of two different approaches, both skipping in a loop:
>  a) Verify EOF with a read call when skip returns zero.
>  b) Throw EOFException if skip returns zero before requested number of bytes have been
> There's related code in iapi.util.UTF8Util. Maybe this class, say StreamUtil, could be
put in the same package?

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message