# Class NioByteStoreAccess

java.lang.Object
uk.ac.starlink.table.storage.NioByteStoreAccess

All Implemented Interfaces:
  `ByteStoreAccess`

public abstract class NioByteStoreAccess extends Object implements ByteStoreAccess
Partial implementation of ByteStoreAccess. Not thread-safe.

Since:
  20 Aug 2010
Author:
  Mark Taylor

## Constructor Summary

Constructors
Constructor
Description
`NioByteStoreAccess()`

## Method Summary

Modifier and Type
Method
Description
`static ByteBuffer[]`
`copyBuffers(ByteBuffer[] bufs)`
Utility method to make a deep copy of an array of ByteBuffers.
`static ByteStoreAccess`
`createAccess(ByteBuffer[] bbufs)`
Returns a reader implementation for an array of ByteBuffers.
`protected abstract ByteBuffer`
`getBuffer(int nbyte)`
Returns a buffer with at least the requested number of bytes between the current position and the limit.
`byte`
`readByte()`
Reads a byte from the current position.
`void`
`readBytes(byte[] b, int offset, int length)`
Reads bytes into a buffer from the current position.
`char`
`readChar()`
Reads a char from the current position.
`double`
`readDouble()`
Reads a double from the current position.
`float`
`readFloat()`
Reads a float from the current position.
`int`
`readInt()`
Reads an int from the current position.
`long`
`readLong()`
Reads a long from the current position.
`short`
`readShort()`
Reads a short from the current position.

### Methods inherited from class Object

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

### Methods inherited from interface ByteStoreAccess

`seek, skip`

## Constructor Details

### NioByteStoreAccess

public NioByteStoreAccess()

## Method Details

### getBuffer

protected abstract ByteBuffer getBuffer(int nbyte) throws IOException
Returns a buffer with at least the requested number of bytes between the current position and the limit. When `nbyte` bytes have been read from the returned buffer, the current position of this ByteStoreAccess will have advanced by `nbyte` bytes. The position in the case that this call is made with no corresponding read is undefined, so it's important that the read is actually done (don't call this method speculatively).

If no such buffer is available (the end of the storage has been reached), then an IOException will be thrown.

Parameters:
  `nbyte` - number of bytes required
Returns:
  buffer from which `nbyte` bytes can be read
Throws:
  `IOException`

### readByte

public byte readByte() throws IOException
Description copied from interface: `ByteStoreAccess`
Reads a byte from the current position.

Specified by:
  `readByte` in interface `ByteStoreAccess`
Returns:
  read value
Throws:
  `IOException`

### readShort

public short readShort() throws IOException
Description copied from interface: `ByteStoreAccess`
Reads a short from the current position.

Specified by:
  `readShort` in interface `ByteStoreAccess`
Returns:
  read value
Throws:
  `IOException`

### readChar

public char readChar() throws IOException
Description copied from interface: `ByteStoreAccess`
Reads a char from the current position.

Specified by:
  `readChar` in interface `ByteStoreAccess`
Returns:
  read value
Throws:
  `IOException`

### readInt

public int readInt() throws IOException
Description copied from interface: `ByteStoreAccess`
Reads an int from the current position.

Specified by:
  `readInt` in interface `ByteStoreAccess`
Returns:
  read value
Throws:
  `IOException`

### readLong

public long readLong() throws IOException
Description copied from interface: `ByteStoreAccess`
Reads a long from the current position.

Specified by:
  `readLong` in interface `ByteStoreAccess`
Returns:
  read value
Throws:
  `IOException`

### readFloat

public float readFloat() throws IOException
Description copied from interface: `ByteStoreAccess`
Reads a float from the current position.

Specified by:
  `readFloat` in interface `ByteStoreAccess`
Returns:
  read value
Throws:
  `IOException`

### readDouble

public double readDouble() throws IOException
Description copied from interface: `ByteStoreAccess`
Reads a double from the current position.

Specified by:
  `readDouble` in interface `ByteStoreAccess`
Returns:
  read value
Throws:
  `IOException`

### readBytes

public void readBytes(byte[] b, int offset, int length) throws IOException
Description copied from interface: `ByteStoreAccess`
Reads bytes into a buffer from the current position.

Specified by:
  `readBytes` in interface `ByteStoreAccess`
Parameters:
  `b` - buffer to receive bytes
  `offset` - offset into `b` for first byte
  `length` - number of bytes to read
Throws:
  `IOException`

### copyBuffers

public static ByteBuffer[] copyBuffers(ByteBuffer[] bufs)
Utility method to make a deep copy of an array of ByteBuffers.

Parameters:
  `bufs` - input buffers
Returns:
  matching array with buffers that are duplicates of the input elements

### createAccess

public static ByteStoreAccess createAccess(ByteBuffer[] bbufs)
Returns a reader implementation for an array of ByteBuffers.

Parameters:
  `bbufs` - buffer array
Returns:
  reader implementation