Repository: nifi Updated Branches: refs/heads/develop a19390cde -> dcd9739bc
NIFI-769: - Add test for and fix bug in ByteCountingInputStream reset method. Signed-off-by: Mark Payne <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/dcd9739b Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/dcd9739b Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/dcd9739b Branch: refs/heads/develop Commit: dcd9739bc36f1ba73d27b4bcb1c7158bcd9da5cd Parents: a19390c Author: Joe Skora <[email protected]> Authored: Fri Jul 17 00:31:21 2015 -0400 Committer: Mark Payne <[email protected]> Committed: Mon Jul 20 11:25:36 2015 -0400 ---------------------------------------------------------------------- .../nifi/stream/io/ByteCountingInputStream.java | 1 + .../stream/io/ByteCountingInputStreamTest.java | 55 ++++++++++++++++++++ 2 files changed, 56 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/dcd9739b/nifi/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/stream/io/ByteCountingInputStream.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/stream/io/ByteCountingInputStream.java b/nifi/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/stream/io/ByteCountingInputStream.java index d1ed023..e9b8c9e 100644 --- a/nifi/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/stream/io/ByteCountingInputStream.java +++ b/nifi/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/stream/io/ByteCountingInputStream.java @@ -100,6 +100,7 @@ public class ByteCountingInputStream extends InputStream { public void reset() throws IOException { in.reset(); bytesRead -= bytesSinceMark; + bytesSinceMark = 0L; } @Override http://git-wip-us.apache.org/repos/asf/nifi/blob/dcd9739b/nifi/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/ByteCountingInputStreamTest.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/ByteCountingInputStreamTest.java b/nifi/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/ByteCountingInputStreamTest.java new file mode 100644 index 0000000..27b1493 --- /dev/null +++ b/nifi/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/ByteCountingInputStreamTest.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.stream.io; + +import junit.framework.TestCase; + +public class ByteCountingInputStreamTest extends TestCase { + + final ByteArrayInputStream reader = new ByteArrayInputStream("abcdefghijklmnopqrstuvwxyz".getBytes()); + + public void testReset() throws Exception { + + final ByteArrayInputStream reader = new ByteArrayInputStream("abcdefghijklmnopqrstuvwxyz".getBytes()); + final ByteCountingInputStream bcis = new ByteCountingInputStream(reader); + int tmp; + + /* verify first 2 bytes */ + tmp = bcis.read(); + assertEquals(tmp, 97); + tmp = bcis.read(); + assertEquals(tmp, 98); + + /* save bytes read and place mark */ + final long bytesAtMark = bcis.getBytesRead(); + bcis.mark(0); + + /* verify next 2 bytes */ + tmp = bcis.read(); + assertEquals(tmp, 99); + tmp = bcis.read(); + assertEquals(tmp, 100); + + /* verify reset returns to position when mark was placed */ + bcis.reset(); + assertEquals(bytesAtMark, bcis.getBytesRead()); + + /* verify that the reset bug has been fixed (bug would reduce bytes read count) */ + bcis.reset(); + assertEquals(bytesAtMark, bcis.getBytesRead()); + } +} \ No newline at end of file
