2 * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang2sources.plugin;
10 import com.google.common.hash.Hashing;
11 import com.google.common.hash.HashingOutputStream;
12 import java.io.FilterOutputStream;
13 import java.io.IOException;
14 import java.io.OutputStream;
17 * An {@link OutputStream} which captures the sum of its contents.
19 final class CapturingOutputStream extends FilterOutputStream {
22 CapturingOutputStream(final OutputStream out) {
23 super(new HashingOutputStream(Hashing.crc32c(), out));
27 @SuppressWarnings("checkstyle:parameterName")
28 public void write(final int b) throws IOException {
34 @SuppressWarnings("checkstyle:parameterName")
35 public void write(final byte[] b, final int off, final int len) throws IOException {
36 out().write(b, off, len);
45 return out().hash().asInt();
48 private HashingOutputStream out() {
49 return (HashingOutputStream) out;