Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix queries not being able to be repeated #289

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading