未验证 提交 368d1de3 编写于 作者: O Oleg Nenashev 提交者: GitHub

Merge pull request #4256 from jsoref/java-cleanup-ChunkedInputStream.advanceChunk

IntelliJ/Java: Duplicate code -> ChunkedInputStream.advanceChunk
......@@ -111,18 +111,7 @@ public class ChunkedInputStream extends InputStream {
*/
public int read() throws IOException {
if (closed) {
throw new IOException("Attempted read from closed stream.");
}
if (eof) {
return -1;
}
if (pos >= chunkSize) {
nextChunk();
if (eof) {
return -1;
}
}
if (advanceChunk()) return -1;
pos++;
return in.read();
}
......@@ -141,23 +130,28 @@ public class ChunkedInputStream extends InputStream {
@Override
public int read (byte[] b, int off, int len) throws IOException {
if (advanceChunk()) return -1;
len = Math.min(len, chunkSize - pos);
int count = in.read(b, off, len);
pos += count;
return count;
}
private boolean advanceChunk() throws IOException {
if (closed) {
throw new IOException("Attempted read from closed stream.");
}
if (eof) {
return -1;
return true;
}
if (pos >= chunkSize) {
nextChunk();
if (eof) {
return -1;
return true;
}
}
len = Math.min(len, chunkSize - pos);
int count = in.read(b, off, len);
pos += count;
return count;
return false;
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册