Package org.wso2.carbon.logging.appender.http.utils.queue

## Class QueueBlock

- java.lang.Object
- - org.wso2.carbon.logging.appender.http.utils.queue.QueueBlock

-     public class QueueBlock
      extends Object

  This class represents a block of the queue. Each block is a file in the disk.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `QueueBlock​(String queueDirectoryPath, String fileName, long length)` | This constructor is to be used when creating a new block.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `append​(byte[] data)` | Appends the given data to the block.
    `boolean` | `canAppend​(int length)` | Returns if the block can append the given length of data.
    `void` | `close()` | Closes the block.
    `byte[]` | `consume()` | Consumes the next item in the block.
    `void` | `delete()` | Deletes the block.
    `String` | `getFileName()` | Returns the name of the file relevant to the block.
    `boolean` | `hasUnprocessedItems()` | Returns if the block has unprocessed items.
    `static void` | `initClass​(String queueDirectoryPath)` | This method is to be used when initializing the class.
    `static QueueBlock` | `loadBlock​(String directoryPath, String fileName)` | This method is to be used when loading the next queue block to memory.
    `byte[]` | `peekNextItem()` | Peeks the next item in the block without consuming.
    `void` | `setValuesToDefault()` | Resets the block.

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

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

- - ### Constructor Detail

    - #### QueueBlock

          public QueueBlock​(String queueDirectoryPath,
                            String fileName,
                            long length)
                     throws PersistentQueueException

      This constructor is to be used when creating a new block.
      Parameters:
        `queueDirectoryPath` - path of the queue directory
        `fileName` - name of the file
        `length` - length of the file
      Throws:
        `PersistentQueueException` - if an error occurs while creating the block.

  - ### Method Detail

    - #### initClass

          public static void initClass​(String queueDirectoryPath)

      This method is to be used when initializing the class.
      Parameters:
        `queueDirectoryPath` - path of the queue directory

    - #### loadBlock

          public static QueueBlock loadBlock​(String directoryPath,
                                             String fileName)
                                      throws PersistentQueueException

      This method is to be used when loading the next queue block to memory.
      Parameters:
        `directoryPath` - path of the queue directory
        `fileName` - name of the file
      Returns:
        QueueBlock next queue block
      Throws:
        `PersistentQueueException` - if an error occurs while creating the block.

    - #### canAppend

          public boolean canAppend​(int length)

      Returns if the block can append the given length of data.
      Parameters:
        `length` - length of the data
      Returns:
        boolean if the block can append the given length of data.

    - #### hasUnprocessedItems

          public boolean hasUnprocessedItems()

      Returns if the block has unprocessed items.
      Returns:
        boolean if the block has unprocessed items.

    - #### append

          public boolean append​(byte[] data)

      Appends the given data to the block.
      Parameters:
        `data` - byte stream to be appended
      Returns:
        boolean if the append operation was successful.

    - #### consume

          public byte[] consume()

      Consumes the next item in the block.
      Returns:
        byte stream of the next item

    - #### peekNextItem

          public byte[] peekNextItem()

      Peeks the next item in the block without consuming.
      Returns:
        byte stream of the next item

    - #### delete

          public void delete()
                      throws PersistentQueueException

      Deletes the block.
      Throws:
        `PersistentQueueException` - if an error occurs while deleting the block.

    - #### getFileName

          public String getFileName()

      Returns the name of the file relevant to the block.
      Returns:
        name of the block

    - #### close

          public void close()
                     throws PersistentQueueException

      Closes the block.
      Throws:
        `PersistentQueueException` - if an error occurs while closing the block.

    - #### setValuesToDefault

          public void setValuesToDefault()

      Resets the block.