aboutsummaryrefslogtreecommitdiff
path: root/other/java/examples
diff options
context:
space:
mode:
authorKonstantin Lebedev <lebedev_k@tochka.com>2020-11-19 18:16:44 +0500
committerKonstantin Lebedev <lebedev_k@tochka.com>2020-11-19 18:16:44 +0500
commit27e73de7975ff9f097bbfd8d2717aa27931f25b5 (patch)
tree802f8cf0f7cc6834e03a24700a8d07a218f5bd86 /other/java/examples
parente1190b3224638616cf4e1318ddcba0b1575f2130 (diff)
parentda04bb3d1bb60d92fdacfb2edd8c8bdba2643038 (diff)
downloadseaweedfs-27e73de7975ff9f097bbfd8d2717aa27931f25b5.tar.xz
seaweedfs-27e73de7975ff9f097bbfd8d2717aa27931f25b5.zip
Merge branch 'upstream_master' into store_s3cred
# Conflicts: # weed/s3api/filer_util.go
Diffstat (limited to 'other/java/examples')
-rw-r--r--other/java/examples/pom.xml32
-rw-r--r--other/java/examples/src/main/java/com/seaweedfs/examples/UnzipFile.java54
-rw-r--r--other/java/examples/src/main/java/com/seaweedfs/examples/WatchFiles.java46
3 files changed, 132 insertions, 0 deletions
diff --git a/other/java/examples/pom.xml b/other/java/examples/pom.xml
new file mode 100644
index 000000000..f7c48d0ab
--- /dev/null
+++ b/other/java/examples/pom.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.example</groupId>
+ <artifactId>unzip</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <dependencies>
+ <dependency>
+ <groupId>com.github.chrislusf</groupId>
+ <artifactId>seaweedfs-client</artifactId>
+ <version>1.5.6</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.github.chrislusf</groupId>
+ <artifactId>seaweedfs-hadoop2-client</artifactId>
+ <version>1.5.6</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-common</artifactId>
+ <version>2.9.2</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+
+</project> \ No newline at end of file
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
new file mode 100644
index 000000000..0529a5c73
--- /dev/null
+++ b/other/java/examples/src/main/java/com/seaweedfs/examples/UnzipFile.java
@@ -0,0 +1,54 @@
+package com.seaweedfs.examples;
+
+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 UnzipFile {
+
+ public static void main(String[] args) throws IOException {
+
+ FilerGrpcClient filerGrpcClient = new FilerGrpcClient("localhost", 18888);
+ FilerClient filerClient = new FilerClient(filerGrpcClient);
+
+ long startTime = System.currentTimeMillis();
+ parseZip("/Users/chris/tmp/test.zip");
+
+ long startTime2 = System.currentTimeMillis();
+
+ long localProcessTime = startTime2 - startTime;
+
+ SeaweedInputStream seaweedInputStream = new SeaweedInputStream(
+ filerGrpcClient,
+ new org.apache.hadoop.fs.FileSystem.Statistics(""),
+ "/",
+ filerClient.lookupEntry("/", "test.zip")
+ );
+ parseZip(seaweedInputStream);
+
+ long swProcessTime = System.currentTimeMillis() - startTime2;
+
+ System.out.println("Local time: " + localProcessTime);
+ System.out.println("SeaweedFS time: " + swProcessTime);
+
+ }
+
+ 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());
+ }
+ }
+}
diff --git a/other/java/examples/src/main/java/com/seaweedfs/examples/WatchFiles.java b/other/java/examples/src/main/java/com/seaweedfs/examples/WatchFiles.java
new file mode 100644
index 000000000..e489cb3b1
--- /dev/null
+++ b/other/java/examples/src/main/java/com/seaweedfs/examples/WatchFiles.java
@@ -0,0 +1,46 @@
+package com.seaweedfs.examples;
+
+import seaweedfs.client.FilerClient;
+import seaweedfs.client.FilerProto;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.Iterator;
+
+public class WatchFiles {
+
+ public static void main(String[] args) throws IOException {
+
+ FilerClient filerClient = new FilerClient("localhost", 18888);
+
+ long sinceNs = (System.currentTimeMillis() - 3600 * 1000) * 1000000L;
+
+ Iterator<FilerProto.SubscribeMetadataResponse> watch = filerClient.watch(
+ "/buckets",
+ "exampleClientName",
+ sinceNs
+ );
+
+ System.out.println("Connected to filer, subscribing from " + new Date());
+
+ while (watch.hasNext()) {
+ FilerProto.SubscribeMetadataResponse event = watch.next();
+ FilerProto.EventNotification notification = event.getEventNotification();
+ if (!event.getDirectory().equals(notification.getNewParentPath())) {
+ // move an entry to a new directory, possibly with a new name
+ if (notification.hasOldEntry() && notification.hasNewEntry()) {
+ System.out.println("moved " + event.getDirectory() + "/" + notification.getOldEntry().getName() + " to " + notification.getNewParentPath() + "/" + notification.getNewEntry().getName());
+ } else {
+ System.out.println("this should not happen.");
+ }
+ } else if (notification.hasNewEntry() && !notification.hasOldEntry()) {
+ System.out.println("created entry " + event.getDirectory() + "/" + notification.getNewEntry().getName());
+ } else if (!notification.hasNewEntry() && notification.hasOldEntry()) {
+ System.out.println("deleted entry " + event.getDirectory() + "/" + notification.getOldEntry().getName());
+ } else if (notification.hasNewEntry() && notification.hasOldEntry()) {
+ System.out.println("updated entry " + event.getDirectory() + "/" + notification.getNewEntry().getName());
+ }
+ }
+
+ }
+}