diff options
| author | Chris Lu <chris.lu@gmail.com> | 2021-02-04 20:16:08 -0800 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2021-02-04 20:16:08 -0800 |
| commit | 7f90d14f100f9ce69b6b05f6b8f80823f4c69fdf (patch) | |
| tree | f6438e29b855636594ad1add4887bf46a42bbf2f /other/java/examples/src | |
| parent | 502554887f58915c077462372db4e2813eac3f92 (diff) | |
| download | seaweedfs-7f90d14f100f9ce69b6b05f6b8f80823f4c69fdf.tar.xz seaweedfs-7f90d14f100f9ce69b6b05f6b8f80823f4c69fdf.zip | |
Java: add SeaweedOutputStream example
Diffstat (limited to 'other/java/examples/src')
| -rw-r--r-- | other/java/examples/src/main/java/com/seaweedfs/examples/UnzipFile.java | 2 | ||||
| -rw-r--r-- | other/java/examples/src/main/java/com/seaweedfs/examples/WriteFile.java | 48 |
2 files changed, 49 insertions, 1 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/UnzipFile.java index fad1471b6..12eab1a2c 100644 --- a/other/java/examples/src/main/java/com/seaweedfs/examples/UnzipFile.java +++ b/other/java/examples/src/main/java/com/seaweedfs/examples/UnzipFile.java @@ -23,7 +23,7 @@ public class UnzipFile { long localProcessTime = startTime2 - startTime; SeaweedInputStream seaweedInputStream = new SeaweedInputStream( - filerGrpcClient, "/", "test.zip"); + filerGrpcClient, "/test.zip"); parseZip(seaweedInputStream); long swProcessTime = System.currentTimeMillis() - startTime2; diff --git a/other/java/examples/src/main/java/com/seaweedfs/examples/WriteFile.java b/other/java/examples/src/main/java/com/seaweedfs/examples/WriteFile.java new file mode 100644 index 000000000..b0bd54997 --- /dev/null +++ b/other/java/examples/src/main/java/com/seaweedfs/examples/WriteFile.java @@ -0,0 +1,48 @@ +package com.seaweedfs.examples; + +import seaweedfs.client.FilerGrpcClient; +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 WriteFile { + + public static void main(String[] args) throws IOException { + + FilerGrpcClient filerGrpcClient = new FilerGrpcClient("localhost", 18888); + + SeaweedInputStream seaweedInputStream = new SeaweedInputStream( + filerGrpcClient, "/test.zip"); + unZipFiles(filerGrpcClient, seaweedInputStream); + + } + + public static void unZipFiles(FilerGrpcClient filerGrpcClient, 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(filerGrpcClient, "/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()); + } + } +} |
