Github user JPercivall commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1202#discussion_r87520923
--- Diff:
nifi-commons/nifi-schema-utils/src/main/java/org/apache/nifi/repository/schema/RecordSchema.java
---
@@ -0,0 +1,183 @@
+/*
+ * 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.repository.schema;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class RecordSchema {
+ private static final String FIELD_NAME = "Field Name";
+ private static final String FIELD_TYPE = "Field Type";
+ private static final String REPETITION = "Repetition";
+ private static final String SUBFIELDS = "SubFields";
+
+ private static final String STRING_TYPE = "String";
+ private static final String INT_TYPE = "Integer";
+ private static final String LONG_TYPE = "Long";
+ private static final String SUBFIELD_TYPE = "SubFieldList";
+
+ private final List<RecordField> fields;
+
+ public RecordSchema(final List<RecordField> fields) {
+ this.fields = fields;
+ }
+
+ public RecordSchema(final RecordField... fields) {
+ this(Arrays.asList(fields));
+ }
+
+ public List<RecordField> getFields() {
+ return fields;
+ }
+
+ public RecordField getField(final String fieldName) {
+ return fields.stream()
+ .filter(field -> field.getFieldName().equals(fieldName))
+ .findFirst()
+ .orElse(null);
+ }
+
+ public void writeTo(final OutputStream out) throws IOException {
+ try {
+ final DataOutputStream dos = (out instanceof DataOutputStream)
? (DataOutputStream) out : new DataOutputStream(out);
+
+ dos.writeInt(fields.size());
+ for (final RecordField field : fields) {
+ writeField(field, dos);
+ }
+ } catch (final IOException ioe) {
+ throw new IOException("Unable to write Record Schema to
stream", ioe);
+ }
+ }
+
+ private void writeField(final RecordField field, final
DataOutputStream dos) throws IOException {
+ dos.writeInt(4); // 4 fields.
--- End diff --
This comment is/was very confusing to me. (I believe) this is writing the
4 values defining a field, not actually writing 4 fields.
This goes hand-in-hand with the loop in "readField" (that it's not reading
multiple fields but is reading the values defining a field).
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---