When can DataInputStream.skipBytes(n) not skip n bytes?

1) There might not be that much data available to read (the other end of the pipe might not have sent that much data yet), and the implementing class might be non-blocking (i.e. It will just return what it can, rather than waiting for enough data to fulfil the request).

1) There might not be that much data available to read (the other end of the pipe might not have sent that much data yet), and the implementing class might be non-blocking (i.e. It will just return what it can, rather than waiting for enough data to fulfil the request). I don't know if any implementations actually behave in this way, however, but the interface is designed to permit it.

Another option is simply that the file gets closed part-way through the read. 2) Either readFully() (which will always wait for enough input or else fail) or call skipBytes() in a loop. I think the former is probably better, unless the array is truly vast.

Josh Bloch has publicised this recently. It is consistent in that InputStream. Read is not guaranteed to read as many bytes as it could.

However, it is utterly pointless as an API method. InputStream should probably also have readFully.

It turns out that readFully() adds more performance overhead than I was willing to put up with. In the end I compromised: I call skipBytes() once, and if that returns fewer than the right number of bytes, I call readFully() for the remaining bytes.

I came across this problem today. It was reading off a network connection on a virtual machine so I imagine there could be a number of reasons for this happening. I solved it by simply forcing the input stream to skip bytes until it had skipped the number of bytes I wanted it to: int byteOffsetX = someNumber; //n bytes to skip int nSkipped = 0; nSkipped = in.

SkipBytes(byteOffsetX); while (nSkipped.

Mostly if implementation decides it is better to return after skipping at least some bytes (it MUST skip at least one; similar contract to read(byte) method) than to block. This is most commonly the case for streams read over the network.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions