Class PropertyFile

java.lang.Object
com.peterphi.std.io.PropertyFile

public class PropertyFile extends Object
  • Field Details

    • f

      protected File f
    • readOnly

      protected boolean readOnly
    • caseSensitive

      protected boolean caseSensitive
    • forceNameValueDelimiterWhitespace

      protected boolean forceNameValueDelimiterWhitespace
    • entries

      protected List<PropertyFile.Entry> entries
    • vars

    • dirty

      protected boolean dirty
  • Constructor Details

  • Method Details

    • find

      public static PropertyFile find()
    • find

      public static PropertyFile find(String fileName)
    • find

      public static PropertyFile find(ClassLoader classloader, String... fileNames)
      Find a property file
      Parameters:
      classloader -
      fileNames -
      Returns:
    • fromString

      public static PropertyFile fromString(String contents)
    • fromString

      public static PropertyFile fromString(String contents, String filename)
    • openResource

      public static PropertyFile openResource(ClassLoader classloader, URL resource, String fileName)
    • findAll

      public static PropertyFile[] findAll(String name)
      Find all property files by the name name by searching the classloader that owns PropertyFile
      Parameters:
      name -
      Returns:
    • findAll

      public static PropertyFile[] findAll(ClassLoader loader, String name)
      Find all property files by the name name by searching the specified classloader
      Parameters:
      loader -
      name -
      Returns:
    • toProperties

      public Properties toProperties()
      Converts the name/value pairs stored in this PropertyFile to the Java Properties propertyfile type
      Returns:
      a Properties representing the data (but not the comments, etc) in this file
    • toMap

      public Map<String,String> toMap()
      Converts the name/value pairs stored in this PropertyFile to a Map of key/value pairs
      Returns:
      a Map representing the data (but not the comments, etc) in this file
    • getCaseSensitive

      public boolean getCaseSensitive()
    • getFile

      public File getFile()
    • setFile

      public void setFile(File file)
    • setForceNameValueDelimiterWhitespace

      public void setForceNameValueDelimiterWhitespace(boolean value)
    • getForceNameValueDelimiterWhitespace

      public boolean getForceNameValueDelimiterWhitespace()
    • load

      public void load() throws IOException
      Throws:
      IOException
    • load

      public void load(Map<String,String> map)
    • load

      public void load(Properties p)
    • load

      public void load(File file) throws IOException
      Throws:
      IOException
    • load

      public void load(InputStream is) throws IOException
      Throws:
      IOException
    • save

      public void save() throws IOException
      Throws:
      IOException
    • save

      public void save(File f, String comment) throws IOException
      Throws:
      IOException
    • save

      public void save(OutputStream os) throws IOException
      Throws:
      IOException
    • save

      public void save(String comment) throws IOException
      Throws:
      IOException
    • save

      public void save(String comment, OutputStream os) throws IOException
      Throws:
      IOException
    • makeReadOnly

      public void makeReadOnly()
      Make this PropertyFile object read-only
    • containsKey

      public boolean containsKey(String name)
    • get

      public String get(String name)
    • get

      public String get(String name, String defaultValue)
    • get

      public int get(String name, int defaultValue)
    • get

      public long get(String name, long defaultValue)
    • get

      public boolean get(String name, boolean defaultValue)
    • getBoolean

      public boolean getBoolean(String name, boolean defaultValue)
    • getURI

      public URI getURI(String name, String defaultValue)
    • set

      public String set(String name, String value)
    • set

      public String set(String name, long value)
    • set

      public String set(String name, int value)
    • remove

      public void remove(String name)
    • clear

      public void clear()
    • keySet

      public Set<String> keySet()
    • keyIterator

      public Iterator<String> keyIterator()
    • getLineCount

      public int getLineCount()
    • getVariableCount

      public int getVariableCount()
    • hook_changed

      protected void hook_changed(String name, String oldValue, String newValue)
    • hook_added

      protected void hook_added(String name, String newValue)
    • hook_removed

      protected void hook_removed(String name)
    • hook_cleared

      protected void hook_cleared()
    • hook_loaded

      protected void hook_loaded()
    • hook_saved

      protected void hook_saved()
    • load

      public void load(Reader r) throws IOException
      Throws:
      IOException
    • save

      public void save(String comment, Writer w) throws IOException
      Throws:
      IOException
    • _clear

      protected void _clear()
    • _set

      protected String _set(String name, String value)
    • _get

      protected String _get(String name, String defaultValue)
    • _get_core

      protected String _get_core(String name, String defaultValue)
    • _contains

      protected boolean _contains(String name)
    • _rm

      protected void _rm(String name)
    • readOnly

      public static PropertyFile readOnly(File filename) throws IOException
      Creates a read-only version of a property file
      Fails if the file does not exist.
      Parameters:
      filename - the filename to load
      Returns:
      Throws:
      IOException - if the file cannot be loaded