mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-10-22 05:08:51 +08:00
HDFS: read gzip content
This commit is contained in:
@@ -2,6 +2,7 @@ package seaweedfs.client;
|
|||||||
|
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpHeaders;
|
import org.apache.http.HttpHeaders;
|
||||||
|
import org.apache.http.client.entity.GzipDecompressingEntity;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
@@ -78,7 +79,7 @@ public class SeaweedRead {
|
|||||||
HttpGet request = new HttpGet(
|
HttpGet request = new HttpGet(
|
||||||
String.format("http://%s/%s", locations.getLocations(0).getUrl(), chunkView.fileId));
|
String.format("http://%s/%s", locations.getLocations(0).getUrl(), chunkView.fileId));
|
||||||
|
|
||||||
request.setHeader(HttpHeaders.ACCEPT_ENCODING, "");
|
request.setHeader(HttpHeaders.ACCEPT_ENCODING, "gzip");
|
||||||
|
|
||||||
byte[] data = null;
|
byte[] data = null;
|
||||||
|
|
||||||
@@ -87,6 +88,18 @@ public class SeaweedRead {
|
|||||||
try {
|
try {
|
||||||
HttpEntity entity = response.getEntity();
|
HttpEntity entity = response.getEntity();
|
||||||
|
|
||||||
|
Header contentEncodingHeader = entity.getContentEncoding();
|
||||||
|
|
||||||
|
if (contentEncodingHeader != null) {
|
||||||
|
HeaderElement[] encodings =contentEncodingHeader.getElements();
|
||||||
|
for (int i = 0; i < encodings.length; i++) {
|
||||||
|
if (encodings[i].getName().equalsIgnoreCase("gzip")) {
|
||||||
|
entity = new GzipDecompressingEntity(entity);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
data = EntityUtils.toByteArray(entity);
|
data = EntityUtils.toByteArray(entity);
|
||||||
|
|
||||||
EntityUtils.consume(entity);
|
EntityUtils.consume(entity);
|
||||||
@@ -96,10 +109,6 @@ public class SeaweedRead {
|
|||||||
request.releaseConnection();
|
request.releaseConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chunkView.isCompressed) {
|
|
||||||
// data = Gzip.decompress(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chunkView.cipherKey != null && chunkView.cipherKey.length != 0) {
|
if (chunkView.cipherKey != null && chunkView.cipherKey.length != 0) {
|
||||||
try {
|
try {
|
||||||
data = SeaweedCipher.decrypt(data, chunkView.cipherKey);
|
data = SeaweedCipher.decrypt(data, chunkView.cipherKey);
|
||||||
|
Reference in New Issue
Block a user