tpalfy commented on a change in pull request #4577:
URL: https://github.com/apache/nifi/pull/4577#discussion_r581148769



##########
File path: 
nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/ExampleDataGenerator.java
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.
+ */
+package org.apache.nifi.jasn1;
+
+import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream;
+import com.beanit.asn1bean.ber.types.BerBoolean;
+import com.beanit.asn1bean.ber.types.BerInteger;
+import com.beanit.asn1bean.ber.types.BerOctetString;
+import com.beanit.asn1bean.ber.types.string.BerUTF8String;
+import org.apache.nifi.jasn1.example.BasicTypeSet;
+import org.apache.nifi.jasn1.example.BasicTypes;
+import org.apache.nifi.jasn1.example.Composite;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+/**
+ * Depends on generated test classes
+ */
+public class ExampleDataGenerator {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(ExampleDataGenerator.class);
+
+    public static void main(String[] args) throws Exception {
+
+        final File asnFile = new 
File(ExampleDataGenerator.class.getResource("/example.asn").getFile());
+        final File dir = new 
File(asnFile.getParentFile().getParentFile().getParentFile(), 
"src/test/resources/examples");
+
+        generateBasicTypes(dir);
+
+        generateComposite(dir);
+    }
+
+    private static void generateBasicTypes(File dir) throws IOException {
+        final File file = new File(dir, "basic-types.dat");
+        try (final ReverseByteArrayOutputStream rev = new 
ReverseByteArrayOutputStream(1024);
+             final OutputStream out = new FileOutputStream(file)) {
+            final BasicTypes basicTypes = new BasicTypes();
+            basicTypes.setB(new BerBoolean(true));
+            basicTypes.setI(new BerInteger(789));
+            basicTypes.setOctStr(new BerOctetString(new byte[]{1, 2, 3, 4, 
5}));
+            basicTypes.setUtf8Str(new BerUTF8String("Some UTF-8 String. 
こんにちは世界。"));
+            final int encoded = basicTypes.encode(rev);
+            out.write(rev.getArray(), 0, encoded);
+            LOG.info("Generated {} bytes to {}", encoded, file);
+        }
+    }
+
+    private static void generateComposite(File dir) throws IOException {
+        final File file = new File(dir, "composite.dat");

Review comment:
       The template uses `ForkRecord` for the composite data. It seems that 
`ForkRecord` doesn't work. Not sure what exactly the issue is but I think it 
might have something to do with the fact that no matter the settings it uses 
the original schema when writing the extracted records. Not sure if the record 
writer logic has changed at some point or this processor never worked properly, 
at least with certain setup & input.
   
   In any case, this doesn't seem to be related to the ASN.1 functionality. 
I'll replace that processor with a different one in the template.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to