This is an automated email from the ASF dual-hosted git repository.
dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/master by this push:
new 6fddbae AVRO-2352: Cleanup BinaryDecoder isEnd Method
6fddbae is described below
commit 6fddbae08fcf0aba1d51289d1b90681c3bfa9477
Author: Beluga Behr <[email protected]>
AuthorDate: Tue Mar 12 10:43:13 2019 -0400
AVRO-2352: Cleanup BinaryDecoder isEnd Method
---
.../java/org/apache/avro/io/BinaryDecoder.java | 37 +++++++++++-----------
1 file changed, 18 insertions(+), 19 deletions(-)
diff --git a/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java
b/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java
index d25eb51..61bd958 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java
@@ -456,32 +456,31 @@ public class BinaryDecoder extends Decoder {
}
/**
- * Returns true if the current BinaryDecoder is at the end of its source
data and
- * cannot read any further without throwing an EOFException or other
+ * Returns true if the current BinaryDecoder is at the end of its source data
+ * and cannot read any further without throwing an EOFException or other
* IOException.
* <p/>
- * Not all implementations of BinaryDecoder support isEnd(). Implementations
that do
- * not support isEnd() will throw a
+ * Not all implementations of BinaryDecoder support isEnd(). Implementations
+ * that do not support isEnd() will throw a
* {@link java.lang.UnsupportedOperationException}.
+ *
+ * @throws IOException If the first byte cannot be read for any reason other
+ * than the end of the file, if the input stream has been closed,
or
+ * if some other I/O error occurs.
*/
public boolean isEnd() throws IOException {
- if (limit - pos > 0) {
- // buffer not empty, not at end.
- return false;
- } else {
- if (source.isEof()) {
- return true;
- }
- // read from source.
- int read = source.tryReadRaw(buf, 0, buf.length);
- pos = 0;
- limit = read;
- if (0 == read) {
- // nothing left
- return true;
- }
+ if (pos < limit) {
return false;
}
+ if (source.isEof()) {
+ return true;
+ }
+
+ // read from source.
+ final int read = source.tryReadRaw(buf, 0, buf.length);
+ pos = 0;
+ limit = read;
+ return (0 == read);
}
/**