|
@ -2,10 +2,10 @@ package seaweed.hdfs; |
|
|
|
|
|
|
|
|
import org.apache.hadoop.fs.Path; |
|
|
import org.apache.hadoop.fs.Path; |
|
|
import org.apache.http.HttpResponse; |
|
|
import org.apache.http.HttpResponse; |
|
|
import org.apache.http.client.HttpClient; |
|
|
|
|
|
import org.apache.http.client.methods.HttpPost; |
|
|
import org.apache.http.client.methods.HttpPost; |
|
|
import org.apache.http.entity.mime.HttpMultipartMode; |
|
|
import org.apache.http.entity.mime.HttpMultipartMode; |
|
|
import org.apache.http.entity.mime.MultipartEntityBuilder; |
|
|
import org.apache.http.entity.mime.MultipartEntityBuilder; |
|
|
|
|
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
|
import org.apache.http.impl.client.HttpClientBuilder; |
|
|
import org.apache.http.impl.client.HttpClientBuilder; |
|
|
import seaweedfs.client.FilerGrpcClient; |
|
|
import seaweedfs.client.FilerGrpcClient; |
|
|
import seaweedfs.client.FilerProto; |
|
|
import seaweedfs.client.FilerProto; |
|
@ -60,7 +60,7 @@ public class SeaweedWrite { |
|
|
final byte[] bytes, |
|
|
final byte[] bytes, |
|
|
final long bytesOffset, final long bytesLength) throws IOException { |
|
|
final long bytesOffset, final long bytesLength) throws IOException { |
|
|
|
|
|
|
|
|
HttpClient client = HttpClientBuilder.create().setUserAgent("hdfs-client").build(); |
|
|
|
|
|
|
|
|
CloseableHttpClient client = HttpClientBuilder.create().setUserAgent("hdfs-client").build(); |
|
|
|
|
|
|
|
|
InputStream inputStream = new ByteArrayInputStream(bytes, (int) bytesOffset, (int) bytesLength); |
|
|
InputStream inputStream = new ByteArrayInputStream(bytes, (int) bytesOffset, (int) bytesLength); |
|
|
|
|
|
|
|
@ -71,6 +71,7 @@ public class SeaweedWrite { |
|
|
.addBinaryBody("upload", inputStream) |
|
|
.addBinaryBody("upload", inputStream) |
|
|
.build()); |
|
|
.build()); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
HttpResponse response = client.execute(post); |
|
|
HttpResponse response = client.execute(post); |
|
|
|
|
|
|
|
|
String etag = response.getLastHeader("ETag").getValue(); |
|
|
String etag = response.getLastHeader("ETag").getValue(); |
|
@ -80,5 +81,9 @@ public class SeaweedWrite { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return etag; |
|
|
return etag; |
|
|
|
|
|
} finally { |
|
|
|
|
|
client.close(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |