@Test public void testCalcNrRead() { Integer[] testData = new Integer[] { 0, 0, 0, 1, 1, 2, 10, Integer.MAX_VALUE - 10, Integer.MAX_VALUE, 1, Integer.MAX_VALUE - 1, Integer.MAX_VALUE, 10, Integer.MAX_VALUE - 9, -1 }; for (int i = 0; i < testData.length; i += 3) { int actualResult = IOUtil.calcNewNrReadSize(testData[i], testData[i + 1]); int expectedResult = testData[i + 2]; assertEquals((i / 3) + " : " + testData[i] + ", " + testData[i + 1], expectedResult, actualResult); } }
protected static int calcNewNrReadSize(int nrRead, int totalNrNread) { if (totalNrNread < 0) { return totalNrNread; } if (totalNrNread > (Integer.MAX_VALUE - nrRead)) { return -1; } else { return (totalNrNread + nrRead); } }
IOUtil { protected static int calcNewNrReadSize(int nrRead, int totalNrNread) { if (totalNrNread < 0) { return totalNrNread; } if (totalNrNread > (Integer.MAX_VALUE - nrRead)) { return -1; } else { return (totalNrNread + nrRead); } } }
IOUtil { protected static int calcNewNrReadSize(int nrRead, int totalNrNread) { if (totalNrNread < 0) { return totalNrNread; } if (totalNrNread > (Integer.MAX_VALUE - nrRead)) { return -1; } else { return (totalNrNread + nrRead); } }  }
IOUtil { protected static int calcNewNrReadSize(int nrRead, int totalNrNread) { if (totalNrNread < 0) { return totalNrNread; } if (totalNrNread > (Integer.MAX_VALUE - nrRead)) { return -1; } else { return (totalNrNread + nrRead); } }  static byte[] toByteArray(Reader in, String encoding); static byte[] toByteArray(InputStream in); static byte[] toByteArray( InputStream in, int size ); static int copy(InputStream in, OutputStream out); static int copy(Reader in, Writer out); }
IOUtil { protected static int calcNewNrReadSize(int nrRead, int totalNrNread) { if (totalNrNread < 0) { return totalNrNread; } if (totalNrNread > (Integer.MAX_VALUE - nrRead)) { return -1; } else { return (totalNrNread + nrRead); } }  static byte[] toByteArray(Reader in, String encoding); static byte[] toByteArray(InputStream in); static byte[] toByteArray( InputStream in, int size ); static int copy(InputStream in, OutputStream out); static int copy(Reader in, Writer out); static final int IO_COPY_BUFFER_SIZE; }