All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opendaylight.yangtools.yang2sources.plugin.CapturingInputStream Maven / Gradle / Ivy

Go to download

This plugin is a wrapper for "yang to source code" generation. It can be configured by a set of third-party code generators and resource providers. For further info see available goals. Sample usage: TODO: add sample usage when finished

The newest version!
/*
 * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.yangtools.yang2sources.plugin;

import com.google.common.hash.Hashing;
import com.google.common.hash.HashingInputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * An {@link InputStream} which captures the sum of its contents.
 */
final class CapturingInputStream extends FilterInputStream {
    private long size;

    CapturingInputStream(final InputStream in) {
        super(new HashingInputStream(Hashing.crc32c(), in));
    }

    @Override
    public int read() throws IOException {
        final int ret = super.read();
        if (ret != -1) {
            size++;
        }
        return ret;
    }

    @Override
    @SuppressWarnings("checkstyle:parameterName")
    public int read(final byte[] b, final int off, final int len) throws IOException {
        final int ret = super.read(b, off, len);
        if (ret != -1) {
            size += ret;
        }
        return ret;
    }

    long size() {
        return size;
    }

    int crc32c() {
        return ((HashingInputStream) in).hash().asInt();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy