2 * Copyright (c) 2017 Inocybe Technologies 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.controller.cluster.io;
10 import org.eclipse.jdt.annotation.Nullable;
13 * A factory for creating {@link FileBackedOutputStream} instances.
15 * @author Thomas Pantelis
16 * @see FileBackedOutputStream
18 public class FileBackedOutputStreamFactory {
19 private final int fileThreshold;
20 private final String fileDirectory;
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
29 public FileBackedOutputStreamFactory(final int fileThreshold, final @Nullable String fileDirectory) {
30 this.fileThreshold = fileThreshold;
31 this.fileDirectory = fileDirectory;
35 * Creates a new {@link FileBackedOutputStream} with the settings configured for this factory.
37 * @return a {@link FileBackedOutputStream} instance
39 public FileBackedOutputStream newInstance() {
40 return new FileBackedOutputStream(fileThreshold, fileDirectory);
44 * Creates a new {@link SharedFileBackedOutputStream} with the settings configured for this factory.
46 * @return a {@link SharedFileBackedOutputStream} instance
48 public SharedFileBackedOutputStream newSharedInstance() {
49 return new SharedFileBackedOutputStream(fileThreshold, fileDirectory);