|
@ -3,10 +3,10 @@ package seaweedfs.client; |
|
|
import com.google.protobuf.ByteString; |
|
|
import com.google.protobuf.ByteString; |
|
|
import org.apache.http.HttpResponse; |
|
|
import org.apache.http.HttpResponse; |
|
|
import org.apache.http.client.HttpClient; |
|
|
import org.apache.http.client.HttpClient; |
|
|
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse; |
|
|
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.HttpClientBuilder; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
import java.io.ByteArrayInputStream; |
|
|
import java.io.Closeable; |
|
|
import java.io.Closeable; |
|
@ -16,7 +16,7 @@ import java.security.SecureRandom; |
|
|
|
|
|
|
|
|
public class SeaweedWrite { |
|
|
public class SeaweedWrite { |
|
|
|
|
|
|
|
|
private static SecureRandom random = new SecureRandom(); |
|
|
private static final SecureRandom random = new SecureRandom(); |
|
|
|
|
|
|
|
|
public static void writeData(FilerProto.Entry.Builder entry, |
|
|
public static void writeData(FilerProto.Entry.Builder entry, |
|
|
final String replication, |
|
|
final String replication, |
|
@ -79,8 +79,6 @@ public class SeaweedWrite { |
|
|
final long bytesOffset, final long bytesLength, |
|
|
final long bytesOffset, final long bytesLength, |
|
|
byte[] cipherKey) throws IOException { |
|
|
byte[] cipherKey) throws IOException { |
|
|
|
|
|
|
|
|
HttpClient client = HttpClientBuilder.create().build(); |
|
|
|
|
|
|
|
|
|
|
|
InputStream inputStream = null; |
|
|
InputStream inputStream = null; |
|
|
if (cipherKey == null || cipherKey.length == 0) { |
|
|
if (cipherKey == null || cipherKey.length == 0) { |
|
|
inputStream = new ByteArrayInputStream(bytes, (int) bytesOffset, (int) bytesLength); |
|
|
inputStream = new ByteArrayInputStream(bytes, (int) bytesOffset, (int) bytesLength); |
|
@ -103,8 +101,9 @@ public class SeaweedWrite { |
|
|
.addBinaryBody("upload", inputStream) |
|
|
.addBinaryBody("upload", inputStream) |
|
|
.build()); |
|
|
.build()); |
|
|
|
|
|
|
|
|
|
|
|
CloseableHttpResponse response = SeaweedUtil.getClosableHttpClient().execute(post); |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
HttpResponse response = client.execute(post); |
|
|
|
|
|
|
|
|
|
|
|
String etag = response.getLastHeader("ETag").getValue(); |
|
|
String etag = response.getLastHeader("ETag").getValue(); |
|
|
|
|
|
|
|
@ -114,10 +113,7 @@ public class SeaweedWrite { |
|
|
|
|
|
|
|
|
return etag; |
|
|
return etag; |
|
|
} finally { |
|
|
} finally { |
|
|
if (client instanceof Closeable) { |
|
|
response.close(); |
|
|
Closeable t = (Closeable) client; |
|
|
|
|
|
t.close(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
xxxxxxxxxx