Author: markt Date: Wed Feb 24 11:59:37 2016 New Revision: 1732093 URL: http://svn.apache.org/viewvc?rev=1732093&view=rev Log: De-duplication Reported by Simian.
Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java?rev=1732093&r1=1732092&r2=1732093&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java Wed Feb 24 11:59:37 2016 @@ -360,42 +360,21 @@ public final class ByteChunk implements // -------------------- Removing data from the buffer -------------------- public int substract() throws IOException { - if ((end - start) == 0) { - if (in == null) { - return -1; - } - int n = in.realReadBytes(); - if (n < 0) { - return -1; - } - } - return (buff[start++] & 0xFF); + return substractB() & 0xFF; } public byte substractB() throws IOException { - if ((end - start) == 0) { - if (in == null) { - return -1; - } - int n = in.realReadBytes(); - if (n < 0) { - return -1; - } + if (checkEof()) { + return -1; } return buff[start++]; } public int substract(byte dest[], int off, int len ) throws IOException { - if ((end - start) == 0) { - if (in == null) { - return -1; - } - int n = in.realReadBytes(); - if (n < 0) { - return -1; - } + if (checkEof()) { + return -1; } int n = len; if (len > getLength()) { @@ -407,6 +386,20 @@ public final class ByteChunk implements } + private boolean checkEof() throws IOException { + if ((end - start) == 0) { + if (in == null) { + return true; + } + int n = in.realReadBytes(); + if (n < 0) { + return true; + } + } + return false; + } + + /** * Send the buffer to the sink. Called by append() when the limit is * reached. You can also call it explicitly to force the data to be written. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org