HADOOP-13017. Implementations of InputStream.read(buffer, offset, bytes) to exit 0 if bytes==0. Contributed by Steve Loughran.
This commit is contained in:
parent
e29cba61a0
commit
0bdd263d82
|
@ -968,6 +968,9 @@ public class HarFileSystem extends FileSystem {
|
||||||
@Override
|
@Override
|
||||||
public synchronized int read(byte[] b, int offset, int len)
|
public synchronized int read(byte[] b, int offset, int len)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
if (len == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int newlen = len;
|
int newlen = len;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
if (position + len > end) {
|
if (position + len > end) {
|
||||||
|
|
|
@ -246,6 +246,9 @@ public class SaslInputStream extends InputStream implements ReadableByteChannel
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int read(byte[] b, int off, int len) throws IOException {
|
public int read(byte[] b, int off, int len) throws IOException {
|
||||||
|
if (len == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (!useWrap) {
|
if (!useWrap) {
|
||||||
return inStream.read(b, off, len);
|
return inStream.read(b, off, len);
|
||||||
}
|
}
|
||||||
|
@ -378,4 +381,4 @@ public class SaslInputStream extends InputStream implements ReadableByteChannel
|
||||||
}
|
}
|
||||||
return bytesRead;
|
return bytesRead;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -569,6 +569,9 @@ public class SaslRpcClient {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized int read(byte[] buf, int off, int len) throws IOException {
|
public synchronized int read(byte[] buf, int off, int len) throws IOException {
|
||||||
|
if (len == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
// fill the buffer with the next RPC message
|
// fill the buffer with the next RPC message
|
||||||
if (unwrappedRpcBuffer.remaining() == 0) {
|
if (unwrappedRpcBuffer.remaining() == 0) {
|
||||||
readNextRpcPacket();
|
readNextRpcPacket();
|
||||||
|
|
|
@ -74,6 +74,9 @@ public final class LimitInputStream extends FilterInputStream {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int read(byte[] b, int off, int len) throws IOException {
|
public int read(byte[] b, int off, int len) throws IOException {
|
||||||
|
if (len == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (left == 0) {
|
if (left == 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1832,6 +1832,9 @@ public class WebHdfsFileSystem extends FileSystem
|
||||||
if (runnerState == RunnerState.CLOSED) {
|
if (runnerState == RunnerState.CLOSED) {
|
||||||
throw new IOException("Stream closed");
|
throw new IOException("Stream closed");
|
||||||
}
|
}
|
||||||
|
if (len == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Before the first read, pos and fileLength will be 0 and readBuffer
|
// Before the first read, pos and fileLength will be 0 and readBuffer
|
||||||
// will all be null. They will be initialized once the first connection
|
// will all be null. They will be initialized once the first connection
|
||||||
|
|
|
@ -84,6 +84,9 @@ public class ThrottledInputStream extends InputStream {
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public int read(byte[] b, int off, int len) throws IOException {
|
public int read(byte[] b, int off, int len) throws IOException {
|
||||||
|
if (len == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
throttle();
|
throttle();
|
||||||
int readLen = rawStream.read(b, off, len);
|
int readLen = rawStream.read(b, off, len);
|
||||||
if (readLen != -1) {
|
if (readLen != -1) {
|
||||||
|
|
|
@ -187,6 +187,9 @@ public class HttpInputStreamWithRelease extends InputStream {
|
||||||
@Override
|
@Override
|
||||||
public int read(byte[] b, int off, int len) throws IOException {
|
public int read(byte[] b, int off, int len) throws IOException {
|
||||||
SwiftUtils.validateReadArgs(b, off, len);
|
SwiftUtils.validateReadArgs(b, off, len);
|
||||||
|
if (len == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
//if the stream is already closed, then report an exception.
|
//if the stream is already closed, then report an exception.
|
||||||
assumeNotReleased();
|
assumeNotReleased();
|
||||||
//now read in a buffer, reacting differently to different operations
|
//now read in a buffer, reacting differently to different operations
|
||||||
|
|
|
@ -161,6 +161,9 @@ class SwiftNativeInputStream extends FSInputStream {
|
||||||
public synchronized int read(byte[] b, int off, int len) throws IOException {
|
public synchronized int read(byte[] b, int off, int len) throws IOException {
|
||||||
SwiftUtils.debug(LOG, "read(buffer, %d, %d)", off, len);
|
SwiftUtils.debug(LOG, "read(buffer, %d, %d)", off, len);
|
||||||
SwiftUtils.validateReadArgs(b, off, len);
|
SwiftUtils.validateReadArgs(b, off, len);
|
||||||
|
if (len == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int result = -1;
|
int result = -1;
|
||||||
try {
|
try {
|
||||||
verifyOpen();
|
verifyOpen();
|
||||||
|
|
Loading…
Reference in New Issue