git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH JGIT] Method ignores results of InputStream.skip()

From
Shawn O. Pearce <spearce@spearce.org>
Date
Apr 27, 2009, 23:21 UTC
Message-ID
<20090427232112.GN23604@spearce.org>
In-Reply-To
<366BBB1215D0AB4B8A153AF047A2878002FCE7EA@dewdfe18.wdf.sap.corp>
"Sohn, Matthias" <matthias.sohn@sap.com> wrote:
> This method ignores the return value of java.io.InputStream.skip()
Doh.  In theory the skip should always succeed because the buffer
held the entire block we want to skip over due to the mark/reset
usage around this region.  But I agree, a skipFully() pattern is
better here.
 
Show 17 quoted lines
> @@ -139,12 +140,23 @@ private String readLine(final byte[] hdrbuf)
> throws IOException {
>  		while (lf < cnt && hdrbuf[lf] != '\n')
>  			lf++;
>  		bin.reset();
> -		bin.skip(lf);
> +		skipFully(bin, lf);
>  		if (lf < cnt && hdrbuf[lf] == '\n')
> -			bin.skip(1);
> +			skipFully(bin, 1);
>  		return RawParseUtils.decode(Constants.CHARSET, hdrbuf,
> 0, lf);
>  	}
>  
> +	// skip given number of bytes on InputStream respecting return
> value of InputStream.skip()
> +	static private void skipFully(InputStream in, long nBytes)
We already have this method; see NB.skipFully().

NB also has readFully() and a few other useful functions for dealing with common IO related patterns.

Please respin by calling NB.skipFully above rather than creating a new package level method, and fix the line wrapping issue so we can more easily apply it. :-)

-- 
Shawn.
Previous: Sohn, MatthiasNext: Sohn, Matthias
Message 5 of 9 in “Computation of average could overflow”
  1. Computation of average could overflowSohn, Matthias, Apr 27, 2009
  2. Method invokes inefficient new String(String) constructorSohn, Matthias, Apr 27, 2009
  3. Method invokes inefficient Number constructor; use static valueOf insteadSohn, Matthias, Apr 27, 2009
  4. Method ignores results of InputStream.skip()Sohn, Matthias, Apr 27, 2009
  5. Shawn O. PearceApr 27, 2009
  6. Method ignores results of InputStream.skip()Sohn, Matthias, Apr 28, 2009
  7. Shawn O. PearceApr 27, 2009
  8. Shawn O. PearceApr 27, 2009
  9. Shawn O. PearceApr 27, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.