org.apache.avro.file

## Class SyncableFileOutputStream

- java.lang.Object
- - java.io.OutputStream
  - - java.io.FileOutputStream
    - - org.apache.avro.file.SyncableFileOutputStream

All Implemented Interfaces:
  Closeable, Flushable, AutoCloseable, Syncable

    public class SyncableFileOutputStream
    extends FileOutputStream
    implements Syncable

An implementation of Syncable which writes to a file. An instance of this class can be used with DataFileWriter to guarantee that Avro Container Files are persisted to disk on supported platforms using the DataFileWriter.fSync() method.

See Also:
  `FileOutputStream`

### Constructor Summary

Constructors
Constructor and Description
`SyncableFileOutputStream(File file)` Creates an instance of SyncableFileOutputStream using the given File instance.
`SyncableFileOutputStream(File file, boolean append)` Creates an instance of SyncableFileOutputStream that writes to the file represented by the given File instance and optionally append to the file if it already exists.
`SyncableFileOutputStream(FileDescriptor fdObj)` Creates an instance of SyncableFileOutputStream using the given FileDescriptor instance.
`SyncableFileOutputStream(String name)` Creates an instance of SyncableFileOutputStream with the given name.
`SyncableFileOutputStream(String name, boolean append)` Creates an instance of SyncableFileOutputStream with the given name and optionally append to the file if it already exists.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `sync()` Sync the file to disk.

### Methods inherited from class java.io.FileOutputStream

`close, finalize, getChannel, getFD, write, write, write`

### Methods inherited from class java.io.OutputStream

`flush`

### Methods inherited from class java.lang.Object

`clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### SyncableFileOutputStream

    public SyncableFileOutputStream(String name)
                             throws FileNotFoundException

Creates an instance of SyncableFileOutputStream with the given name.

Parameters:
  `name` - - the full file name.
Throws:
  `FileNotFoundException` - - if the file cannot be created or opened.

#### SyncableFileOutputStream

    public SyncableFileOutputStream(File file)
                             throws FileNotFoundException

Creates an instance of SyncableFileOutputStream using the given File instance.

Parameters:
  `file` - - The file to use to create the output stream.
Throws:
  `FileNotFoundException` - - if the file cannot be created or opened.

#### SyncableFileOutputStream

    public SyncableFileOutputStream(String name,
                                    boolean append)
                             throws FileNotFoundException

Creates an instance of SyncableFileOutputStream with the given name and optionally append to the file if it already exists.

Parameters:
  `name` - - the full file name.
  `append` - - true if the file is to be appended to
Throws:
  `FileNotFoundException` - - if the file cannot be created or opened.

#### SyncableFileOutputStream

    public SyncableFileOutputStream(File file,
                                    boolean append)
                             throws FileNotFoundException

Creates an instance of SyncableFileOutputStream that writes to the file represented by the given File instance and optionally append to the file if it already exists.

Parameters:
  `file` - - the file instance to use to create the stream.
  `append` - - true if the file is to be appended to
Throws:
  `FileNotFoundException` - - if the file cannot be created or opened.

#### SyncableFileOutputStream

    public SyncableFileOutputStream(FileDescriptor fdObj)

Creates an instance of SyncableFileOutputStream using the given FileDescriptor instance.

### Method Detail

#### sync

    public void sync()
              throws IOException

Sync the file to disk. On supported platforms, this method behaves like POSIX `fsync` and syncs all underlying OS buffers for this file descriptor to disk. On these platforms, if this method returns, the data written to this instance is guaranteed to be persisted on disk.

Specified by:
  `sync` in interface `Syncable`
Throws:
  `IOException` - - if an error occurred while attempting to sync the data to disk.