aboutsummaryrefslogtreecommitdiff
path: root/other/java/client/src
diff options
context:
space:
mode:
authorjoeslay <54322500+joeslay@users.noreply.github.com>2019-10-14 16:03:40 +0100
committerGitHub <noreply@github.com>2019-10-14 16:03:40 +0100
commitd53aee179b6624b981caa7e702425ec260808be9 (patch)
tree0e641a775fe2ba398283282b9f9a109986e41f58 /other/java/client/src
parentbaa813ee3012d52a4b861cb61a2ef87f94e5b127 (diff)
parent50e885da45a58180eeb0098e5446d252181964fc (diff)
downloadseaweedfs-d53aee179b6624b981caa7e702425ec260808be9.tar.xz
seaweedfs-d53aee179b6624b981caa7e702425ec260808be9.zip
Merge pull request #10 from chrislusf/master
merge seaweed master
Diffstat (limited to 'other/java/client/src')
-rw-r--r--other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java23
-rw-r--r--other/java/client/src/main/java/seaweedfs/client/SeaweedWrite.java12
-rw-r--r--other/java/client/src/test/java/seaweedfs/client/SeaweedFilerTest.java4
3 files changed, 21 insertions, 18 deletions
diff --git a/other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java b/other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java
index a307983bb..2efa64580 100644
--- a/other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java
+++ b/other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java
@@ -5,16 +5,13 @@ import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.DefaultHttpClient;
+import java.io.Closeable;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
public class SeaweedRead {
@@ -23,7 +20,7 @@ public class SeaweedRead {
// returns bytesRead
public static long read(FilerGrpcClient filerGrpcClient, List<VisibleInterval> visibleIntervals,
final long position, final byte[] buffer, final int bufferOffset,
- final int bufferLength) {
+ final int bufferLength) throws IOException {
List<ChunkView> chunkViews = viewFromVisibles(visibleIntervals, position, bufferLength);
@@ -58,8 +55,8 @@ public class SeaweedRead {
return readCount;
}
- private static int readChunkView(long position, byte[] buffer, int startOffset, ChunkView chunkView, FilerProto.Locations locations) {
- HttpClient client = HttpClientBuilder.create().build();
+ private static int readChunkView(long position, byte[] buffer, int startOffset, ChunkView chunkView, FilerProto.Locations locations) throws IOException {
+ HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(
String.format("http://%s/%s", locations.getLocations(0).getUrl(), chunkView.fileId));
@@ -80,10 +77,12 @@ public class SeaweedRead {
return len;
- } catch (IOException e) {
- e.printStackTrace();
+ } finally {
+ if (client instanceof Closeable) {
+ Closeable t = (Closeable) client;
+ t.close();
+ }
}
- return 0;
}
protected static List<ChunkView> viewFromVisibles(List<VisibleInterval> visibleIntervals, long offset, long size) {
diff --git a/other/java/client/src/main/java/seaweedfs/client/SeaweedWrite.java b/other/java/client/src/main/java/seaweedfs/client/SeaweedWrite.java
index 15db87195..0663e8d98 100644
--- a/other/java/client/src/main/java/seaweedfs/client/SeaweedWrite.java
+++ b/other/java/client/src/main/java/seaweedfs/client/SeaweedWrite.java
@@ -1,13 +1,14 @@
package seaweedfs.client;
import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
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.DefaultHttpClient;
import java.io.ByteArrayInputStream;
+import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
@@ -59,7 +60,7 @@ public class SeaweedWrite {
final byte[] bytes,
final long bytesOffset, final long bytesLength) throws IOException {
- CloseableHttpClient client = HttpClientBuilder.create().setUserAgent("hdfs-client").build();
+ HttpClient client = new DefaultHttpClient();
InputStream inputStream = new ByteArrayInputStream(bytes, (int) bytesOffset, (int) bytesLength);
@@ -84,7 +85,10 @@ public class SeaweedWrite {
return etag;
} finally {
- client.close();
+ if (client instanceof Closeable) {
+ Closeable t = (Closeable) client;
+ t.close();
+ }
}
}
diff --git a/other/java/client/src/test/java/seaweedfs/client/SeaweedFilerTest.java b/other/java/client/src/test/java/seaweedfs/client/SeaweedFilerTest.java
index 87165af0c..eaf17e5c6 100644
--- a/other/java/client/src/test/java/seaweedfs/client/SeaweedFilerTest.java
+++ b/other/java/client/src/test/java/seaweedfs/client/SeaweedFilerTest.java
@@ -16,8 +16,8 @@ public class SeaweedFilerTest {
filerClient.mkdirs("/new_folder", 0755);
filerClient.touch("/new_folder/new_empty_file", 0755);
filerClient.touch("/new_folder/new_empty_file2", 0755);
- filerClient.rm("/new_folder/new_empty_file", false);
- filerClient.rm("/new_folder", true);
+ filerClient.rm("/new_folder/new_empty_file", false, true);
+ filerClient.rm("/new_folder", true, true);
}
}