Class FileIO

java.lang.Object
org.cojen.tupl.io.FileIO
All Implemented Interfaces:
Closeable, AutoCloseable, CauseCloseable

public abstract class FileIO extends Object implements CauseCloseable
Lowest I/O interface to a file or device.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    static void
    dirSync(File file)
    Durably flushes the given directory, if required.
    void
    expandLength(long length)
    Attempt to expand the length of the file.
    abstract void
    expandLength(long length, LengthOption option)
    Attempt to expand the length of the file.
    abstract boolean
     
    abstract boolean
     
    abstract long
     
    abstract void
    map()
    Maps or remaps the file into main memory, up to the current file length.
    static FileIO
    open(File file, EnumSet<OpenOption> options)
     
    static FileIO
    open(File file, EnumSet<OpenOption> options, int openFileCount)
     
    abstract void
    read(long pos, byte[] buf, int offset, int length)
     
    void
    read(long pos, long ptr, int offset, int length)
     
    abstract void
    If file is mapped, remaps it if the file length has changed.
    abstract void
    sync(boolean metadata)
    Durably flushes all writes to the underlying device.
    abstract void
    truncateLength(long length)
    Attempt to truncate the length of the file.
    abstract void
    Unmaps the file from main memory, leaving the file open.
    abstract void
    write(long pos, byte[] buf, int offset, int length)
     
    void
    write(long pos, long ptr, int offset, int length)
     

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface org.cojen.tupl.io.CauseCloseable

    close
  • Method Details

    • open

      public static FileIO open(File file, EnumSet<OpenOption> options) throws IOException
      Throws:
      IOException
    • open

      public static FileIO open(File file, EnumSet<OpenOption> options, int openFileCount) throws IOException
      Throws:
      IOException
    • isDirectIO

      public abstract boolean isDirectIO()
    • isReadOnly

      public abstract boolean isReadOnly()
    • length

      public abstract long length() throws IOException
      Throws:
      IOException
    • truncateLength

      public abstract void truncateLength(long length) throws IOException
      Attempt to truncate the length of the file. It isn't critical that the operation succeed, and so any exceptions can be suppressed.
      Throws:
      IOException
    • expandLength

      public void expandLength(long length) throws IOException
      Attempt to expand the length of the file. It isn't critical that the operation succeed, and so any exceptions can be suppressed.
      Throws:
      IOException
    • expandLength

      public abstract void expandLength(long length, LengthOption option) throws IOException
      Attempt to expand the length of the file. It isn't critical that the operation succeed, and so any exceptions can be suppressed.
      Throws:
      IOException
    • read

      public abstract void read(long pos, byte[] buf, int offset, int length) throws IOException
      Parameters:
      pos - zero-based position in file
      buf - receives read data
      offset - offset into data buffer
      length - amount of data to read
      Throws:
      IllegalArgumentException
      IOException
    • read

      public void read(long pos, long ptr, int offset, int length) throws IOException
      Throws:
      IOException
    • write

      public abstract void write(long pos, byte[] buf, int offset, int length) throws IOException
      Parameters:
      pos - zero-based position in file
      buf - data to write
      offset - offset into data buffer
      length - amount of data
      Throws:
      IllegalArgumentException
      IOException
    • write

      public void write(long pos, long ptr, int offset, int length) throws IOException
      Throws:
      IOException
    • map

      public abstract void map() throws IOException
      Maps or remaps the file into main memory, up to the current file length.
      Throws:
      IOException
    • remap

      public abstract void remap() throws IOException
      If file is mapped, remaps it if the file length has changed. Method does nothing if not already mapped.
      Throws:
      IOException
    • unmap

      public abstract void unmap() throws IOException
      Unmaps the file from main memory, leaving the file open. Method does nothing if not already mapped.
      Throws:
      IOException
    • sync

      public abstract void sync(boolean metadata) throws IOException
      Durably flushes all writes to the underlying device.
      Parameters:
      metadata - pass true to flush all file metadata
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • dirSync

      public static void dirSync(File file) throws IOException
      Durably flushes the given directory, if required. If the given file is not a directory, the parent directory is flushed.
      Throws:
      IOException