You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by GitBox <gi...@apache.org> on 2019/11/10 18:30:54 UTC

[GitHub] [jena] afs commented on a change in pull request #628: JENA-1776: Set Content-Length when sending a graph or dataset

afs commented on a change in pull request #628: JENA-1776: Set Content-Length when sending a graph or dataset
URL: https://github.com/apache/jena/pull/628#discussion_r344507199
 
 

 ##########
 File path: jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionRemote.java
 ##########
 @@ -492,8 +495,33 @@ protected HttpEntity graphToHttpEntity(Graph graph) {
         return graphToHttpEntity(graph, outputTriples);
     }
 
-    /** Create an HttpEntity for the graph */
+    /** Create an HttpEntity for the graph. */
     protected HttpEntity graphToHttpEntity(Graph graph, RDFFormat syntax) {
+        // Length - leaves connection reusable. 
+        return graphToHttpEntityWithLength(graph, syntax);
+    }
+    
+    /** 
+     * Create an HttpEntity for the graph. The HTTP entity will have the length but this
+     * requires serialising the graph at the point when this function is called.  
+     */
+    private HttpEntity graphToHttpEntityWithLength(Graph graph, RDFFormat syntax) {
+        String ct = syntax.getLang().getContentType().getContentType();
+        ByteArrayOutputStream out = new ByteArrayOutputStream(128*1024);
 
 Review comment:
   Needs to pass the ByteArrayOutputStream out of the "try" scope and until Java9 you can't write `try (out) {}` so it's a bit yukky.
   
   And I added the "IO.close" for neatness as it is not really needed.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services