Skip to content

Commit 78cf54d

Browse files
authored
Fix queries not being able to be repeated (#289)
* Fix StreamEntityProducer not able to repeat the production of the content * Update version
1 parent a4f755f commit 78cf54d

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<major.minor.version>${major.version}.${minor.version}</major.minor.version>
3939
<major.version>4</major.version>
4040
<minor.version>1</minor.version>
41-
<build.version>0</build.version>
41+
<build.version>1</build.version>
4242

4343
<java.version>17</java.version>
4444
<jena.version>4.2.0</jena.version>

src/main/java/org/aksw/iguana/cc/utils/http/StreamEntityProducer.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,11 @@ public class StreamEntityProducer implements AsyncEntityProducer {
3939
* @param streamSupplier the input stream supplier, should be repeatable
4040
* @param chunked whether the entity data should be sent in chunks
4141
*/
42-
public StreamEntityProducer(Supplier<InputStream> streamSupplier, boolean chunked, String contentType) throws IOException {
42+
public StreamEntityProducer(Supplier<InputStream> streamSupplier, boolean chunked, String contentType) {
4343
this.streamSupplier = streamSupplier;
4444
this.chunked = chunked;
4545
this.contentType = contentType;
46-
if (!chunked) {
47-
content = (streamSupplier.get() instanceof ByteArrayListInputStream) ? (ByteArrayListInputStream) streamSupplier.get() : null;
48-
}
46+
if (!chunked) loadContent();
4947
}
5048

5149
@Override
@@ -132,7 +130,8 @@ public int available() {
132130
@Override
133131
public void produce(DataStreamChannel channel) throws IOException {
134132
// handling of non-chunked request
135-
if (content != null) {
133+
if (!chunked) {
134+
if (content == null) loadContent(); // might be necessary if the producer is reused
136135
ByteBuffer buffer = content.getCurrentBuffer();
137136
while (channel.write(buffer) > 0) {
138137
if (!buffer.hasRemaining()) {
@@ -148,7 +147,7 @@ public void produce(DataStreamChannel channel) throws IOException {
148147
}
149148

150149
// handling of chunked request
151-
if (chunked && currentStream == null) {
150+
if (currentStream == null) {
152151
currentStream = streamSupplier.get();
153152
}
154153

@@ -162,4 +161,8 @@ public void produce(DataStreamChannel channel) throws IOException {
162161
channel.endStream();
163162
}
164163
}
164+
165+
private void loadContent() {
166+
content = (ByteArrayListInputStream) streamSupplier.get();
167+
}
165168
}

0 commit comments

Comments
 (0)