Package com.indeed.util.io
Class SafeOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- com.indeed.util.io.SafeOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable,java.nio.channels.Channel,java.nio.channels.WritableByteChannel
@NotThreadSafe public abstract class SafeOutputStream extends java.io.OutputStream implements java.nio.channels.WritableByteChannel, java.io.Closeable- See Also:
SafeFiles.createAtomicFile(Path)
-
-
Constructor Summary
Constructors Constructor Description SafeOutputStream()
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description abstract voidclose()Ifcommit()as been called, this method is a NO-OP.abstract voidcommit()Commit causes the current atomic file writing operation to conclude and the current temp file is safely promoted to being the canonical file.abstract intwrite(java.nio.ByteBuffer src)Writes a sequence of bytes to this channel from the given buffer.
-
-
-
Method Detail
-
write
public abstract int write(@Nonnull java.nio.ByteBuffer src) throws java.io.IOExceptionWrites a sequence of bytes to this channel from the given buffer.Unlike the contract of
WritableByteChannel, the ENTIRE buffer is written to the channel (behaving like writeFully).- Specified by:
writein interfacejava.nio.channels.WritableByteChannel- Parameters:
src- The buffer to flush.- Returns:
- The number of bytes written to the output stream.
- Throws:
java.io.IOException- in the event that the buffer could not be written.
-
commit
public abstract void commit() throws java.io.IOExceptionCommit causes the current atomic file writing operation to conclude and the current temp file is safely promoted to being the canonical file.It is safe to call
close()} after commit. It is NOT safe to call any of the variations onwrite(java.nio.ByteBuffer)orOutputStream.flush()however.- Throws:
java.io.IOException- in the event that the data could not be committed.
-
close
public abstract void close() throws java.io.IOExceptionIfcommit()as been called, this method is a NO-OP. Otherwise...Close causes the current atomic file writing operation to abort and the current temp file to be erased. It is NOT safe to call any of the variations on
write(java.nio.ByteBuffer)orOutputStream.flush()however.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException- in the event that the output stream cannot be closed.
-
-