Skip to content

Commit 13d0e60

Browse files
authored
Deprecated public constructor of DataReader, replaced with static create method. (helidon-io#10867)
Replaced usages.
1 parent bcf5843 commit 13d0e60

16 files changed

Lines changed: 63 additions & 38 deletions

File tree

common/buffers/src/main/java/io/helidon/common/buffers/DataReader.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ public class DataReader {
3838
* Data reader from a supplier of bytes.
3939
*
4040
* @param bytesSupplier supplier that can be pulled for more data
41+
* @deprecated use {@link #create(java.util.function.Supplier)} instead
4142
*/
43+
@Deprecated(forRemoval = true, since = "4.4.0")
4244
public DataReader(Supplier<byte[]> bytesSupplier) {
4345
this.ignoreLoneEol = false;
4446
this.bytesSupplier = bytesSupplier;
@@ -52,7 +54,9 @@ public DataReader(Supplier<byte[]> bytesSupplier) {
5254
*
5355
* @param bytesSupplier supplier that can be pulled for more data
5456
* @param ignoreLoneEol ignore LF without CR and CR without LF
57+
* @deprecated use {@link #create(java.util.function.Supplier, boolean)} instead
5558
*/
59+
@Deprecated(forRemoval = true, since = "4.4.0")
5660
public DataReader(Supplier<byte[]> bytesSupplier, boolean ignoreLoneEol) {
5761
this.ignoreLoneEol = ignoreLoneEol;
5862
this.bytesSupplier = bytesSupplier;
@@ -61,6 +65,27 @@ public DataReader(Supplier<byte[]> bytesSupplier, boolean ignoreLoneEol) {
6165
this.tail = this.head;
6266
}
6367

68+
/**
69+
* Data reader from a supplier of bytes.
70+
*
71+
* @param bytesSupplier supplier that can be pulled for more data
72+
* @return data reader using the provided supplier and treating only {@code CRLF} as a new line
73+
*/
74+
public static DataReader create(Supplier<byte[]> bytesSupplier) {
75+
return new DataReader(bytesSupplier);
76+
}
77+
78+
/**
79+
* Data reader from a supplier of bytes.
80+
*
81+
* @param bytesSupplier supplier that can be pulled for more data
82+
* @param ignoreLoneEol ignore LF without CR and CR without LF
83+
* @return data reader using the provided supplier with specified new line handling
84+
*/
85+
public static DataReader create(Supplier<byte[]> bytesSupplier, boolean ignoreLoneEol) {
86+
return new DataReader(bytesSupplier, ignoreLoneEol);
87+
}
88+
6489
/**
6590
* Number of bytes available in the currently pulled data.
6691
*

common/buffers/src/test/java/io/helidon/common/buffers/DataReaderTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Oracle and/or its affiliates.
2+
* Copyright (c) 2024, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@ void testFindNewLineWithLoneCR() {
3333

3434
byte[] data = "00\r0\r\n".getBytes(StandardCharsets.US_ASCII);
3535
AtomicReference<byte[]> ref = new AtomicReference<>(data);
36-
DataReader dataReader = new DataReader(() -> ref.getAndSet(null), true);
36+
DataReader dataReader = DataReader.create(() -> ref.getAndSet(null), true);
3737

3838
int n = 2;
3939
assertThat(dataReader.findNewLine(n), is(n));
@@ -50,7 +50,7 @@ void testFindNewLineWithMultipleLoneCR() {
5050

5151
byte[] data = "00\r\r\r\n".getBytes(StandardCharsets.US_ASCII);
5252
AtomicReference<byte[]> ref = new AtomicReference<>(data);
53-
DataReader dataReader = new DataReader(() -> ref.getAndSet(null), true);
53+
DataReader dataReader = DataReader.create(() -> ref.getAndSet(null), true);
5454

5555
int n = 5;
5656
assertThat(dataReader.findNewLine(n), is(4));
@@ -63,7 +63,7 @@ void testFindNewLineWithMultipleLoneWithinMax() {
6363

6464
byte[] data = "00\r00\r\n00".getBytes(StandardCharsets.US_ASCII);
6565
AtomicReference<byte[]> ref = new AtomicReference<>(data);
66-
DataReader dataReader = new DataReader(() -> ref.getAndSet(null), true);
66+
DataReader dataReader = DataReader.create(() -> ref.getAndSet(null), true);
6767

6868
int n = 4;
6969
assertThat(dataReader.findNewLine(n), is(n));

http/http/src/test/java/io/helidon/http/Http1HeadersParserTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,7 +40,7 @@ class Http1HeadersParserTest {
4040

4141
@Test
4242
void testHeadersAreCaseInsensitive() {
43-
DataReader reader = new DataReader(() -> (
43+
DataReader reader = DataReader.create(() -> (
4444
"Set-Cookie: c1=v1\r\nSet-Cookie: c2=v2\r\n"
4545
+ "Header: hv1\r\nheader: hv2\r\nheaDer: hv3\r\n"
4646
+ "\r\n").getBytes(StandardCharsets.US_ASCII));
@@ -83,7 +83,7 @@ void testHeadersWithValidationDisabled(String headerValue) {
8383

8484
private static WritableHeaders<?> getHeaders(String headerName, String headerValue, boolean validate) {
8585
DataReader reader =
86-
new DataReader(() -> (headerName + ":" + headerValue + "\r\n" + "\r\n").getBytes(StandardCharsets.US_ASCII));
86+
DataReader.create(() -> (headerName + ":" + headerValue + "\r\n" + "\r\n").getBytes(StandardCharsets.US_ASCII));
8787
return Http1HeadersParser.readHeaders(reader, 1024, validate);
8888
}
8989

http/media/multipart/src/main/java/io/helidon/http/media/multipart/MultiPartImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@ class MultiPartImpl extends MultiPart {
4545
this.endBoundary = "--" + boundary + "--";
4646
this.maxNewLine = this.boundary.length() + 6;
4747
byte[] readBuffer = new byte[1024];
48-
this.dataReader = new DataReader(() -> {
48+
this.dataReader = DataReader.create(() -> {
4949
try {
5050
int r = stream.read(readBuffer);
5151
if (r == -1) {

metadata/hson/src/main/java/io/helidon/metadata/hson/HsonParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Oracle and/or its affiliates.
2+
* Copyright (c) 2024, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@ private HsonParser(DataReader reader) {
4747
}
4848

4949
static Hson.Value<?> parse(InputStream stream) {
50-
DataReader dr = new DataReader(() -> {
50+
DataReader dr = DataReader.create(() -> {
5151
byte[] buffer = new byte[1024];
5252
try {
5353
int num = stream.read(buffer);

tests/benchmark/jmh/src/main/java/io/helidon/webserver/benchmark/jmh/Http1ParsingJmhTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -68,14 +68,14 @@ public void setup() {
6868

6969
@Benchmark
7070
public void singleBuffer(Blackhole bh) {
71-
DataReader reader = new DataReader(() -> SINGLE_BUFFER);
71+
DataReader reader = DataReader.create(() -> SINGLE_BUFFER);
7272
readRequest(bh, reader);
7373
}
7474

7575
@Benchmark
7676
public void multiBuffer(Blackhole bh) {
7777
Iterator<byte[]> iterator = MULTI_BUFFER.iterator();
78-
DataReader reader = new DataReader(() -> {
78+
DataReader reader = DataReader.create(() -> {
7979
if (iterator.hasNext()) {
8080
return iterator.next();
8181
}
@@ -86,7 +86,7 @@ public void multiBuffer(Blackhole bh) {
8686

8787
@Benchmark
8888
public void longHeader(Blackhole bh) {
89-
DataReader reader = new DataReader(() -> longMessage);
89+
DataReader reader = DataReader.create(() -> longMessage);
9090
readRequest(bh, reader);
9191
}
9292

tests/benchmark/jmh/src/main/java/io/helidon/webserver/benchmark/jmh/HttpPrologueParsingJmhTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,14 +36,14 @@ public class HttpPrologueParsingJmhTest {
3636

3737
@Benchmark
3838
public void techEmpower(Blackhole bh) {
39-
HttpPrologue prologue = new Http1Prologue(new DataReader(() -> TECHEMPOWER_PROLOGUE), 1024, false)
39+
HttpPrologue prologue = new Http1Prologue(DataReader.create(() -> TECHEMPOWER_PROLOGUE), 1024, false)
4040
.readPrologue();
4141
bh.consume(prologue);
4242
}
4343

4444
@Benchmark
4545
public void encoded(Blackhole bh) {
46-
HttpPrologue prologue = new Http1Prologue(new DataReader(() -> ENCODED_PROLOGUE), 1024, false)
46+
HttpPrologue prologue = new Http1Prologue(DataReader.create(() -> ENCODED_PROLOGUE), 1024, false)
4747
.readPrologue();
4848
bh.consume(prologue);
4949
}

tests/benchmark/jmh/src/main/java/io/helidon/webserver/benchmark/jmh/ParsingJmhTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,7 +55,7 @@ public class ParsingJmhTest {
5555

5656
@Benchmark
5757
public void prologue(Blackhole bh) {
58-
DataReader reader = new DataReader(() -> PROLOGUE_WITH_EOL);
58+
DataReader reader = DataReader.create(() -> PROLOGUE_WITH_EOL);
5959
Http1Prologue p = new Http1Prologue(reader, 1024, false);
6060
HttpPrologue httpPrologue = p.readPrologue();
6161
bh.consume(httpPrologue.method());
@@ -66,7 +66,7 @@ public void prologue(Blackhole bh) {
6666

6767
@Benchmark
6868
public void headers(Blackhole bh) {
69-
DataReader reader = new DataReader(() -> HEADERS);
69+
DataReader reader = DataReader.create(() -> HEADERS);
7070
Http1Headers p = new Http1Headers(reader, 1024, false);
7171
WritableHeaders<?> headers = p.readHeaders(PROLOGUE);
7272

webclient/api/src/main/java/io/helidon/webclient/api/TcpClientConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Obtain target socket through proxy (if enabled), or connect to target socket
147147
this.helidonSocket = PlainSocket.client(socket, channelId);
148148
}
149149

150-
this.reader = new DataReader(helidonSocket);
150+
this.reader = DataReader.create(helidonSocket);
151151
int writeBufferSize = webClient.prototype().writeBufferSize();
152152
this.writer = new BufferedDataWriter(helidonSocket, writeBufferSize);
153153

webclient/http1/src/test/java/io/helidon/webclient/http1/Http1ClientTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023 Oracle and/or its affiliates.
2+
* Copyright (c) 2023, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -723,7 +723,7 @@ public void writeNow(BufferData buffer) {
723723
}
724724

725725
private DataReader reader(ArrayBlockingQueue<byte[]> queue) {
726-
return new DataReader(() -> {
726+
return DataReader.create(() -> {
727727
if (serverException != null) {
728728
throw new IllegalStateException("Server exception", serverException);
729729
}

0 commit comments

Comments
 (0)