Class FileIndex

java.lang.Object
uk.co.sculptor.kflibjava.FileIndex
All Implemented Interfaces:
AutoCloseable

public class FileIndex extends Object implements AutoCloseable

Represents one KeyedFile index (main or secondary). Can only be created from one of the KeyedFile constructors and accessed via the KeyedFile.getIndex(java.lang.String)

Note: This class implements the AutoCloseable interface, meaning that an object may hold resources (such as file or socket handles) until it is closed. The close() method of an AutoCloseable object is called automatically when exiting a try-with-resources block for which the object has been declared in the resource specification header. This construction ensures prompt release, avoiding resource exhaustion exceptions and errors that may otherwise occur.
Author:
Marcos Gutierrez Batz
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Close All the objects hanging from the FileIndex.
    int
    Count the number of records/keys in a file/index.
    void
    Find first record with matching key, locking the record and not waiting when the record is in use.
    void
    Find first record with matching key not locking the record.
    void
    Find first record with matching key, locking the record and waiting when the record is in use.
    Returns current FileIndex name
    int
    Returns current FileIndex keylen
    int
    Returns current FileIndex number of keys
    boolean
    Returns whether the current FileIndex is the main KeyedFile index
    boolean
    Returns whether the current FileIndex permits nulls
    void
    Find next record with matching key, locking the record and not waiting when the record is in use.
    void
    Find next record with matching key not locking the record.
    void
    Find next record with matching key, locking the record and waiting when the record is in use.
    void
    Read next record, locking the record and not waiting when the record is in use.
    void
    Read next key.
    void
    Read next record not locking the record.
    void
    Read next record, locking the record and waiting when the record is in use.
    void
    Read previous record, locking the record and not waiting when the record is in use.
    void
    Read previous key.
    void
    Read previous record not locking the record.
    void
    Read previous record, locking the record and waiting when the record is in use.
    void
    Read record for given key, locking the record and not waiting when the record is in use.
    void
    Read key.
    void
    Read record for given key not locking the record.
    void
    Read record for given key, locking the record and waiting when the record is in use.
    void
    Rewind (initialise the key contents)
    void
    Test key exists.
    void
    Wind (initialise the key contents)

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • close

      public void close()
      Close All the objects hanging from the FileIndex.
      Specified by:
      close in interface AutoCloseable
    • count

      public int count() throws IOException, KfException
      Count the number of records/keys in a file/index.
      Returns:
      the number of records.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server process.
    • find

      public void find() throws IOException, KfException
      Find first record with matching key, locking the record and not waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server process.
    • findu

      public void findu() throws IOException, KfException
      Find first record with matching key not locking the record.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server process.
    • findw

      public void findw() throws IOException, KfException
      Find first record with matching key, locking the record and waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server process.
    • getIndexName

      public String getIndexName()
      Returns current FileIndex name
      Returns:
      The indexName
    • getKeyLength

      public int getKeyLength()
      Returns current FileIndex keylen
      Returns:
      The keylen
    • getNumberOfKeys

      public int getNumberOfKeys()
      Returns current FileIndex number of keys
      Returns:
      The number of keys
    • isMainIndex

      public boolean isMainIndex()
      Returns whether the current FileIndex is the main KeyedFile index
      Returns:
      true when that FileIndex is the main index of the KeyedFile
    • isNoNulls

      public boolean isNoNulls()
      Returns whether the current FileIndex permits nulls
      Returns:
      true if no nulls
    • match

      public void match() throws IOException, KfException
      Find next record with matching key, locking the record and not waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server process.
    • matchu

      public void matchu() throws IOException, KfException
      Find next record with matching key not locking the record.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server process.
    • matchw

      public void matchw() throws IOException, KfException
      Find next record with matching key, locking the record and waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server process.
    • next

      public void next() throws IOException, KfException
      Read next record, locking the record and not waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server process.
    • nextKey

      public void nextKey() throws IOException, KfException
      Read next key.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server process.
    • nextu

      public void nextu() throws IOException, KfException
      Read next record not locking the record.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server process.
    • nextw

      public void nextw() throws IOException, KfException
      Read next record, locking the record and waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server process.
    • prev

      public void prev() throws IOException, KfException
      Read previous record, locking the record and not waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server process.
    • prevKey

      public void prevKey() throws IOException, KfException
      Read previous key.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server process.
    • prevu

      public void prevu() throws IOException, KfException
      Read previous record not locking the record.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server process.
    • prevw

      public void prevw() throws IOException, KfException
      Read previous record, locking the record and waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server process.
    • read

      public void read() throws IOException, KfException
      Read record for given key, locking the record and not waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server process.
    • readKey

      public void readKey() throws IOException, KfException
      Read key.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server process.
    • readu

      public void readu() throws IOException, KfException
      Read record for given key not locking the record.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server process.
    • readw

      public void readw() throws IOException, KfException
      Read record for given key, locking the record and waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server process.
    • rewind

      public void rewind() throws KfException
      Rewind (initialise the key contents)
      Throws:
      KfException - Any error on the KfServer protocol or on the server process.
    • testKey

      public void testKey() throws IOException, KfException
      Test key exists.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server process.
    • wind

      public void wind() throws KfException
      Wind (initialise the key contents)
      Throws:
      KfException - Any error on the KfServer protocol or on the server process.