X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fio%2FInputOutputStreamFactory.java;fp=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fio%2FInputOutputStreamFactory.java;h=01e1098bb0eb479b12733a972fae66ccb4d12025;hb=e7e69069ae5ecaacc9ea0e47cb40cdf68237d636;hp=0000000000000000000000000000000000000000;hpb=6ef0b898f2117a4bb3a510c0df7af340f4fc8eca;p=controller.git diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/io/InputOutputStreamFactory.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/io/InputOutputStreamFactory.java new file mode 100644 index 0000000000..01e1098bb0 --- /dev/null +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/io/InputOutputStreamFactory.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2020 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.controller.cluster.io; + +import static java.util.Objects.requireNonNull; + +import com.google.common.annotations.Beta; +import com.google.common.io.ByteSource; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import net.jpountz.lz4.LZ4FrameOutputStream; +import org.eclipse.jdt.annotation.NonNull; + +@Beta +public abstract class InputOutputStreamFactory { + InputOutputStreamFactory() { + // Hidden on purpose + } + + public static @NonNull InputOutputStreamFactory simple() { + return PlainInputOutputStreamSupport.INSTANCE; + } + + public static @NonNull InputOutputStreamFactory lz4(final String blockSize) { + return lz4(LZ4FrameOutputStream.BLOCKSIZE.valueOf("SIZE_" + blockSize)); + } + + public static @NonNull InputOutputStreamFactory lz4(final LZ4FrameOutputStream.BLOCKSIZE blockSize) { + return new LZ4InputOutputStreamSupport(requireNonNull(blockSize)); + } + + public abstract @NonNull InputStream createInputStream(ByteSource input) throws IOException; + + public abstract @NonNull InputStream createInputStream(File file) throws IOException; + + public abstract @NonNull OutputStream createOutputStream(File file) throws IOException; + + public abstract @NonNull OutputStream wrapOutputStream(OutputStream output) throws IOException; + + static @NonNull BufferedInputStream defaultCreateInputStream(final File file) throws FileNotFoundException { + return new BufferedInputStream(new FileInputStream(file)); + } + + static @NonNull BufferedOutputStream defaultCreateOutputStream(final File file) throws FileNotFoundException { + return new BufferedOutputStream(new FileOutputStream(file)); + } +}