Package alluxio.underfs
Class AtomicFileOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- alluxio.underfs.AtomicFileOutputStream
-
- All Implemented Interfaces:
ContentHashable
,java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
@NotThreadSafe public class AtomicFileOutputStream extends java.io.OutputStream implements ContentHashable
AAtomicFileOutputStream
writes to a temporary file and renames on close. This ensures that writing to the stream is atomic, i.e., all writes become readable only after a close.
-
-
Constructor Summary
Constructors Constructor Description AtomicFileOutputStream(java.lang.String path, AtomicFileOutputStreamCallback ufs, CreateOptions options)
Constructs a newAtomicFileOutputStream
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
java.util.Optional<java.lang.String>
getContentHash()
void
write(byte[] b)
void
write(byte[] b, int off, int len)
void
write(int b)
-
-
-
Constructor Detail
-
AtomicFileOutputStream
public AtomicFileOutputStream(java.lang.String path, AtomicFileOutputStreamCallback ufs, CreateOptions options) throws java.io.IOException
Constructs a newAtomicFileOutputStream
.- Parameters:
path
- path being written toufs
- the callingUnderFileSystem
options
- create options for destination file- Throws:
java.io.IOException
-
-
Method Detail
-
write
public void write(int b) throws java.io.IOException
- Specified by:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
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
-
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
-
getContentHash
public java.util.Optional<java.lang.String> getContentHash() throws java.io.IOException
- Specified by:
getContentHash
in interfaceContentHashable
- Returns:
- the content hash of the file written to the UFS if available after the stream has been closed
- Throws:
java.io.IOException
-
-