Code Review
/
controller.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Reduce JSR305 proliferation
[controller.git]
/
opendaylight
/
md-sal
/
sal-clustering-commons
/
src
/
main
/
java
/
org
/
opendaylight
/
controller
/
cluster
/
io
/
FileBackedOutputStream.java
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 452611b5005acc2f8708a037d62a4b88d744345b..353a25156cc4940613a8a2a1a55b7ef8fb6c41fc 100644
(file)
--- 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.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.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.file.Files;
import java.util.Iterator;
import java.util.Set;
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 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;
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
*/
* @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) {
close();
if (source == null) {
@@
-100,7
+98,7
@@
public class FileBackedOutputStream extends OutputStream {
public InputStream openStream() throws IOException {
synchronized (FileBackedOutputStream.this) {
if (file != null) {
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());
}
} 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) {
}
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);
temp.deleteOnExit();
LOG.debug("Byte count {} has exceeded threshold {} - switching to file: {}", memory.getCount() + len,
fileThreshold, temp);
-
File
OutputStream transfer = null;
+ OutputStream transfer = null;
try {
try {
- transfer =
new FileOutputStream(temp
);
+ transfer =
Files.newOutputStream(temp.toPath()
);
transfer.write(memory.getBuffer(), 0, memory.getCount());
transfer.flush();
transfer.write(memory.getBuffer(), 0, memory.getCount());
transfer.flush();