WiretapInputStream.java

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
Location : mark
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.tapNotAffectedByMarkAndReset()
removed call to java/io/InputStream::mark → KILLED

55

1.1
Location : reset
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.tapNotAffectedByMarkAndReset()
removed call to java/io/InputStream::reset → KILLED

62

1.1
Location : skip
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.bytesSkippedWhenTapOffAreNotStored()
negated conditional → KILLED

65

1.1
Location : skip
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.tapsSkippedBytes()
changed conditional boundary → KILLED

2.2
Location : skip
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.tapsSkippedBytes()
Changed increment from 1 to -1 → KILLED

3.3
Location : skip
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.tapsSkippedBytes()
negated conditional → KILLED

4.4
Location : skip
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.tapsSkippedBytes()
negated conditional → KILLED

66

1.1
Location : skip
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.tapsSkippedBytes()
removed call to java/io/ByteArrayOutputStream::write → KILLED

68

1.1
Location : skip
Killed by : none
replaced return of long value with value + 1 for io/earcam/utilitarian/io/WiretapInputStream::skip → SURVIVED

70

1.1
Location : skip
Killed by : none
replaced return of long value with value + 1 for io/earcam/utilitarian/io/WiretapInputStream::skip → SURVIVED

77

1.1
Location : close
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.underlyingIsClosed()
removed call to java/io/InputStream::close → KILLED

85

1.1
Location : read
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.tapNotAffectedByMarkAndReset()
negated conditional → KILLED

86

1.1
Location : read
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.tapNotAffectedByMarkAndReset()
Replaced integer addition with subtraction → KILLED

87

1.1
Location : read
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.tapNotAffectedByMarkAndReset()
negated conditional → KILLED

88

1.1
Location : read
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.tapNotAffectedByMarkAndReset()
removed call to java/io/ByteArrayOutputStream::write → KILLED

90

1.1
Location : read
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.tapNotAffectedByMarkAndReset()
changed conditional boundary → KILLED

2.2
Location : read
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.tapNotAffectedByMarkAndReset()
negated conditional → KILLED

91

1.1
Location : read
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.tapNotAffectedByMarkAndReset()
Replaced integer subtraction with addition → KILLED

92

1.1
Location : read
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.readOneByteWhenNotTapped()
negated conditional → KILLED

93

1.1
Location : read
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.tapNotAffectedByMarkAndReset()
removed call to java/io/ByteArrayOutputStream::write → KILLED

95

1.1
Location : read
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.readOneByteWhenNotTapped()
replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED

101

1.1
Location : toByteArray
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.readOneByteWhenNotTapped()
mutated return of Object value for io/earcam/utilitarian/io/WiretapInputStream::toByteArray to ( if (x != null) null else throw new RuntimeException ) → KILLED

107

1.1
Location : tapping
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.constructorArgumentDeterminesTapIsOff()
replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED

119

1.1
Location : tapOn
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.bytesSkippedWhenTapOffAreNotStored()
removed call to io/earcam/utilitarian/io/WiretapInputStream::tapping → KILLED

125

1.1
Location : tapOff
Killed by : io.earcam.utilitarian.io.WiretapInputStreamTest.onlyStoresWhenTapOn()
removed call to io/earcam/utilitarian/io/WiretapInputStream::tapping → KILLED

Active mutators

Tests examined


Report generated by PIT 1.4.3