garydgregory commented on code in PR #681:
URL: 
https://github.com/apache/httpcomponents-client/pull/681#discussion_r2227658081


##########
httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/GzipDecompressingStringAsyncEntityConsumer.java:
##########
@@ -0,0 +1,334 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.client5.http.async.methods;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.zip.CRC32;
+import java.util.zip.DataFormatException;
+import java.util.zip.Inflater;
+import java.util.zip.ZipException;
+
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.EntityDetails;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.nio.AsyncEntityConsumer;
+import org.apache.hc.core5.http.nio.CapacityChannel;
+
+/**
+ * A GZIP-only {@link AsyncEntityConsumer} that decompresses incrementally 
without buffering the full compressed input.
+ * Parses GZIP header and trailer streaming-style using a state machine. 
Decompressed output is appended to a StringBuilder chunk-by-chunk.
+ * Suitable for modest decompressed payloads.
+ *
+ * @since 5.6
+ */
+public class GzipDecompressingStringAsyncEntityConsumer implements 
AsyncEntityConsumer<String> {
+
+    private final StringBuilder resultBuilder = new StringBuilder();
+    private FutureCallback<String> callback;
+    private List<Header> trailers;
+    private String result;
+    private Inflater inflater;
+    private final byte[] decompressBuffer = new byte[8192];
+    private ContentType contentType;
+
+    private enum GzipState {
+        HEADER_MAGIC1, HEADER_MAGIC2, HEADER_METHOD, HEADER_FLAGS, 
HEADER_MTIME1, HEADER_MTIME2, HEADER_MTIME3, HEADER_MTIME4,
+        HEADER_XFL, HEADER_OS, HEADER_EXTRA_LEN_LO, HEADER_EXTRA_LEN_HI, 
HEADER_EXTRA, HEADER_NAME, HEADER_COMMENT,
+        HEADER_HCRC_LO, HEADER_HCRC_HI, DATA, TRAILER_CRC1, TRAILER_CRC2, 
TRAILER_CRC3, TRAILER_CRC4,
+        TRAILER_ISIZE1, TRAILER_ISIZE2, TRAILER_ISIZE3, TRAILER_ISIZE4, DONE, 
ERROR
+    }
+
+    private GzipState state = GzipState.HEADER_MAGIC1;
+    private int flags = 0;

Review Comment:
   I don't think we should initialize instance variables to default values 
(like in C!), it feels like clutter.



-- 
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.

To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to