You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2020/05/16 22:24:53 UTC
[incubator-streampipes-extensions] 01/01: Create adapter structure
and zip file image iterator
This is an automated email from the ASF dual-hosted git repository.
zehnder pushed a commit to branch STREAMPIPES-130
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-extensions.git
commit 8003e942821f8a2856a54b37aea86e951af6511f
Author: Philipp Zehnder <ze...@fzi.de>
AuthorDate: Sun May 17 00:24:01 2020 +0200
Create adapter structure and zip file image iterator
---
.../adapters/image/ZipFileImageIterator.java | 83 +++++++++++++++
.../adapters/image/set/ImageSetAdapter.java | 20 ++++
.../adapters/image/stream/ImageStreamAdapter.java | 114 +++++++++++++++++++++
.../documentation.md | 33 ++++++
.../icon.png | Bin 0 -> 42675 bytes
.../strings.en | 8 ++
6 files changed, 258 insertions(+)
diff --git a/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/image/ZipFileImageIterator.java b/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/image/ZipFileImageIterator.java
new file mode 100644
index 0000000..a424300
--- /dev/null
+++ b/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/image/ZipFileImageIterator.java
@@ -0,0 +1,83 @@
+/*
+Copyright 2020 FZI Forschungszentrum Informatik
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package org.apache.streampipes.connect.adapters.image;
+
+import org.apache.commons.io.IOUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Base64;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+public class ZipFileImageIterator {
+ private ZipFile zipFile;
+ private List<ZipEntry> allImages;
+ private int current;
+
+ public ZipFileImageIterator(String zipFileRoute) throws IOException {
+ this.zipFile = new ZipFile(zipFileRoute);
+
+ Enumeration<? extends ZipEntry> entries = zipFile.entries();
+
+ this.allImages = new ArrayList<>();
+
+ while(entries.hasMoreElements()){
+ ZipEntry entry = entries.nextElement();
+ if (isImage(entry.getName())){
+ allImages.add(entry);
+ }
+ }
+ current = 0;
+
+ }
+
+ public boolean hasNext() {
+ return current < this.allImages.size();
+ }
+
+ public String next() throws IOException {
+ ZipEntry entry = allImages.get(current);
+ InputStream stream = zipFile.getInputStream(entry);
+ byte[] bytes = IOUtils.toByteArray(stream);
+
+ current++;
+ String resultImage = Base64.getEncoder().encodeToString(bytes);
+ return entry.getName();
+ }
+
+ public static void main(String... args) throws IOException {
+ String route = "";
+ ZipFileImageIterator zipFileImageIterator = new ZipFileImageIterator(route);
+
+ while (zipFileImageIterator.hasNext()) {
+ System.out.println(zipFileImageIterator.next());
+ }
+
+ }
+
+ private static boolean isImage(String name) {
+ return (!name.startsWith("_")) &&
+ (name.toLowerCase().endsWith(".png") ||
+ name.toLowerCase().endsWith(".jpg") ||
+ name.toLowerCase().endsWith(".jpeg"));
+
+ }
+}
diff --git a/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/image/set/ImageSetAdapter.java b/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/image/set/ImageSetAdapter.java
new file mode 100644
index 0000000..76c5f52
--- /dev/null
+++ b/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/image/set/ImageSetAdapter.java
@@ -0,0 +1,20 @@
+/*
+Copyright 2020 FZI Forschungszentrum Informatik
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package org.apache.streampipes.connect.adapters.image.set;
+
+public class ImageSetAdapter {
+}
diff --git a/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/image/stream/ImageStreamAdapter.java b/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/image/stream/ImageStreamAdapter.java
new file mode 100644
index 0000000..f365e8a
--- /dev/null
+++ b/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/image/stream/ImageStreamAdapter.java
@@ -0,0 +1,114 @@
+/*
+Copyright 2020 FZI Forschungszentrum Informatik
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package org.apache.streampipes.connect.adapters.image.stream;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.streampipes.connect.adapter.Adapter;
+import org.apache.streampipes.connect.adapter.exception.AdapterException;
+import org.apache.streampipes.connect.adapter.exception.ParseException;
+import org.apache.streampipes.connect.adapter.model.specific.SpecificDataStreamAdapter;
+import org.apache.streampipes.connect.adapters.iss.IssAdapter;
+import org.apache.streampipes.model.AdapterType;
+import org.apache.streampipes.model.connect.adapter.SpecificAdapterStreamDescription;
+import org.apache.streampipes.model.connect.guess.GuessSchema;
+import org.apache.streampipes.model.staticproperty.FileStaticProperty;
+import org.apache.streampipes.sdk.builder.adapter.GuessSchemaBuilder;
+import org.apache.streampipes.sdk.builder.adapter.SpecificDataStreamAdapterBuilder;
+import org.apache.streampipes.sdk.extractor.StaticPropertyExtractor;
+import org.apache.streampipes.sdk.helpers.Labels;
+import org.apache.streampipes.sdk.helpers.Locales;
+import org.apache.streampipes.sdk.utils.Assets;
+import org.apache.streampipes.vocabulary.Geo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.*;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import static org.apache.streampipes.sdk.helpers.EpProperties.*;
+
+public class ImageStreamAdapter extends SpecificDataStreamAdapter {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ImageStreamAdapter.class);
+
+ public static final String ID = "org.apache.streampipes.connect.adapters.image.stream";
+
+ private static final String INTERVAL_KEY = "interval-key";
+ private static final String ZIP_FILE_KEY = "zip-file-key";
+
+ private static final String Timestamp = "timestamp";
+ private static final String Image = "image";
+
+ public ImageStreamAdapter() {
+
+ }
+
+ public ImageStreamAdapter(SpecificAdapterStreamDescription adapterDescription) {
+ super(adapterDescription);
+ }
+
+ @Override
+ public SpecificAdapterStreamDescription declareModel() {
+ SpecificAdapterStreamDescription description = SpecificDataStreamAdapterBuilder.create(ID)
+ .withLocales(Locales.EN)
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .requiredIntegerParameter(Labels.withId(INTERVAL_KEY))
+ .requiredFile(Labels.withId(ZIP_FILE_KEY))
+ .build();
+ description.setAppId(ID);
+
+ return description;
+ }
+
+ @Override
+ public void startAdapter() throws AdapterException {
+ StaticPropertyExtractor extractor =
+ StaticPropertyExtractor.from(adapterDescription.getConfig(), new ArrayList<>());
+ FileStaticProperty fileStaticProperty = (FileStaticProperty) extractor.getStaticPropertyByName(ZIP_FILE_KEY);
+
+ String fileUri = fileStaticProperty.getLocationPath();
+
+ }
+
+
+
+ @Override
+ public void stopAdapter() throws AdapterException {
+
+ }
+
+ @Override
+ public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription) throws AdapterException, ParseException {
+ return GuessSchemaBuilder.create()
+ .property(timestampProperty(Timestamp))
+ .property(imageProperty("image"))
+ .build();
+ }
+
+ @Override
+ public Adapter getInstance(SpecificAdapterStreamDescription adapterDescription) {
+ return new ImageStreamAdapter(adapterDescription);
+ }
+
+ @Override
+ public String getId() {
+ return ID;
+ }
+}
diff --git a/streampipes-connect-adapters/src/main/resources/org.apache.streampipes.connect.adapters.image.stream/documentation.md b/streampipes-connect-adapters/src/main/resources/org.apache.streampipes.connect.adapters.image.stream/documentation.md
new file mode 100644
index 0000000..c3da505
--- /dev/null
+++ b/streampipes-connect-adapters/src/main/resources/org.apache.streampipes.connect.adapters.image.stream/documentation.md
@@ -0,0 +1,33 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ ~
+ -->
+
+## ISS Adapter
+
+<p align="center">
+ <img src="icon.png" width="150px;" class="pe-image-documentation"/>
+</p>
+
+***
+
+## Description
+
+Shows the live position of the International Space Station (ISS), updated every two seconds.
+
+
+***
+
diff --git a/streampipes-connect-adapters/src/main/resources/org.apache.streampipes.connect.adapters.image.stream/icon.png b/streampipes-connect-adapters/src/main/resources/org.apache.streampipes.connect.adapters.image.stream/icon.png
new file mode 100644
index 0000000..e4d1008
Binary files /dev/null and b/streampipes-connect-adapters/src/main/resources/org.apache.streampipes.connect.adapters.image.stream/icon.png differ
diff --git a/streampipes-connect-adapters/src/main/resources/org.apache.streampipes.connect.adapters.image.stream/strings.en b/streampipes-connect-adapters/src/main/resources/org.apache.streampipes.connect.adapters.image.stream/strings.en
new file mode 100644
index 0000000..51a5873
--- /dev/null
+++ b/streampipes-connect-adapters/src/main/resources/org.apache.streampipes.connect.adapters.image.stream/strings.en
@@ -0,0 +1,8 @@
+org.apache.streampipes.connect.adapters.image.stream.title=Image Upload (Stream)
+org.apache.streampipes.connect.adapters.image.stream.description=
+
+interval-key.title=Interval [ms]
+interval-key.description=Define waiting time between the images
+
+zip-file-key.title=Zipped Folder With Images
+zip-file-key.description=A zip file that contains the images to stream