Package com.backblaze.b2.util
Class B2FlushAndSyncFileOnCloseOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- com.backblaze.b2.util.B2FlushAndSyncFileOnCloseOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public class B2FlushAndSyncFileOnCloseOutputStream extends java.io.OutputStream
Wrap your FileOutputStreams with a B2FlushAndSyncFileOnCloseOutputStream to ensure that your files are always sync'd before being closed. See http://www.pointsoftware.ch/en/4-ext4-vs-ext3-filesystem-and-why-delayed-allocation-is-bad/
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
static B2FlushAndSyncFileOnCloseOutputStream
create(java.io.File outputFile)
static B2FlushAndSyncFileOnCloseOutputStream
create(java.io.FileOutputStream out)
void
flush()
void
write(byte[] b)
void
write(byte[] b, int off, int len)
void
write(int b)
-
-
-
Method Detail
-
write
public void write(byte[] b) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException
- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(int b) throws java.io.IOException
- Specified by:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
create
public static B2FlushAndSyncFileOnCloseOutputStream create(java.io.FileOutputStream out)
- Parameters:
out
- the stream to wrap- Returns:
- a new stream which will carefully finish the file on disk when it's closed.
-
create
public static B2FlushAndSyncFileOnCloseOutputStream create(java.io.File outputFile) throws java.io.FileNotFoundException
- Parameters:
outputFile
- the file to write to. will be wrapped by a new FileOutputStream.- Returns:
- a new stream which will carefully finish the file on disk when it's closed.
- Throws:
java.io.FileNotFoundException
-
-