Class SeparatedValuesFile

java.lang.Object
org.forgerock.openig.text.SeparatedValuesFile

public class SeparatedValuesFile extends Object
Allows records to be retrieved from a delimiter-separated file using key and value. Once constructed, an instance of this class is thread-safe, meaning the object can be long-lived, and multiple concurrent calls to getRecord is fully supported.
  • Constructor Details

    • SeparatedValuesFile

      public SeparatedValuesFile(File file)
      Builds a new SeparatedValuesFile reading the given file using a the Separators.COMMA separator specification and UTF-8 charset. This constructor consider the file has a header line.

      It is equivalent to call: new SeparatedValuesFile(file, "UTF-8");

      Parameters:
      file - file to read from
      See Also:
    • SeparatedValuesFile

      public SeparatedValuesFile(File file, Charset charset)
      Builds a new SeparatedValuesFile reading the given file using a the Separators.COMMA separator specification. This constructor consider the file has a header line.

      It is equivalent to call: new SeparatedValuesFile(file, charset, Separators.COMMA.getSeparator());

      Parameters:
      file - file to read from
      charset - Charset of the file (non-null)
      See Also:
    • SeparatedValuesFile

      public SeparatedValuesFile(File file, Charset charset, Separator separator)
      Builds a new SeparatedValuesFile reading the given file. This constructor consider the file has a header line.

      It is equivalent to call: new SeparatedValuesFile(file, charset, separator, true);

      Parameters:
      file - file to read from
      charset - Charset of the file (non-null)
      separator - separator specification
      See Also:
    • SeparatedValuesFile

      public SeparatedValuesFile(File file, Charset charset, Separator separator, boolean header)
      Builds a new SeparatedValuesFile reading the given file.
      Parameters:
      file - file to read from
      charset - Charset of the file (non-null)
      separator - separator specification
      header - does the file has a header first line ?
  • Method Details

    • getFields

      public List<String> getFields()
      Returns the explicit field keys in the order they appear in a record, overriding any existing field header, or empty to use field header.
      Returns:
      the explicit field keys in the order they appear in a record
    • getRecord

      public Map<String,String> getRecord(String key, String value) throws IOException
      Returns a record from the file where the specified key is equal to the specified value.
      Parameters:
      key - the key to use to lookup the record
      value - the value that the key should have to find a matching record.
      Returns:
      the record with the matching value, or null if no such record could be found.
      Throws:
      IOException - if an I/O exception occurs.