Bug 7449: Add message slicing/re-assembly classes
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / io / FileBackedOutputStreamFactory.java
1 /*
2  * Copyright (c) 2017 Inocybe Technologies 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 javax.annotation.Nullable;
11
12 /**
13  * A factory for creating {@link FileBackedOutputStream} instances.
14  *
15  * @author Thomas Pantelis
16  * @see FileBackedOutputStream
17  */
18 public class FileBackedOutputStreamFactory {
19     private final int fileThreshold;
20     private final String fileDirectory;
21
22     /**
23      * Constructor.
24      *
25      * @param fileThreshold the number of bytes before streams should switch to buffering to a file
26      * @param fileDirectory the directory in which to create files if needed. If null, the default temp file
27      *                      location is used.
28      */
29     public FileBackedOutputStreamFactory(final int fileThreshold, final @Nullable String fileDirectory) {
30         this.fileThreshold = fileThreshold;
31         this.fileDirectory = fileDirectory;
32     }
33
34     /**
35      * Creates a new {@link FileBackedOutputStream} with the settings configured for this factory.
36      *
37      * @return a {@link FileBackedOutputStream} instance
38      */
39     public FileBackedOutputStream newInstance() {
40         return new FileBackedOutputStream(fileThreshold, fileDirectory);
41     }
42 }