Github user JPercivall commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1202#discussion_r87674718
  
    --- Diff: 
nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/serialization/CompressableRecordReader.java
 ---
    @@ -0,0 +1,281 @@
    +/*
    + * 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.provenance.serialization;
    +
    +import java.io.DataInputStream;
    +import java.io.EOFException;
    +import java.io.IOException;
    +import java.io.InputStream;
    +import java.nio.charset.StandardCharsets;
    +import java.util.zip.GZIPInputStream;
    +
    +import org.apache.nifi.provenance.ProvenanceEventRecord;
    +import org.apache.nifi.provenance.StandardProvenanceEventRecord;
    +import org.apache.nifi.provenance.StandardRecordReader;
    +import org.apache.nifi.provenance.toc.TocReader;
    +import org.apache.nifi.stream.io.BufferedInputStream;
    +import org.apache.nifi.stream.io.ByteCountingInputStream;
    +import org.apache.nifi.stream.io.LimitingInputStream;
    +import org.apache.nifi.stream.io.StreamUtils;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +public abstract class CompressableRecordReader implements RecordReader {
    +    private static final Logger logger = 
LoggerFactory.getLogger(StandardRecordReader.class);
    +
    +    private final ByteCountingInputStream rawInputStream;
    +    private final String filename;
    +    private final int serializationVersion;
    +    private final boolean compressed;
    +    private final TocReader tocReader;
    +    private final int headerLength;
    +    private final int maxAttributeChars;
    +
    +    private DataInputStream dis;
    +    private ByteCountingInputStream byteCountingIn;
    +
    +    public CompressableRecordReader(final InputStream in, final String 
filename, final int maxAttributeChars) throws IOException {
    +        this(in, filename, null, maxAttributeChars);
    +    }
    +
    +    public CompressableRecordReader(final InputStream in, final String 
filename, final TocReader tocReader, final int maxAttributeChars) throws 
IOException {
    +        logger.trace("Creating RecordReader for {}", filename);
    +
    +        rawInputStream = new ByteCountingInputStream(in);
    +        this.maxAttributeChars = maxAttributeChars;
    +
    +        final InputStream limitedStream;
    +        if (tocReader == null) {
    +            limitedStream = rawInputStream;
    +        } else {
    +            final long offset1 = tocReader.getBlockOffset(1);
    +            if (offset1 < 0) {
    +                limitedStream = rawInputStream;
    +            } else {
    +                limitedStream = new LimitingInputStream(rawInputStream, 
offset1 - rawInputStream.getBytesConsumed());
    +            }
    +        }
    +
    +        final InputStream readableStream;
    +        if (filename.endsWith(".gz")) {
    +            readableStream = new BufferedInputStream(new 
GZIPInputStream(limitedStream));
    +            compressed = true;
    +        } else {
    +            readableStream = new BufferedInputStream(limitedStream);
    +            compressed = false;
    +        }
    +
    +        byteCountingIn = new ByteCountingInputStream(readableStream);
    +        dis = new DataInputStream(byteCountingIn);
    +
    +        final String repoClassName = dis.readUTF();
    +        final int serializationVersion = dis.readInt();
    +        headerLength = 
repoClassName.getBytes(StandardCharsets.UTF_8).length + 2 + 4; // 2 bytes for 
string length, 4 for integer.
    +
    +        if (serializationVersion < 1 || serializationVersion > 9) {
    +            throw new IllegalArgumentException("Unable to deserialize 
record because the version is " + serializationVersion + " and supported 
versions are 1-9");
    --- End diff --
    
    Wouldn't this be version 10?


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to