chatman commented on a change in pull request #929: SOLR-13821: Package Store 
for storing package artefacts
URL: https://github.com/apache/lucene-solr/pull/929#discussion_r331950231
 
 

 ##########
 File path: solr/solrj/src/java/org/apache/solr/common/util/Utils.java
 ##########
 @@ -713,4 +717,69 @@ public static String getMDCNode() {
     return def;
   }
 
+  public interface InputStreamConsumer<T> {
+
+    T accept(InputStream is) throws IOException;
+
+  }
+
+  public static final InputStreamConsumer<?> JAVABINCONSUMER = is -> new 
JavaBinCodec().unmarshal(is);
+  public static final InputStreamConsumer<?> JSONCONSUMER = is -> 
Utils.fromJSON(is);
+  public static InputStreamConsumer<ByteBuffer> newBytesConsumer(int maxSize){
+    return is -> {
+      try (BinaryRequestWriter.BAOS bos = new BinaryRequestWriter.BAOS()) {
+        long sz = 0;
+        int next = is.read();
+        while (next > -1) {
+          if (++sz > maxSize) throw new BufferOverflowException();
+          bos.write(next);
+          next = is.read();
+        }
+        bos.flush();
+        return ByteBuffer.wrap( bos.getbuf(), 0, bos.size());
+      } catch (IOException e) {
+        throw new RuntimeException(e);
+      }
+    };
+
+  }
+
+
+
+
+  public static <T> T executeGET(HttpClient client, String url, 
InputStreamConsumer<T> consumer) throws SolrException {
+    T result = null;
+    HttpGet httpGet = new HttpGet(url);
+    HttpResponse rsp = null;
+    try {
+      rsp = client.execute(httpGet);
+    } catch (IOException e) {
+      log.error("Error in request to url : "+ url, e);
+      throw new SolrException(SolrException.ErrorCode.UNKNOWN, "error sending 
request");
+    }
+    int statusCode = rsp.getStatusLine().getStatusCode();
+    if(statusCode != 200) {
+      try {
+        log.error("Failed a request to : {} ,  status :{}  body {}",url, 
rsp.getStatusLine(),  EntityUtils.toString(rsp.getEntity(), 
StandardCharsets.UTF_8));
+      } catch (IOException e) {
+        log.error("could not print error", e);
+      }
+      throw new 
SolrException(SolrException.ErrorCode.getErrorCode(statusCode), "Unknown 
error");
+    }
+    HttpEntity entity = rsp.getEntity();
+    try{
+      InputStream is = entity.getContent();
+      if(consumer != null) {
 
 Review comment:
   Please add space after if and before (.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to