Package herddb.utils
Class ManagedFile
- java.lang.Object
-
- herddb.utils.ManagedFile
-
- All Implemented Interfaces:
AutoCloseable
public class ManagedFile extends Object implements AutoCloseable
A "managed" file that give access to underlyingOutputStreamfor write operations and permit to sync to disk flushed data.- Author:
- diego.salvi
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()OutputStreamgetOutputStream()Returns theOutputStreamthat can be used to write to the filestatic ManagedFileopen(FileChannel channel, boolean requirefsync)static ManagedFileopen(Path path, boolean requirefsync)static ManagedFileopen(Path path, boolean requirefsync, StandardOpenOption... options)Opens or creates a file, returning aManagedFilethat may be used to write bytes to the file.static ManagedFileopen(Path path, boolean requirefsync, Set<? extends OpenOption> options, FileAttribute<?>... attrs)Opens or creates a file, returning aManagedFilethat may be used to write bytes to the file.voidsync()Forces any updates to be written to the storage device that contains it.voidsync(boolean metaData)Forces any updates to be written to the storage device that contains it.
-
-
-
Method Detail
-
open
public static ManagedFile open(Path path, boolean requirefsync) throws IOException
- Throws:
IOException
-
open
public static ManagedFile open(Path path, boolean requirefsync, StandardOpenOption... options) throws IOException
Opens or creates a file, returning aManagedFilethat may be used to write bytes to the file.If no options are present then this method works as if the CREATE, TRUNCATE_EXISTING, and WRITE options are present. In other words, it opens the file for writing, creating the file if it doesn't exist, or initially truncating an existing regular-file to a size of 0 if it exists.
- Parameters:
path-requirefsync-options-- Returns:
- Throws:
IOException
-
open
public static ManagedFile open(Path path, boolean requirefsync, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException
Opens or creates a file, returning aManagedFilethat may be used to write bytes to the file.If no options are present then this method works as if the CREATE, TRUNCATE_EXISTING, and WRITE options are present. In other words, it opens the file for writing, creating the file if it doesn't exist, or initially truncating an existing regular-file to a size of 0 if it exists.
- Parameters:
path-options-attrs-- Returns:
- Throws:
IOException
-
open
public static ManagedFile open(FileChannel channel, boolean requirefsync) throws IOException
- Throws:
IOException
-
sync
public void sync() throws IOExceptionForces any updates to be written to the storage device that contains it.- Throws:
IOException- See Also:
FileChannel.force(boolean)
-
sync
public void sync(boolean metaData) throws IOExceptionForces any updates to be written to the storage device that contains it.- Throws:
IOException- See Also:
FileChannel.force(boolean)
-
getOutputStream
public OutputStream getOutputStream()
Returns theOutputStreamthat can be used to write to the file- Returns:
- file output stream
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-
-