X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fio%2FFileBackedOutputStream.java;h=353a25156cc4940613a8a2a1a55b7ef8fb6c41fc;hb=b4bf55727093657662d8c16a50fa85f87978a586;hp=452611b5005acc2f8708a037d62a4b88d744345b;hpb=d796a8de8b208ca24bb57aebfc689f8be8bc2c7b;p=controller.git diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/io/FileBackedOutputStream.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/io/FileBackedOutputStream.java index 452611b500..353a25156c 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/io/FileBackedOutputStream.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/io/FileBackedOutputStream.java @@ -16,17 +16,16 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.file.Files; import java.util.Iterator; import java.util.Set; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import javax.annotation.concurrent.GuardedBy; import javax.annotation.concurrent.ThreadSafe; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -90,8 +89,7 @@ public class FileBackedOutputStream extends OutputStream { * @return a ByteSource instance * @throws IOException if close fails */ - @Nonnull - public synchronized ByteSource asByteSource() throws IOException { + public synchronized @NonNull ByteSource asByteSource() throws IOException { close(); if (source == null) { @@ -100,7 +98,7 @@ public class FileBackedOutputStream extends OutputStream { public InputStream openStream() throws IOException { synchronized (FileBackedOutputStream.this) { if (file != null) { - return new FileInputStream(file); + return Files.newInputStream(file.toPath()); } else { return new ByteArrayInputStream(memory.getBuffer(), 0, memory.getCount()); } @@ -201,15 +199,16 @@ public class FileBackedOutputStream extends OutputStream { } if (file == null && memory.getCount() + len > fileThreshold) { - File temp = File.createTempFile("FileBackedOutputStream", null, new File(fileDirectory)); + File temp = File.createTempFile("FileBackedOutputStream", null, + fileDirectory == null ? null : new File(fileDirectory)); temp.deleteOnExit(); LOG.debug("Byte count {} has exceeded threshold {} - switching to file: {}", memory.getCount() + len, fileThreshold, temp); - FileOutputStream transfer = null; + OutputStream transfer = null; try { - transfer = new FileOutputStream(temp); + transfer = Files.newOutputStream(temp.toPath()); transfer.write(memory.getBuffer(), 0, memory.getCount()); transfer.flush();