L2Properties.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package net.sf.l2j.util;
  16. import java.io.File;
  17. import java.io.FileInputStream;
  18. import java.io.IOException;
  19. import java.io.InputStream;
  20. import java.io.Reader;
  21. import java.util.Properties;
  22. import java.util.logging.Logger;
  23. /**
  24. * @author Noctarius
  25. */
  26. public final class L2Properties extends Properties
  27. {
  28. private static final long serialVersionUID = 1L;
  29. private static Logger _log = Logger.getLogger(L2Properties.class.getName());
  30. public L2Properties() { }
  31. public L2Properties(String name) throws IOException
  32. {
  33. load(new FileInputStream(name));
  34. }
  35. public L2Properties(File file) throws IOException
  36. {
  37. load(new FileInputStream(file));
  38. }
  39. public L2Properties(InputStream inStream) throws IOException
  40. {
  41. load(inStream);
  42. }
  43. public L2Properties(Reader reader) throws IOException
  44. {
  45. load(reader);
  46. }
  47. public void load(String name) throws IOException
  48. {
  49. load(new FileInputStream(name));
  50. }
  51. public void load(File file) throws IOException
  52. {
  53. load(new FileInputStream(file));
  54. }
  55. @Override
  56. public void load(InputStream inStream) throws IOException
  57. {
  58. try
  59. {
  60. super.load(inStream);
  61. }
  62. finally
  63. {
  64. inStream.close();
  65. }
  66. }
  67. @Override
  68. public void load(Reader reader) throws IOException
  69. {
  70. try
  71. {
  72. super.load(reader);
  73. }
  74. finally
  75. {
  76. reader.close();
  77. }
  78. }
  79. @Override
  80. public String getProperty(String key)
  81. {
  82. String property = super.getProperty(key);
  83. if (property == null)
  84. {
  85. _log.info("L2Properties: Missing property for key - " + key);
  86. return null;
  87. }
  88. return property.trim();
  89. }
  90. @Override
  91. public String getProperty(String key, String defaultValue)
  92. {
  93. String property = super.getProperty(key, defaultValue);
  94. if (property == null)
  95. {
  96. _log.warning("L2Properties: Missing defaultValue for key - " + key);
  97. return null;
  98. }
  99. return property.trim();
  100. }
  101. }