From 559dfacdac0d3851541468b60b9046fe9d9f2b51 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Thu, 12 Nov 2020 23:24:39 -0800 Subject: [PATCH] adding test example --- other/java/unzip/pom.xml | 32 +++++++++++++ .../main/java/com/example/test/Example.java | 46 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 other/java/unzip/pom.xml create mode 100644 other/java/unzip/src/main/java/com/example/test/Example.java diff --git a/other/java/unzip/pom.xml b/other/java/unzip/pom.xml new file mode 100644 index 000000000..1f86bb688 --- /dev/null +++ b/other/java/unzip/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + org.example + unzip + 1.0-SNAPSHOT + + + com.github.chrislusf + seaweedfs-client + 1.5.3 + compile + + + com.github.chrislusf + seaweedfs-hadoop2-client + 1.5.3 + compile + + + org.apache.hadoop + hadoop-common + 2.9.2 + compile + + + + + \ No newline at end of file diff --git a/other/java/unzip/src/main/java/com/example/test/Example.java b/other/java/unzip/src/main/java/com/example/test/Example.java new file mode 100644 index 000000000..393ccb5ab --- /dev/null +++ b/other/java/unzip/src/main/java/com/example/test/Example.java @@ -0,0 +1,46 @@ +package com.example.test; + +import seaweed.hdfs.SeaweedInputStream; +import seaweedfs.client.FilerClient; +import seaweedfs.client.FilerGrpcClient; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +public class Example { + + public static FilerClient filerClient = new FilerClient("localhost", 18888); + public static FilerGrpcClient filerGrpcClient = new FilerGrpcClient("localhost", 18888); + + public static void main(String[] args) throws IOException { + + // 本地模式,速度很快 + parseZip("/Users/chris/tmp/test.zip"); + + // swfs读取,慢 + SeaweedInputStream seaweedInputStream = new SeaweedInputStream( + filerGrpcClient, + new org.apache.hadoop.fs.FileSystem.Statistics(""), + "/", + filerClient.lookupEntry("/", "test.zip") + ); + parseZip(seaweedInputStream); + + } + + public static void parseZip(String filename) throws IOException { + FileInputStream fileInputStream = new FileInputStream(filename); + parseZip(fileInputStream); + } + + public static void parseZip(InputStream is) throws IOException { + ZipInputStream zin = new ZipInputStream(is); + ZipEntry ze; + while ((ze = zin.getNextEntry()) != null) { + System.out.println(ze.getName()); + } + } +}