Skip to content

Commit

Permalink
Fix queries not being able to be repeated (#289)
Browse files Browse the repository at this point in the history
* Fix StreamEntityProducer not able to repeat the production of the content

* Update version
  • Loading branch information
nck-mlcnv authored Oct 29, 2024
1 parent a4f755f commit 78cf54d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<major.minor.version>${major.version}.${minor.version}</major.minor.version>
<major.version>4</major.version>
<minor.version>1</minor.version>
<build.version>0</build.version>
<build.version>1</build.version>

<java.version>17</java.version>
<jena.version>4.2.0</jena.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ public class StreamEntityProducer implements AsyncEntityProducer {
* @param streamSupplier the input stream supplier, should be repeatable
* @param chunked whether the entity data should be sent in chunks
*/
public StreamEntityProducer(Supplier<InputStream> streamSupplier, boolean chunked, String contentType) throws IOException {
public StreamEntityProducer(Supplier<InputStream> streamSupplier, boolean chunked, String contentType) {
this.streamSupplier = streamSupplier;
this.chunked = chunked;
this.contentType = contentType;
if (!chunked) {
content = (streamSupplier.get() instanceof ByteArrayListInputStream) ? (ByteArrayListInputStream) streamSupplier.get() : null;
}
if (!chunked) loadContent();
}

@Override
Expand Down Expand Up @@ -132,7 +130,8 @@ public int available() {
@Override
public void produce(DataStreamChannel channel) throws IOException {
// handling of non-chunked request
if (content != null) {
if (!chunked) {
if (content == null) loadContent(); // might be necessary if the producer is reused
ByteBuffer buffer = content.getCurrentBuffer();
while (channel.write(buffer) > 0) {
if (!buffer.hasRemaining()) {
Expand All @@ -148,7 +147,7 @@ public void produce(DataStreamChannel channel) throws IOException {
}

// handling of chunked request
if (chunked && currentStream == null) {
if (currentStream == null) {
currentStream = streamSupplier.get();
}

Expand All @@ -162,4 +161,8 @@ public void produce(DataStreamChannel channel) throws IOException {
channel.endStream();
}
}

private void loadContent() {
content = (ByteArrayListInputStream) streamSupplier.get();
}
}

0 comments on commit 78cf54d

Please sign in to comment.