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;
* @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) {
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());
}
}
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();