streamlet-examples/JarInfo.java
branchv_0
changeset 72 f7b9db6fc32b
child 73 1a067a217454
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/streamlet-examples/JarInfo.java	Wed Jan 29 18:05:13 2020 +0100
@@ -0,0 +1,51 @@
+
+/**
+ * Relational pipes
+ * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+import java.io.File;
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.jar.JarFile;
+
+public class JarInfo extends Streamlet {
+
+	public static void main(String[] args) throws IOException {
+		JarInfo s = new JarInfo();
+		int status = s.run();
+		System.exit(status);
+
+		// TODO: return real values:
+		JarFile jar = new JarFile(new File(args[0]));
+		String mainClass = jar.getManifest() == null ? null : jar.getManifest().getMainAttributes().getValue("Main-Class");
+		System.out.println("Name:       " + jar.getName());
+		System.out.println("Comment:    " + jar.getComment());
+		System.out.println("Entries:    " + jar.stream().count());
+		System.out.println("Main class: " + mainClass);
+	}
+
+	protected List<Streamlet.AttributeMetadata> getOutputAttributesMetadata() {
+		List<Streamlet.AttributeMetadata> result = new LinkedList<>();
+		result.add(new Streamlet.AttributeMetadata("main_class", Streamlet.Type.STRING));
+		return result;
+	}
+
+	protected List<Object> getOutputAttributes() {
+		List<Object> result = new LinkedList<>();
+		result.add("TODO: main class");
+		return result;
+	}
+}