ByteBufferInputStream.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.InputStream;
22
import java.nio.ByteBuffer;
23
24
public class ByteBufferInputStream extends InputStream {
25
26
	private final ByteBuffer buffer;
27
28
29
	public ByteBufferInputStream(ByteBuffer buffer)
30
	{
31
		this(buffer, true);
32
	}
33
34
35
	public ByteBufferInputStream(ByteBuffer buffer, boolean duplicate)
36
	{
37 1 1. : negated conditional → KILLED
		this.buffer = duplicate ? buffer.duplicate() : buffer;
38
	}
39
40
41
	@Override
42
	public int read()
43
	{
44 1 1. read : negated conditional → KILLED
		if(available() == 0) {
45 1 1. read : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED
			return -1;
46
		}
47 2 1. read : Replaced bitwise AND with OR → KILLED
2. read : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED
		return 0xFF & buffer.get();
48
	}
49
50
51
	@Override
52
	public int read(byte[] b)
53
	{
54 1 1. read : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED
		return read(b, 0, b.length);
55
	}
56
57
58
	@Override
59
	public int read(byte[] b, int off, int len)
60
	{
61
		int remaining = available();
62 1 1. read : negated conditional → KILLED
		if(remaining == 0) {
63 1 1. read : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED
			return -1;
64
		}
65
		int length = Math.min(len, remaining);
66
		buffer.get(b, off, length);
67 1 1. read : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED
		return length;
68
	}
69
70
71
	@Override
72
	public long skip(long n)
73
	{
74 2 1. skip : changed conditional boundary → SURVIVED
2. skip : negated conditional → KILLED
		if(n <= 0L) {
75 1 1. skip : replaced return of long value with value + 1 for io/earcam/utilitarian/io/ByteBufferInputStream::skip → SURVIVED
			return 0L;
76
		}
77
		int skipped = Math.min((int) n, buffer.remaining());
78 1 1. skip : Replaced integer addition with subtraction → KILLED
		buffer.position(buffer.position() + skipped);
79 1 1. skip : replaced return of long value with value + 1 for io/earcam/utilitarian/io/ByteBufferInputStream::skip → KILLED
		return skipped;
80
	}
81
82
83
	@Override
84
	public int available()
85
	{
86 1 1. available : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED
		return buffer.remaining();
87
	}
88
89
90
	@Override
91
	public void mark(int readlimit)
92
	{
93
		buffer.mark();
94
	}
95
96
97
	@Override
98
	public void reset()
99
	{
100
		buffer.reset();
101
	}
102
103
104
	@Override
105
	public boolean markSupported()
106
	{
107 1 1. markSupported : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED
		return true;
108
	}
109
110
111
	@Override
112
	public void close()
113
	{
114
		/* NoOp */
115
	}
116
}

Mutations

37

1.1
Location :
Killed by : io.earcam.utilitarian.io.ByteBufferInputStreamTest.whenDuplicatedThenBufferPositionDoesNotMoveWithStream()
negated conditional → KILLED

44

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

45

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

47

1.1
Location : read
Killed by : io.earcam.utilitarian.io.ByteBufferInputStreamTest.whenSkipLessThanZeroThenZeroSkipped()
Replaced bitwise AND with OR → KILLED

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

54

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

62

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

63

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

67

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

74

1.1
Location : skip
Killed by : none
changed conditional boundary → SURVIVED

2.2
Location : skip
Killed by : io.earcam.utilitarian.io.ByteBufferInputStreamTest.readsPastEndReturnsMinusOne()
negated conditional → KILLED

75

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

78

1.1
Location : skip
Killed by : io.earcam.utilitarian.io.ByteBufferInputStreamTest.readsPastEndReturnsMinusOne()
Replaced integer addition with subtraction → KILLED

79

1.1
Location : skip
Killed by : io.earcam.utilitarian.io.ByteBufferInputStreamTest.skips()
replaced return of long value with value + 1 for io/earcam/utilitarian/io/ByteBufferInputStream::skip → KILLED

86

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

107

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

Active mutators

Tests examined


Report generated by PIT 1.4.3