1 | /*- | |
2 | * #%L | |
3 | * io.earcam.instrumental.io | |
4 | * %% | |
5 | * Copyright (C) 2018 earcam | |
6 | * %% | |
7 | * SPDX-License-Identifier: (BSD-3-Clause OR EPL-1.0 OR Apache-2.0 OR MIT) | |
8 | * | |
9 | * You <b>must</b> choose to accept, in full - any individual or combination of | |
10 | * the following licenses: | |
11 | * <ul> | |
12 | * <li><a href="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause</a></li> | |
13 | * <li><a href="https://www.eclipse.org/legal/epl-v10.html">EPL-1.0</a></li> | |
14 | * <li><a href="https://www.apache.org/licenses/LICENSE-2.0">Apache-2.0</a></li> | |
15 | * <li><a href="https://opensource.org/licenses/MIT">MIT</a></li> | |
16 | * </ul> | |
17 | * #L% | |
18 | */ | |
19 | package io.earcam.utilitarian.io; | |
20 | ||
21 | import java.io.IOException; | |
22 | import java.io.InputStream; | |
23 | import java.util.Objects; | |
24 | ||
25 | public class CountedInputStream extends InputStream { | |
26 | ||
27 | private final InputStream delegate; | |
28 | private long count; | |
29 | private boolean marked; | |
30 | private long mark; | |
31 | ||
32 | ||
33 | public CountedInputStream(InputStream wrapped) | |
34 | { | |
35 | Objects.requireNonNull(wrapped); | |
36 | this.delegate = wrapped; | |
37 | } | |
38 | ||
39 | ||
40 | @Override | |
41 | public void close() throws IOException | |
42 | { | |
43 |
1
1. close : removed call to java/io/InputStream::close → KILLED |
delegate.close(); |
44 | } | |
45 | ||
46 | ||
47 | public synchronized long count() | |
48 | { | |
49 |
1
1. count : replaced return of long value with value + 1 for io/earcam/utilitarian/io/CountedInputStream::count → KILLED |
return count; |
50 | } | |
51 | ||
52 | ||
53 | public synchronized void resetCount() | |
54 | { | |
55 | count = 0L; | |
56 | } | |
57 | ||
58 | ||
59 | @Override | |
60 | public synchronized void mark(int readlimit) | |
61 | { | |
62 | marked = true; | |
63 |
1
1. mark : removed call to java/io/InputStream::mark → KILLED |
delegate.mark(readlimit); |
64 | } | |
65 | ||
66 | ||
67 | @Override | |
68 | public synchronized void reset() throws IOException | |
69 | { | |
70 | marked = false; | |
71 |
1
1. reset : removed call to java/io/InputStream::reset → KILLED |
delegate.reset(); |
72 | } | |
73 | ||
74 | ||
75 | @Override | |
76 | public int read() throws IOException | |
77 | { | |
78 | int read = delegate.read(); | |
79 |
1
1. read : negated conditional → KILLED |
if(read != -1) { |
80 |
1
1. read : negated conditional → SURVIVED |
if(marked) { |
81 |
1
1. read : Replaced long addition with subtraction → KILLED |
++mark; |
82 |
1
1. read : Replaced long addition with subtraction → KILLED |
++count; |
83 |
2
1. read : changed conditional boundary → KILLED 2. read : negated conditional → KILLED |
} else if(mark > 0) { |
84 |
1
1. read : Replaced long subtraction with addition → KILLED |
--mark; |
85 | } else { | |
86 |
1
1. read : Replaced long addition with subtraction → KILLED |
++count; |
87 | } | |
88 | } | |
89 |
1
1. read : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return read; |
90 | } | |
91 | } | |
Mutations | ||
43 |
1.1 |
|
49 |
1.1 |
|
63 |
1.1 |
|
71 |
1.1 |
|
79 |
1.1 |
|
80 |
1.1 |
|
81 |
1.1 |
|
82 |
1.1 |
|
83 |
1.1 2.2 |
|
84 |
1.1 |
|
86 |
1.1 |
|
89 |
1.1 |