| 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.ByteArrayOutputStream; | |
| 22 | import java.io.IOException; | |
| 23 | import java.io.InputStream; | |
| 24 | ||
| 25 | public class WiretapInputStream extends InputStream { | |
| 26 | ||
| 27 | private InputStream tapped; | |
| 28 | private ByteArrayOutputStream tap; | |
| 29 | private boolean tapping; | |
| 30 | private boolean marked; | |
| 31 | private int mark; | |
| 32 | ||
| 33 | ||
| 34 | public WiretapInputStream(InputStream tapped, boolean tapOn) | |
| 35 | { | |
| 36 | this.tapping = tapOn; | |
| 37 | this.tapped = tapped; | |
| 38 | this.tap = new ByteArrayOutputStream(); | |
| 39 | } | |
| 40 | ||
| 41 | ||
| 42 | @Override | |
| 43 | public synchronized void mark(int readlimit) | |
| 44 | { | |
| 45 | marked = true; | |
| 46 | mark = 0; | |
| 47 |
1
1. mark : removed call to java/io/InputStream::mark → KILLED |
tapped.mark(readlimit); |
| 48 | } | |
| 49 | ||
| 50 | ||
| 51 | @Override | |
| 52 | public synchronized void reset() throws IOException | |
| 53 | { | |
| 54 | marked = false; | |
| 55 |
1
1. reset : removed call to java/io/InputStream::reset → KILLED |
tapped.reset(); |
| 56 | } | |
| 57 | ||
| 58 | ||
| 59 | @Override | |
| 60 | public long skip(long n) throws IOException | |
| 61 | { | |
| 62 |
1
1. skip : negated conditional → KILLED |
if(tapping) { |
| 63 | int i = 0; | |
| 64 | int b; | |
| 65 |
4
1. skip : changed conditional boundary → KILLED 2. skip : Changed increment from 1 to -1 → KILLED 3. skip : negated conditional → KILLED 4. skip : negated conditional → KILLED |
while(i++ < n && (b = tapped.read()) != -1) { |
| 66 |
1
1. skip : removed call to java/io/ByteArrayOutputStream::write → KILLED |
tap.write(b); |
| 67 | } | |
| 68 |
1
1. skip : replaced return of long value with value + 1 for io/earcam/utilitarian/io/WiretapInputStream::skip → SURVIVED |
return i; |
| 69 | } | |
| 70 |
1
1. skip : replaced return of long value with value + 1 for io/earcam/utilitarian/io/WiretapInputStream::skip → SURVIVED |
return super.skip(n); |
| 71 | } | |
| 72 | ||
| 73 | ||
| 74 | @Override | |
| 75 | public void close() throws IOException | |
| 76 | { | |
| 77 |
1
1. close : removed call to java/io/InputStream::close → KILLED |
tapped.close(); |
| 78 | } | |
| 79 | ||
| 80 | ||
| 81 | @Override | |
| 82 | public int read() throws IOException | |
| 83 | { | |
| 84 | int read = tapped.read(); | |
| 85 |
1
1. read : negated conditional → KILLED |
if(marked) { |
| 86 |
1
1. read : Replaced integer addition with subtraction → KILLED |
++mark; |
| 87 |
1
1. read : negated conditional → KILLED |
if(tapping) { |
| 88 |
1
1. read : removed call to java/io/ByteArrayOutputStream::write → KILLED |
tap.write(read); |
| 89 | } | |
| 90 |
2
1. read : changed conditional boundary → KILLED 2. read : negated conditional → KILLED |
} else if(mark > 0) { |
| 91 |
1
1. read : Replaced integer subtraction with addition → KILLED |
--mark; |
| 92 |
1
1. read : negated conditional → KILLED |
} else if(tapping) { |
| 93 |
1
1. read : removed call to java/io/ByteArrayOutputStream::write → KILLED |
tap.write(read); |
| 94 | } | |
| 95 |
1
1. read : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return read; |
| 96 | } | |
| 97 | ||
| 98 | ||
| 99 | public byte[] toByteArray() | |
| 100 | { | |
| 101 |
1
1. toByteArray : mutated return of Object value for io/earcam/utilitarian/io/WiretapInputStream::toByteArray to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return tap.toByteArray(); |
| 102 | } | |
| 103 | ||
| 104 | ||
| 105 | public boolean tapping() | |
| 106 | { | |
| 107 |
1
1. tapping : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return tapping; |
| 108 | } | |
| 109 | ||
| 110 | ||
| 111 | public void tapping(boolean tapOn) | |
| 112 | { | |
| 113 | tapping = tapOn; | |
| 114 | } | |
| 115 | ||
| 116 | ||
| 117 | public void tapOn() | |
| 118 | { | |
| 119 |
1
1. tapOn : removed call to io/earcam/utilitarian/io/WiretapInputStream::tapping → KILLED |
tapping(true); |
| 120 | } | |
| 121 | ||
| 122 | ||
| 123 | public void tapOff() | |
| 124 | { | |
| 125 |
1
1. tapOff : removed call to io/earcam/utilitarian/io/WiretapInputStream::tapping → KILLED |
tapping(false); |
| 126 | } | |
| 127 | } | |
Mutations | ||
| 47 |
1.1 |
|
| 55 |
1.1 |
|
| 62 |
1.1 |
|
| 65 |
1.1 2.2 3.3 4.4 |
|
| 66 |
1.1 |
|
| 68 |
1.1 |
|
| 70 |
1.1 |
|
| 77 |
1.1 |
|
| 85 |
1.1 |
|
| 86 |
1.1 |
|
| 87 |
1.1 |
|
| 88 |
1.1 |
|
| 90 |
1.1 2.2 |
|
| 91 |
1.1 |
|
| 92 |
1.1 |
|
| 93 |
1.1 |
|
| 95 |
1.1 |
|
| 101 |
1.1 |
|
| 107 |
1.1 |
|
| 119 |
1.1 |
|
| 125 |
1.1 |