Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / io / InputOutputStreamFactory.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.io;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import com.google.common.io.ByteSource;
14 import java.io.BufferedInputStream;
15 import java.io.BufferedOutputStream;
16 import java.io.File;
17 import java.io.FileInputStream;
18 import java.io.FileNotFoundException;
19 import java.io.FileOutputStream;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.io.OutputStream;
23 import net.jpountz.lz4.LZ4FrameOutputStream;
24 import org.eclipse.jdt.annotation.NonNull;
25
26 @Beta
27 public abstract class InputOutputStreamFactory {
28     InputOutputStreamFactory() {
29         // Hidden on purpose
30     }
31
32     public static @NonNull InputOutputStreamFactory simple() {
33         return PlainInputOutputStreamSupport.INSTANCE;
34     }
35
36     public static @NonNull InputOutputStreamFactory lz4(final String blockSize) {
37         return lz4(LZ4FrameOutputStream.BLOCKSIZE.valueOf("SIZE_" + blockSize));
38     }
39
40     public static @NonNull InputOutputStreamFactory lz4(final LZ4FrameOutputStream.BLOCKSIZE blockSize) {
41         return new LZ4InputOutputStreamSupport(requireNonNull(blockSize));
42     }
43
44     public abstract @NonNull InputStream createInputStream(ByteSource input) throws IOException;
45
46     public abstract @NonNull InputStream createInputStream(File file) throws IOException;
47
48     public abstract @NonNull OutputStream createOutputStream(File file) throws IOException;
49
50     public abstract @NonNull OutputStream wrapOutputStream(OutputStream output) throws IOException;
51
52     static @NonNull BufferedInputStream defaultCreateInputStream(final File file) throws FileNotFoundException {
53         return new BufferedInputStream(new FileInputStream(file));
54     }
55
56     static @NonNull BufferedOutputStream defaultCreateOutputStream(final File file) throws FileNotFoundException {
57         return new BufferedOutputStream(new FileOutputStream(file));
58     }
59 }