# Class BlockManager

java.lang.Object
uk.ac.starlink.fits.BlockManager

public class BlockManager extends Object
Manages access to a region of a file in blocks using multiple BufferManagers to cover it.

Since:
  12 May 2022
Author:
  Mark Taylor

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`DEFAULT_BLOCKSIZE`
Default size of a block.

## Constructor Summary

Constructors
Constructor
Description
`BlockManager(FileChannel chan, long offset, long size, String logName, Unmapper unmapper, int blockSize)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Closes all the BufferManagers maintained by this object.
`int`
`getBlockCount()`
Returns the number of blocks used by this mananger.
`int`
`getBlockSize()`
Returns the size of blocks used by this manager.
`BufferManager`
`getBufferManager(int ib)`
Returns the BufferManager for a given block.

### Methods inherited from class Object

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

## Field Details

### DEFAULT_BLOCKSIZE

public static final int DEFAULT_BLOCKSIZE
Default size of a block.

See Also:
  - Constant Field Values

## Constructor Details

### BlockManager

public BlockManager(FileChannel chan, long offset, long size, String logName, Unmapper unmapper, int blockSize)
Constructor.

Parameters:
  `chan` - file channel
  `offset` - offset into file of start of mapped region
  `size` - length of mapped region
  `logName` - description of mapped region suitable for use in logging messages
  `unmapper` - used to unmap buffers, may be null for safety
  `blockSize` - size of each block (except the last)

## Method Details

### getBlockCount

public int getBlockCount()
Returns the number of blocks used by this mananger.

Returns:
  block count

### getBlockSize

public int getBlockSize()
Returns the size of blocks used by this manager. All blocks are the same size, except (probably) the last one, which may be shorter.

Returns:
  block size

### getBufferManager

public BufferManager getBufferManager(int ib)
Returns the BufferManager for a given block.

Parameters:
  `ib` - block index
Returns:
  buffer manager

### close

public void close()
Closes all the BufferManagers maintained by this object. Only use when no buffers will be used any more.