/** * Set the byte count back to 0. * <p> * NOTE: From v1.3 this method throws an ArithmeticException if the * count is greater than can be expressed by an <code>int</code>. * See {@link #resetByteCount()} for a method using a <code>long</code>. * * @return the count previous to resetting * @throws ArithmeticException if the byte count is too large */ public int resetCount() { final long result = resetByteCount(); if (result > Integer.MAX_VALUE) { throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int"); } return (int) result; }
/** * Set the byte count back to 0. * <p> * NOTE: From v1.3 this method throws an ArithmeticException if the * count is greater than can be expressed by an <code>int</code>. * See {@link #resetByteCount()} for a method using a <code>long</code>. * * @return the count previous to resetting * @throws ArithmeticException if the byte count is too large */ public synchronized int resetCount() { long result = resetByteCount(); if (result > Integer.MAX_VALUE) { throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int"); } return (int) result; }
@Test public void testLargeFiles_IO84() throws Exception { final long size = (long)Integer.MAX_VALUE + (long)1; final NullInputStream mock = new NullInputStream(size); final CountingInputStream cis = new CountingInputStream(mock); final OutputStream out = new NullOutputStream(); // Test integer methods IOUtils.copyLarge(cis, out); try { cis.getCount(); fail("Expected getCount() to throw an ArithmeticException"); } catch (final ArithmeticException ae) { // expected result } try { cis.resetCount(); fail("Expected resetCount() to throw an ArithmeticException"); } catch (final ArithmeticException ae) { // expected result } mock.close(); // Test long methods IOUtils.copyLarge(cis, out); assertEquals("getByteCount()", size, cis.getByteCount()); assertEquals("resetByteCount()", size, cis.resetByteCount()); }
/** * Set the byte count back to 0. * <p> * NOTE: From v1.3 this method throws an ArithmeticException if the * count is greater than can be expressed by an <code>int</code>. * See {@link #resetByteCount()} for a method using a <code>long</code>. * * @return the count previous to resetting * @throws ArithmeticException if the byte count is too large */ public int resetCount() { long result = resetByteCount(); if (result > Integer.MAX_VALUE) { throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int"); } return (int) result; }
/** * Set the byte count back to 0. * <p> * NOTE: From v1.3 this method throws an ArithmeticException if the * count is greater than can be expressed by an <code>int</code>. * See {@link #resetByteCount()} for a method using a <code>long</code>. * * @return the count previous to resetting * @throws ArithmeticException if the byte count is too large */ public synchronized int resetCount() { long result = resetByteCount(); if (result > Integer.MAX_VALUE) { throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int"); } return (int) result; }
/** * Set the byte count back to 0. * <p> * NOTE: From v1.3 this method throws an ArithmeticException if the * count is greater than can be expressed by an <code>int</code>. * See {@link #resetByteCount()} for a method using a <code>long</code>. * * @return the count previous to resetting * @throws ArithmeticException if the byte count is too large */ public synchronized int resetCount() { long result = resetByteCount(); if (result > Integer.MAX_VALUE) { throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int"); } return (int) result; }
/** * Set the byte count back to 0. * <p> * NOTE: From v1.3 this method throws an ArithmeticException if the * count is greater than can be expressed by an <code>int</code>. * See {@link #resetByteCount()} for a method using a <code>long</code>. * * @return the count previous to resetting * @throws ArithmeticException if the byte count is too large */ public int resetCount() { final long result = resetByteCount(); if (result > Integer.MAX_VALUE) { throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int"); } return (int) result; }
/** * Set the byte count back to 0. * <p> * NOTE: From v1.3 this method throws an ArithmeticException if the * count is greater than can be expressed by an <code>int</code>. * See {@link #resetByteCount()} for a method using a <code>long</code>. * * @return the count previous to resetting * @throws ArithmeticException if the byte count is too large */ public int resetCount() { final long result = resetByteCount(); if (result > Integer.MAX_VALUE) { throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int"); } return (int) result; }
/** * Set the byte count back to 0. * <p> * NOTE: From v1.3 this method throws an ArithmeticException if the * count is greater than can be expressed by an <code>int</code>. * See {@link #resetByteCount()} for a method using a <code>long</code>. * * @return the count previous to resetting * @throws ArithmeticException if the byte count is too large */ public int resetCount() { long result = resetByteCount(); if (result > Integer.MAX_VALUE) { throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int"); } return (int) result; }
/** * Skip the remaining bytes of the last message returned from nextMessage(). This must be called if it is not certain * that all of the bytes of the message were consumed. * @throws IOException On IO error */ public void skipRemainingBytes() throws IOException { long count = countingInputStream.resetByteCount(); if (count < messageSize) { IOUtils.skipFully(dataInputStream, messageSize - count); } messageSize = 0; } }