package ircbot;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class API {

    /**
     * Get the username of the client specified in the <i>credentials.properties<i>
     * @return IRC username
     * @throws IOException
     */
    public static String getUsername() throws IOException {
        File file = new File("credentials.properties");
        FileInputStream fileInput = new FileInputStream(file);
        Properties properties = new Properties();
        properties.load(fileInput);
        fileInput.close();
        return properties.getProperty("username");
    }

    /**
     * Get the NickServ password specified in the <i>credentials.properties<i>
     * @return NickServ password
     * @throws IOException
     */
    public static String getAuthPass() throws IOException {
        File file = new File("credentials.properties");
        FileInputStream fileInput = new FileInputStream(file);
        Properties properties = new Properties();
        properties.load(fileInput);
        fileInput.close();
        return properties.getProperty("pass");
    }

    /**
     * Get the channel specified in the <i>credentials.properties</i>
     * @return Channel name
     * @throws IOException
     */
    public static String getChannel() throws IOException {
        File file = new File("credentials.properties");
        FileInputStream fileInput = new FileInputStream(file);
        Properties properties = new Properties();
        properties.load(fileInput);
        fileInput.close();
        return properties.getProperty("channel");
    }

}

@@ -364,36 +364,35 @@
         
-File file = new File
+return readProperty
 (%22creden
@@ -412,186 +412,244 @@
 ies%22
+, %22username%22
 );%0A    
+%7D%0A%0A
     
-FileInputStream fileInput = new FileInputStream(file);%0A        Properties properties = new Properties();%0A        properties.load(fileInput);%0A        fileInput.close();
+/**%0A     * Get the NickServ password specified in the %3Ci%3Ecredentials.properties%3Ci%3E%0A     * @return NickServ password%0A     * @throws IOException%0A     */%0A    public static String getAuthPass() throws IOException %7B
 %0A   
@@ -664,40 +664,52 @@
 urn 
-p
+readP
 ropert
-ies.getProperty(%22username
+y(%22credentials.properties%22, %22pass
 %22);%0A
@@ -738,33 +738,23 @@
 Get the 
-NickServ password
+channel
  specifi
@@ -781,32 +781,33 @@
 ials.properties%3C
+/
 i%3E%0A     * @retur
@@ -808,33 +808,28 @@
 @return 
-NickServ password
+Channel name
 %0A     * 
@@ -880,32 +880,31 @@
 c String get
-AuthPass
+Channel
 () throws IO
@@ -923,36 +923,35 @@
         
-File file = new File
+return readProperty
 (%22creden
@@ -971,346 +971,247 @@
 ies%22
+, %22channel%22
 );%0A    
+%7D%0A%0A
     
-FileInputStream fileInput = new FileInputStream(file);%0A        Properties properties = new Properties();%0A        properties.load(fileInput);%0A        fileInput.close();%0A        return properties.getProperty(%22pass%22);%0A    %7D%0A%0A    /**%0A     * Get the channel specified in the %3Ci%3Ecredentials.properties%3C/i%3E%0A     * @return Channel name
+/**%0A     * Read from a properties file and get property value%0A     * @param fileName      filename of .properties file%0A     * @param property      property key%0A     * @return              property key, default null
 %0A   
@@ -1263,35 +1263,69 @@
 atic String 
-getChannel(
+readProperty(String fileName, String property
 ) throws IOE
@@ -1368,32 +1368,16 @@
 ile(
-%22credentials.properties%22
+fileName
 );%0A 
@@ -1465,17 +1465,16 @@
 properti
-e
 s = new 
@@ -1503,17 +1503,16 @@
 properti
-e
 s.load(f
@@ -1572,17 +1572,16 @@
 properti
-e
 s.getPro
@@ -1586,25 +1586,30 @@
 roperty(
-%22channel%22
+property, null
 );%0A    %7D

Rework .properties file reading