org.opendaylight.yangtools.yang2sources.plugin.CapturingOutputStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yang-maven-plugin Show documentation
Show all versions of yang-maven-plugin Show documentation
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
/*
* 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.HashingOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
/**
* An {@link OutputStream} which captures the sum of its contents.
*/
final class CapturingOutputStream extends FilterOutputStream {
private long size;
CapturingOutputStream(final OutputStream out) {
super(new HashingOutputStream(Hashing.crc32c(), out));
}
@Override
@SuppressWarnings("checkstyle:parameterName")
public void write(final int b) throws IOException {
out().write(b);
size++;
}
@Override
@SuppressWarnings("checkstyle:parameterName")
public void write(final byte[] b, final int off, final int len) throws IOException {
out().write(b, off, len);
size += len;
}
long size() {
return size;
}
int crc32c() {
return out().hash().asInt();
}
private HashingOutputStream out() {
return (HashingOutputStream) out;
}
}