org.apache.ignite.internal.processors.cache.persistence.file

## Class RandomAccessFileIO

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIO

All Implemented Interfaces:
  AutoCloseable, FileIO

    public class RandomAccessFileIO
    extends Object
    implements FileIO

File I/O implementation based on `java.io.RandomAccessFile`.

### Constructor Summary

Constructors
Constructor and Description
`RandomAccessFileIO(RandomAccessFile file)` Creates I/O implementation for specified `file`

### Method Summary

Methods
`void` `clear()` Truncates current file to zero length and resets current file position to zero.
`void` `close()` Closes current file.
`void` `force()` Forces any updates of this file to be written to the storage device that contains it.
`long` `position()` Returns current file position.
`void` `position(long newPosition)` Sets new current file position.
`int` `read(byte[] buffer, int offset, int length)` Reads a up to `length` bytes from this file into the `buffer`.
`int` `read(ByteBuffer destinationBuffer)` Reads a sequence of bytes from this file into the `destinationBuffer`.
`int` `read(ByteBuffer destinationBuffer, long position)` Reads a sequence of bytes from this file into the `destinationBuffer` starting from specified file `position`.
`long` `size()` Returns current file size in bytes.
`void` `write(byte[] buffer, int offset, int length)` Writes `length` bytes from the `buffer` starting at offset `off` to this file.
`int` `write(ByteBuffer sourceBuffer)` Writes a sequence of bytes to this file from the `sourceBuffer`.
`int` `write(ByteBuffer sourceBuffer, long position)` Writes a sequence of bytes to this file from the `sourceBuffer` starting from specified file `position`

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

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

### Constructor Detail

#### RandomAccessFileIO

    public RandomAccessFileIO(RandomAccessFile file)

Creates I/O implementation for specified `file`

Parameters:
  `file` - Random access file

### Method Detail

#### position

    public long position()
                  throws IOException

Returns current file position.

Specified by:
  `position` in interface `FileIO`
Returns:
  Current file position, a non-negative integer counting the number of bytes from the beginning of the file to the current position.
Throws:
  `IOException` - If some I/O error occurs.

#### position

    public void position(long newPosition)
                  throws IOException

Sets new current file position.

Specified by:
  `position` in interface `FileIO`
Parameters:
  `newPosition` - The new position, a non-negative integer counting the number of bytes from the beginning of the file.
Throws:
  `IOException` - If some I/O error occurs.

#### read

    public int read(ByteBuffer destinationBuffer)
             throws IOException

Reads a sequence of bytes from this file into the `destinationBuffer`.

Specified by:
  `read` in interface `FileIO`
Parameters:
  `destinationBuffer` - Destination byte buffer.
Returns:
  Number of read bytes.
Throws:
  `IOException` - If some I/O error occurs.

#### read

    public int read(ByteBuffer destinationBuffer,
           long position)
             throws IOException

Reads a sequence of bytes from this file into the `destinationBuffer` starting from specified file `position`.

Specified by:
  `read` in interface `FileIO`
Parameters:
  `destinationBuffer` - Destination byte buffer.
  `position` - Starting position of file.
Returns:
  Number of read bytes.
Throws:
  `IOException` - If some I/O error occurs.

#### read

    public int read(byte[] buffer,
           int offset,
           int length)
             throws IOException

Reads a up to `length` bytes from this file into the `buffer`.

Specified by:
  `read` in interface `FileIO`
Parameters:
  `buffer` - Destination byte array.
  `offset` - The start offset in array `b` at which the data is written.
  `length` - Maximum number of bytes read.
Returns:
  Number of read bytes.
Throws:
  `IOException` - If some I/O error occurs.

#### write

    public int write(ByteBuffer sourceBuffer)
              throws IOException

Writes a sequence of bytes to this file from the `sourceBuffer`.

Specified by:
  `write` in interface `FileIO`
Parameters:
  `sourceBuffer` - Source buffer.
Returns:
  Number of written bytes.
Throws:
  `IOException` - If some I/O error occurs.

#### write

    public int write(ByteBuffer sourceBuffer,
            long position)
              throws IOException

Writes a sequence of bytes to this file from the `sourceBuffer` starting from specified file `position`

Specified by:
  `write` in interface `FileIO`
Parameters:
  `sourceBuffer` - Source buffer.
  `position` - Starting file position.
Returns:
  Number of written bytes.
Throws:
  `IOException` - If some I/O error occurs.

#### write

    public void write(byte[] buffer,
             int offset,
             int length)
               throws IOException

Writes `length` bytes from the `buffer` starting at offset `off` to this file.

Specified by:
  `write` in interface `FileIO`
Parameters:
  `buffer` - Source byte array.
  `offset` - Start offset in the `buffer`.
  `length` - Number of bytes to write.
Throws:
  `IOException` - If some I/O error occurs.

#### force

    public void force()
               throws IOException

Forces any updates of this file to be written to the storage device that contains it.

Specified by:
  `force` in interface `FileIO`
Throws:
  `IOException` - If some I/O error occurs.

#### size

    public long size()
              throws IOException

Returns current file size in bytes.

Specified by:
  `size` in interface `FileIO`
Returns:
  File size.
Throws:
  `IOException` - If some I/O error occurs.

#### clear

    public void clear()
               throws IOException

Truncates current file to zero length and resets current file position to zero.

Specified by:
  `clear` in interface `FileIO`
Throws:
  `IOException` - If some I/O error occurs.

#### close

    public void close()
               throws IOException

Closes current file.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `FileIO`
Throws:
  `IOException` - If some I/O error occurs.

2017 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.2.0
Release Date | : September 15 2017