Skip to content

Commit 514ca6c

Browse files
committed
Renames InputStreamInterceptor methods to avoid referring to 'headers'.
1 parent 6c97502 commit 514ca6c

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

src/main/java/com/amazon/ion/impl/_Private_IonReaderBuilder.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,12 @@ static IonReader buildReader(
215215
) {
216216
List<InputStreamInterceptor> streamInterceptors = builder.getInputStreamInterceptors();
217217
for (InputStreamInterceptor streamInterceptor : streamInterceptors) {
218-
int headerLength = streamInterceptor.headerMatchLength();
218+
int headerLength = streamInterceptor.numberOfBytesNeededToDetermineMatch();
219219
validateHeaderLength(headerLength);
220220
if (length < headerLength) {
221221
continue;
222222
}
223-
if (streamInterceptor.matchesHeader(ionData, offset, length)) {
223+
if (streamInterceptor.isMatch(ionData, offset, length)) {
224224
try {
225225
return buildReader(
226226
builder,
@@ -329,7 +329,7 @@ static IonReader buildReader(
329329
}
330330
int maxHeaderLength = Math.max(
331331
_Private_IonConstants.BINARY_VERSION_MARKER_SIZE,
332-
inputStreamInterceptors.stream().mapToInt(InputStreamInterceptor::headerMatchLength).max().orElse(0)
332+
inputStreamInterceptors.stream().mapToInt(InputStreamInterceptor::numberOfBytesNeededToDetermineMatch).max().orElse(0)
333333
);
334334
validateHeaderLength(maxHeaderLength);
335335
// Note: this can create a lot of layers of InputStream wrappers. For example, if this method is called
@@ -349,10 +349,10 @@ static IonReader buildReader(
349349
// or it's a binary stream (in which case the correct reader was created) or it's a growing text stream
350350
// (which has always been unsupported).
351351
for (InputStreamInterceptor streamInterceptor : inputStreamInterceptors) {
352-
if (bytesRead < streamInterceptor.headerMatchLength()) {
352+
if (bytesRead < streamInterceptor.numberOfBytesNeededToDetermineMatch()) {
353353
continue;
354354
}
355-
if (streamInterceptor.matchesHeader(possibleIVM, 0, bytesRead)) {
355+
if (streamInterceptor.isMatch(possibleIVM, 0, bytesRead)) {
356356
try {
357357
ionData = streamInterceptor.newInputStream(
358358
new TwoElementInputStream(new ByteArrayInputStream(possibleIVM, 0, bytesRead), ionData)

src/main/java/com/amazon/ion/util/GzipStreamInterceptor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public String formatName() {
2121
}
2222

2323
@Override
24-
public int headerMatchLength() {
24+
public int numberOfBytesNeededToDetermineMatch() {
2525
return GZIP_HEADER.length;
2626
}
2727

2828
@Override
29-
public boolean matchesHeader(byte[] candidate, int offset, int length) {
29+
public boolean isMatch(byte[] candidate, int offset, int length) {
3030
if (candidate == null || length < GZIP_HEADER.length) {
3131
return false;
3232
}

src/main/java/com/amazon/ion/util/InputStreamInterceptor.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
/**
1212
* An interceptor to be consulted by the {@link com.amazon.ion.system.IonReaderBuilder} when creating an
13-
* {@link IonReader} over a user-provided stream. This allows users to configure a sequence of interceptors
14-
* to allow transformation of the stream's raw bytes into valid text or binary Ion.
13+
* {@link IonReader} over a user-provided stream. This allows users to transform a stream's raw bytes into
14+
* valid text or binary Ion.
1515
*
1616
* @see com.amazon.ion.system.IonReaderBuilder#addInputStreamInterceptor(InputStreamInterceptor)
1717
* @see com.amazon.ion.system.IonSystemBuilder#withReaderBuilder(IonReaderBuilder)
@@ -26,22 +26,22 @@ public interface InputStreamInterceptor {
2626

2727
/**
2828
* The number of bytes required to be read from the beginning of the stream in order to determine whether
29-
* it matches this format. If a stream contains fewer than the number of bytes returned by this method, then
30-
* {@link #matchesHeader(byte[], int, int)} will never be called and this interceptor will not be considered
31-
* a match.
29+
* it matches the format relevant to this interceptor. If a stream contains fewer than the number of bytes
30+
* returned by this method, then this interceptor will not be considered a match and
31+
* {@link #isMatch(byte[], int, int)} will not be called.
3232
* @return the length in bytes.
3333
*/
34-
int headerMatchLength();
34+
int numberOfBytesNeededToDetermineMatch();
3535

3636
/**
3737
* Determines whether the given candidate byte sequence matches this format.
3838
* @param candidate the candidate byte sequence.
3939
* @param offset the offset into the candidate bytes to begin matching.
4040
* @param length the number of bytes (beginning at 'offset') in `candidate`. Must be greater than or equal to
41-
* {@link #headerMatchLength()}.
41+
* {@link #numberOfBytesNeededToDetermineMatch()}.
4242
* @return true if the candidate byte sequence matches; otherwise, false.
4343
*/
44-
boolean matchesHeader(byte[] candidate, int offset, int length);
44+
boolean isMatch(byte[] candidate, int offset, int length);
4545

4646
/**
4747
* Creates a new InputStream that transforms the bytes in the given InputStream into valid text or binary Ion.

src/test/java/com/amazon/ion/util/ZstdStreamInterceptorTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ public String formatName() {
5959
}
6060

6161
@Override
62-
public int headerMatchLength() {
62+
public int numberOfBytesNeededToDetermineMatch() {
6363
return ZSTD_HEADER.length;
6464
}
6565

6666
@Override
67-
public boolean matchesHeader(byte[] candidate, int offset, int length) {
67+
public boolean isMatch(byte[] candidate, int offset, int length) {
6868
if (candidate == null || length < ZSTD_HEADER.length) {
6969
return false;
7070
}
@@ -362,12 +362,12 @@ public String formatName() {
362362
}
363363

364364
@Override
365-
public int headerMatchLength() {
365+
public int numberOfBytesNeededToDetermineMatch() {
366366
return length;
367367
}
368368

369369
@Override
370-
public boolean matchesHeader(byte[] candidate, int offset, int length) {
370+
public boolean isMatch(byte[] candidate, int offset, int length) {
371371
return Assertions.fail("This method should be unreachable.");
372372
}
373373

0 commit comments

Comments
 (0)