nifi-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markap14 <...@git.apache.org>
Subject [GitHub] nifi pull request #1214: NIFI-2876 refactored demarcators into a common abst...
Date Thu, 23 Feb 2017 14:40:36 GMT
Github user markap14 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1214#discussion_r102712235
  
    --- Diff: nifi-commons/nifi-utils/src/main/java/org/apache/nifi/stream/io/util/AbstractDemarcator.java
---
    @@ -0,0 +1,138 @@
    +/*
    + * 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.stream.io.util;
    +
    +import java.io.Closeable;
    +import java.io.IOException;
    +import java.io.InputStream;
    +
    +import org.apache.nifi.stream.io.exception.TokenTooLargeException;
    +
    +/**
    + * Base class for implementing streaming demarcators.
    + * <p>
    + * NOTE: Not intended for multi-thread usage hence not Thread-safe.
    + * </p>
    + */
    +abstract class AbstractDemarcator implements Closeable {
    +
    +    final static int INIT_BUFFER_SIZE = 8192;
    +
    +    private final InputStream is;
    +
    +    private final int initialBufferSize;
    +
    +    private final int maxDataSize;
    +
    +    byte[] buffer;
    +
    +    int index;
    +
    +    int mark;
    +
    +    long offset;
    +
    +    int bufferLength;
    +
    +    /**
    +     * Constructs an instance of demarcator with provided {@link InputStream}
    +     * and max buffer size. Each demarcated token must fit within max buffer
    +     * size, otherwise the exception will be raised.
    +     */
    +    AbstractDemarcator(InputStream is, int maxDataSize) {
    +        this(is, maxDataSize, INIT_BUFFER_SIZE);
    +    }
    +
    +    /**
    +     * Constructs an instance of demarcator with provided {@link InputStream}
    +     * and max buffer size and initial buffer size. Each demarcated token must
    +     * fit within max buffer size, otherwise the exception will be raised.
    +     */
    +    AbstractDemarcator(InputStream is, int maxDataSize, int initialBufferSize) {
    +        this.validate(is, maxDataSize, initialBufferSize);
    +        this.is = is;
    +        this.initialBufferSize = initialBufferSize;
    +        this.buffer = new byte[initialBufferSize];
    +        this.maxDataSize = maxDataSize;
    +    }
    +
    +    @Override
    +    public void close() throws IOException {
    +        // noop
    --- End diff --
    
    This appears to be a resource leak, as it is not closing the given InputStream


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

Mime
View raw message