aboutsummaryrefslogtreecommitdiff
path: root/other/java/examples/src
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2021-02-09 11:37:07 -0800
committerChris Lu <chris.lu@gmail.com>2021-02-09 11:37:07 -0800
commit821c46edf10097200b986bd17dc01d3991cf57ff (patch)
treeca181a9ef3c2f7e45cf0dbb40373b87717a9a636 /other/java/examples/src
parent15da5834e1a33d060924740ba195f6bcd79f2af2 (diff)
parenta6e8d606b47e5f3e8cd8a57d2769d6f1404fbc8f (diff)
downloadseaweedfs-821c46edf10097200b986bd17dc01d3991cf57ff.tar.xz
seaweedfs-821c46edf10097200b986bd17dc01d3991cf57ff.zip
Merge branch 'master' into support_ssd_volume
Diffstat (limited to 'other/java/examples/src')
-rw-r--r--other/java/examples/src/main/java/com/seaweedfs/examples/ExampleReadFile.java (renamed from other/java/examples/src/main/java/com/seaweedfs/examples/UnzipFile.java)14
-rw-r--r--other/java/examples/src/main/java/com/seaweedfs/examples/ExampleWatchFileChanges.java (renamed from other/java/examples/src/main/java/com/seaweedfs/examples/WatchFiles.java)2
-rw-r--r--other/java/examples/src/main/java/com/seaweedfs/examples/ExampleWriteFile.java47
-rw-r--r--other/java/examples/src/main/java/com/seaweedfs/examples/HdfsCopyFile.java25
4 files changed, 77 insertions, 11 deletions
diff --git a/other/java/examples/src/main/java/com/seaweedfs/examples/UnzipFile.java b/other/java/examples/src/main/java/com/seaweedfs/examples/ExampleReadFile.java
index 0529a5c73..d2eb94135 100644
--- a/other/java/examples/src/main/java/com/seaweedfs/examples/UnzipFile.java
+++ b/other/java/examples/src/main/java/com/seaweedfs/examples/ExampleReadFile.java
@@ -1,8 +1,7 @@
package com.seaweedfs.examples;
-import seaweed.hdfs.SeaweedInputStream;
import seaweedfs.client.FilerClient;
-import seaweedfs.client.FilerGrpcClient;
+import seaweedfs.client.SeaweedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
@@ -10,12 +9,11 @@ import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
-public class UnzipFile {
+public class ExampleReadFile {
public static void main(String[] args) throws IOException {
- FilerGrpcClient filerGrpcClient = new FilerGrpcClient("localhost", 18888);
- FilerClient filerClient = new FilerClient(filerGrpcClient);
+ FilerClient filerClient = new FilerClient("localhost", 18888);
long startTime = System.currentTimeMillis();
parseZip("/Users/chris/tmp/test.zip");
@@ -25,11 +23,7 @@ public class UnzipFile {
long localProcessTime = startTime2 - startTime;
SeaweedInputStream seaweedInputStream = new SeaweedInputStream(
- filerGrpcClient,
- new org.apache.hadoop.fs.FileSystem.Statistics(""),
- "/",
- filerClient.lookupEntry("/", "test.zip")
- );
+ filerClient, "/test.zip");
parseZip(seaweedInputStream);
long swProcessTime = System.currentTimeMillis() - startTime2;
diff --git a/other/java/examples/src/main/java/com/seaweedfs/examples/WatchFiles.java b/other/java/examples/src/main/java/com/seaweedfs/examples/ExampleWatchFileChanges.java
index e489cb3b1..72c572d31 100644
--- a/other/java/examples/src/main/java/com/seaweedfs/examples/WatchFiles.java
+++ b/other/java/examples/src/main/java/com/seaweedfs/examples/ExampleWatchFileChanges.java
@@ -7,7 +7,7 @@ import java.io.IOException;
import java.util.Date;
import java.util.Iterator;
-public class WatchFiles {
+public class ExampleWatchFileChanges {
public static void main(String[] args) throws IOException {
diff --git a/other/java/examples/src/main/java/com/seaweedfs/examples/ExampleWriteFile.java b/other/java/examples/src/main/java/com/seaweedfs/examples/ExampleWriteFile.java
new file mode 100644
index 000000000..26b74028f
--- /dev/null
+++ b/other/java/examples/src/main/java/com/seaweedfs/examples/ExampleWriteFile.java
@@ -0,0 +1,47 @@
+package com.seaweedfs.examples;
+
+import seaweedfs.client.FilerClient;
+import seaweedfs.client.SeaweedInputStream;
+import seaweedfs.client.SeaweedOutputStream;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+public class ExampleWriteFile {
+
+ public static void main(String[] args) throws IOException {
+
+ FilerClient filerClient = new FilerClient("localhost", 18888);
+
+ SeaweedInputStream seaweedInputStream = new SeaweedInputStream(filerClient, "/test.zip");
+ unZipFiles(filerClient, seaweedInputStream);
+
+ }
+
+ public static void unZipFiles(FilerClient filerClient, InputStream is) throws IOException {
+ ZipInputStream zin = new ZipInputStream(is);
+ ZipEntry ze;
+ while ((ze = zin.getNextEntry()) != null) {
+
+ String filename = ze.getName();
+ if (filename.indexOf("/") >= 0) {
+ filename = filename.substring(filename.lastIndexOf("/") + 1);
+ }
+ if (filename.length()==0) {
+ continue;
+ }
+
+ SeaweedOutputStream seaweedOutputStream = new SeaweedOutputStream(filerClient, "/test/"+filename);
+ byte[] bytesIn = new byte[16 * 1024];
+ int read = 0;
+ while ((read = zin.read(bytesIn))!=-1) {
+ seaweedOutputStream.write(bytesIn,0,read);
+ }
+ seaweedOutputStream.close();
+
+ System.out.println(ze.getName());
+ }
+ }
+}
diff --git a/other/java/examples/src/main/java/com/seaweedfs/examples/HdfsCopyFile.java b/other/java/examples/src/main/java/com/seaweedfs/examples/HdfsCopyFile.java
new file mode 100644
index 000000000..006c581c9
--- /dev/null
+++ b/other/java/examples/src/main/java/com/seaweedfs/examples/HdfsCopyFile.java
@@ -0,0 +1,25 @@
+package com.seaweedfs.examples;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.io.IOUtils;
+
+import java.io.*;
+
+public class HdfsCopyFile {
+ public static void main(String[] args) throws IOException {
+ Configuration configuration = new Configuration();
+
+ configuration.set("fs.defaultFS", "seaweedfs://localhost:8888");
+ configuration.set("fs.seaweedfs.impl", "seaweed.hdfs.SeaweedFileSystem");
+
+ FileSystem fs = FileSystem.get(configuration);
+ String source = "/Users/chris/tmp/test.zip";
+ String destination = "/buckets/spark/test01.zip";
+ InputStream in = new BufferedInputStream(new FileInputStream(source));
+
+ OutputStream out = fs.create(new Path(destination));
+ IOUtils.copyBytes(in, out, 4096, true);
+ }
+}