Skip to content

Commit 082a719

Browse files
committed
IO: Rename these fields to follow conventions.
Makes the code clearer IMO.
1 parent b48c5a7 commit 082a719

File tree

7 files changed

+36
-41
lines changed

7 files changed

+36
-41
lines changed

io/src/main/java/co/casterlabs/commons/io/bytes/reading/_AsInputStream.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
@AllArgsConstructor
1010
class _AsInputStream extends InputStream {
11-
private final ByteReader reader;
11+
private final ByteReader delegate;
1212

1313
@Override
1414
public int read() throws IOException {
1515
try {
16-
return this.reader.read();
16+
return this.delegate.read();
1717
} catch (EndOfStreamException e) {
1818
return -1;
1919
}
@@ -22,7 +22,7 @@ public int read() throws IOException {
2222
@Override
2323
public int read(byte[] b, int off, int len) throws IOException {
2424
try {
25-
this.reader.read(b, off, len);
25+
this.delegate.read(b, off, len);
2626
return len;
2727
} catch (EndOfStreamException e) {
2828
return -1;

io/src/main/java/co/casterlabs/commons/io/bytes/writing/_AsOutputStream.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77

88
@AllArgsConstructor
99
class _AsOutputStream extends OutputStream {
10-
private final ByteWriter writer;
10+
private final ByteWriter delegate;
1111

1212
@Override
1313
public void write(int b) throws IOException {
14-
this.writer.write(b);
14+
this.delegate.write(b);
1515
}
1616

1717
@Override
1818
public void write(byte[] b) throws IOException {
19-
this.writer.write(b);
19+
this.delegate.write(b);
2020
}
2121

2222
@Override
2323
public void write(byte[] b, int off, int len) throws IOException {
24-
this.writer.write(b, off, len);
24+
this.delegate.write(b, off, len);
2525
}
2626

2727
}

io/src/main/java/co/casterlabs/commons/io/streams/ForceFlushedOutputStream.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,49 @@
2121
*/
2222
@RequiredArgsConstructor
2323
public class ForceFlushedOutputStream extends OutputStream {
24-
private final OutputStream wrap;
24+
private final OutputStream underlying;
2525

2626
/**
2727
* See: {@link OutputStream#write(int)}
2828
*/
2929
@Override
3030
public void write(int b) throws IOException {
31-
this.wrap.write(b);
32-
this.wrap.flush();
31+
this.underlying.write(b);
32+
this.underlying.flush();
3333
}
3434

3535
/**
3636
* See: {@link OutputStream#write(byte[])}
3737
*/
3838
@Override
3939
public void write(byte[] b) throws IOException {
40-
this.wrap.write(b);
41-
this.wrap.flush();
40+
this.underlying.write(b);
41+
this.underlying.flush();
4242
}
4343

4444
/**
4545
* See: {@link OutputStream#write(byte[], int, int)}
4646
*/
4747
@Override
4848
public void write(byte[] b, int off, int len) throws IOException {
49-
this.wrap.write(b, off, len);
50-
this.wrap.flush();
49+
this.underlying.write(b, off, len);
50+
this.underlying.flush();
5151
}
5252

5353
/**
5454
* See: {@link OutputStream#flush()}
5555
*/
5656
@Override
5757
public void flush() throws IOException {
58-
this.wrap.flush();
58+
this.underlying.flush();
5959
}
6060

6161
/**
6262
* See: {@link OutputStream#close()}
6363
*/
6464
@Override
6565
public void close() throws IOException {
66-
this.wrap.close();
66+
this.underlying.close();
6767
}
6868

6969
}

io/src/main/java/co/casterlabs/commons/io/streams/LimitedInputStream.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
@AllArgsConstructor
2626
public class LimitedInputStream extends InputStream {
27-
private final InputStream in;
27+
private final InputStream underlying;
2828
private long remaining;
2929

3030
/**
@@ -41,7 +41,7 @@ public int read() throws IOException {
4141
return -1;
4242
}
4343
this.remaining--;
44-
return this.in.read();
44+
return this.underlying.read();
4545
}
4646

4747
@Override
@@ -58,7 +58,7 @@ public int read(byte b[], int off, int len) throws IOException {
5858
len = (int) this.remaining;
5959
}
6060

61-
int read = this.in.read(b, off, len);
61+
int read = this.underlying.read(b, off, len);
6262
this.remaining -= read;
6363
return read;
6464
}
@@ -77,7 +77,7 @@ public long skip(long n) throws IOException {
7777
n = this.remaining;
7878
}
7979

80-
long skipped = this.in.skip(n);
80+
long skipped = this.underlying.skip(n);
8181
this.remaining -= skipped;
8282
return skipped;
8383
}
@@ -88,7 +88,7 @@ public int available() throws IOException {
8888
return -1;
8989
}
9090

91-
int available = this.in.available();
91+
int available = this.underlying.available();
9292
if (available > this.remaining) {
9393
return (int) this.remaining;
9494
}

io/src/main/java/co/casterlabs/commons/io/streams/NonCloseableOutputStream.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
@RequiredArgsConstructor
2323
public class NonCloseableOutputStream extends OutputStream {
24-
private final OutputStream out;
24+
private final OutputStream underlying;
2525
private boolean isClosed;
2626

2727
@Override
@@ -33,14 +33,14 @@ public void close() throws IOException {
3333
@Override
3434
public void write(int b) throws IOException {
3535
if (this.isClosed) throw new IOException("NCOutputStream is closed.");
36-
this.out.write(b);
36+
this.underlying.write(b);
3737
}
3838

3939
@Override
4040
public void write(byte[] b, int off, int len) throws IOException {
4141
if (this.isClosed) throw new IOException("NCOutputStream is closed.");
4242
if (len == 0) return;
43-
this.out.write(b, off, len);
43+
this.underlying.write(b, off, len);
4444
}
4545

4646
}

io/src/main/java/co/casterlabs/commons/io/streams/OverzealousInputStream.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
import java.util.concurrent.locks.ReentrantLock;
66

77
import lombok.NonNull;
8+
import lombok.RequiredArgsConstructor;
89

910
/**
1011
* Basically we buffered too many bytes, so we need to give them back during a
1112
* read.
1213
*/
14+
@RequiredArgsConstructor
1315
public class OverzealousInputStream extends InputStream {
1416
private final ReentrantLock lock = new ReentrantLock();
1517

@@ -19,10 +21,6 @@ public class OverzealousInputStream extends InputStream {
1921
private int overageEnd = 0;
2022
private int overageIndex = 0;
2123

22-
public OverzealousInputStream(@NonNull InputStream underlying) {
23-
this.underlying = underlying;
24-
}
25-
2624
private void ensureCapacity(int additionalSize) {
2725
int requiredCapacity = this.overageEnd - this.overageIndex + additionalSize;
2826
if (requiredCapacity > this.overage.length) {

io/src/main/java/co/casterlabs/commons/io/streams/PeekableInputStream.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import java.io.IOException;
1515
import java.io.InputStream;
1616

17-
import lombok.NonNull;
17+
import lombok.RequiredArgsConstructor;
1818

1919
/**
2020
* An InputStream wrapper that allows you to "peek" ahead at bytes without
@@ -24,16 +24,13 @@
2424
*
2525
* @see {@link PeekableInputStream#peek(int)}
2626
*/
27+
@RequiredArgsConstructor
2728
public class PeekableInputStream extends InputStream {
28-
private final InputStream wrapped;
29+
private final InputStream underlying;
2930

3031
private byte[] currentBuffer = null;
3132
private int bufferPos = 0;
3233

33-
public PeekableInputStream(@NonNull InputStream toWrap) {
34-
this.wrapped = toWrap;
35-
}
36-
3734
/**
3835
* @return if the stream is current buffering data as the result of a peek()
3936
* operation.
@@ -87,7 +84,7 @@ public synchronized void preBuffer(int nbytes) throws IOException {
8784
int bytesReadIntoBuffer = oldAmountBuffered;
8885
do {
8986
// Keep reading into the buffer until we have the correct amount.
90-
bytesReadIntoBuffer += this.wrapped.read(this.currentBuffer, bytesReadIntoBuffer, newBufferSize - bytesReadIntoBuffer);
87+
bytesReadIntoBuffer += this.underlying.read(this.currentBuffer, bytesReadIntoBuffer, newBufferSize - bytesReadIntoBuffer);
9188
} while (bytesReadIntoBuffer < newBufferSize);
9289
} else {
9390
// We need to create a buffer.
@@ -99,7 +96,7 @@ public synchronized void preBuffer(int nbytes) throws IOException {
9996
int bytesReadIntoBuffer = 0;
10097
do {
10198
// Keep reading into the buffer until we have the correct amount.
102-
bytesReadIntoBuffer += this.wrapped.read(this.currentBuffer, bytesReadIntoBuffer, toRead - bytesReadIntoBuffer);
99+
bytesReadIntoBuffer += this.underlying.read(this.currentBuffer, bytesReadIntoBuffer, toRead - bytesReadIntoBuffer);
103100
} while (bytesReadIntoBuffer < toRead);
104101
}
105102
} // Otherwise, we already have the data buffered :D
@@ -132,7 +129,7 @@ public synchronized int peek(int ahead) throws IOException {
132129
@Override
133130
public synchronized int read() throws IOException {
134131
if (!this.hasDataBuffered()) {
135-
return this.wrapped.read();
132+
return this.underlying.read();
136133
}
137134

138135
int result = this.currentBuffer[this.bufferPos++];
@@ -150,7 +147,7 @@ public synchronized int read() throws IOException {
150147
@Override
151148
public synchronized int read(byte[] b, int off, int len) throws IOException {
152149
if (!this.hasDataBuffered()) {
153-
return this.wrapped.read(b, off, len);
150+
return this.underlying.read(b, off, len);
154151
}
155152

156153
int nread = Math.min(len, this.amountBuffered());
@@ -171,7 +168,7 @@ public synchronized int read(byte[] b, int off, int len) throws IOException {
171168
@Override
172169
public synchronized long skip(long n) throws IOException {
173170
if (!this.hasDataBuffered()) {
174-
return this.wrapped.skip(n);
171+
return this.underlying.skip(n);
175172
}
176173

177174
long nread = Math.min(n, this.amountBuffered());
@@ -190,7 +187,7 @@ public synchronized long skip(long n) throws IOException {
190187
@Override
191188
public synchronized int available() throws IOException {
192189
if (!this.hasDataBuffered()) {
193-
return this.wrapped.available();
190+
return this.underlying.available();
194191
}
195192

196193
return this.amountBuffered();
@@ -209,7 +206,7 @@ public synchronized int available() throws IOException {
209206
@Override
210207
public void close() throws IOException {
211208
this.currentBuffer = null;
212-
this.wrapped.close();
209+
this.underlying.close();
213210
}
214211

215212
}

0 commit comments

Comments
 (0)