{"action":"created","comment":{"url":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/comments/56157661","id":56157661,"diff_hunk":"@@ -0,0 +1,109 @@\n+package util;\n+\n+import org.apache.logging.log4j.LogManager;\n+import org.apache.logging.log4j.Logger;\n+\n+import java.io.*;\n+import java.nio.file.Files;\n+import java.nio.file.Paths;\n+\n+/**\n+ * A helper that manages file I/O.\n+ */\n+public class FileHelper {\n+    private static final Logger logger = LogManager.getLogger(FileHelper.class.getName());\n+\n+    private static final String CHARSET = \"UTF-8\";\n+    private static final String EMPTY_STRING = \"\";\n+\n+    private final String configFileDirectory;\n+    private final String configFileName;\n+\n+    /**\n+     * Initialise the FileHelper with the directory and the file name\n+     * @param configFileDirectory the directory that the config file is located in\n+     * @param configFileName the name of the config file\n+     */\n+    public FileHelper(String configFileDirectory, String configFileName) {\n+        this.configFileName = configFileName;\n+        this.configFileDirectory = configFileDirectory;\n+    }\n+\n+    /**\n+     * Returns the File representation at the config file path\n+     */\n+    private File getFile() {\n+        createDirectoryIfNotExist();\n+        return new File(configFileDirectory, configFileName).getAbsoluteFile();\n+    }\n+\n+    /**\n+     * Attempts to create the config directory if it does not exist.\n+     */\n+    private void createDirectoryIfNotExist() {\n+        File directory = new File(configFileDirectory);\n+        boolean directoryExists = directory.exists() && directory.isDirectory();\n+        if (!directoryExists) {\n+            if (directory.mkdirs()) {\n+                logger.info(\"Config directory created: \" + directory.toString());\n+            } else {\n+                logger.warn(\"Could not create config file directory\");","path":"src/main/java/util/FileHelper.java","position":50,"original_position":50,"commit_id":"3c05dbf3487ab3ac722eac484ad6eacc1966f8b0","original_commit_id":"3c05dbf3487ab3ac722eac484ad6eacc1966f8b0","user":{"login":"dariusf","id":4328341,"avatar_url":"https://avatars.githubusercontent.com/u/4328341?v=3","gravatar_id":"","url":"https://api.github.com/users/dariusf","html_url":"https://github.com/dariusf","followers_url":"https://api.github.com/users/dariusf/followers","following_url":"https://api.github.com/users/dariusf/following{/other_user}","gists_url":"https://api.github.com/users/dariusf/gists{/gist_id}","starred_url":"https://api.github.com/users/dariusf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dariusf/subscriptions","organizations_url":"https://api.github.com/users/dariusf/orgs","repos_url":"https://api.github.com/users/dariusf/repos","events_url":"https://api.github.com/users/dariusf/events{/privacy}","received_events_url":"https://api.github.com/users/dariusf/received_events","type":"User","site_admin":false},"body":"If it can't be handled here, an exception should be thrown so the caller can handle it.\r\n\r\nIf we just log, then continue as if we were able to create the directory, code which comes after may run into problems.","created_at":"2016-03-15T12:59:47Z","updated_at":"2016-03-15T12:59:47Z","html_url":"https://github.com/HubTurbo/HubTurbo/pull/1276#discussion_r56157661","pull_request_url":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1276","_links":{"self":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/comments/56157661"},"html":{"href":"https://github.com/HubTurbo/HubTurbo/pull/1276#discussion_r56157661"},"pull_request":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1276"}}},"pull_request":{"url":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1276","id":60056008,"html_url":"https://github.com/HubTurbo/HubTurbo/pull/1276","diff_url":"https://github.com/HubTurbo/HubTurbo/pull/1276.diff","patch_url":"https://github.com/HubTurbo/HubTurbo/pull/1276.patch","issue_url":"https://api.github.com/repos/HubTurbo/HubTurbo/issues/1276","number":1276,"state":"open","locked":false,"title":"Generalise ConfigFileHandler to handle more than just the global config file #1272","user":{"login":"nicholaslum444","id":7083004,"avatar_url":"https://avatars.githubusercontent.com/u/7083004?v=3","gravatar_id":"","url":"https://api.github.com/users/nicholaslum444","html_url":"https://github.com/nicholaslum444","followers_url":"https://api.github.com/users/nicholaslum444/followers","following_url":"https://api.github.com/users/nicholaslum444/following{/other_user}","gists_url":"https://api.github.com/users/nicholaslum444/gists{/gist_id}","starred_url":"https://api.github.com/users/nicholaslum444/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicholaslum444/subscriptions","organizations_url":"https://api.github.com/users/nicholaslum444/orgs","repos_url":"https://api.github.com/users/nicholaslum444/repos","events_url":"https://api.github.com/users/nicholaslum444/events{/privacy}","received_events_url":"https://api.github.com/users/nicholaslum444/received_events","type":"User","site_admin":false},"body":"Fixes #1272 \r\n\r\nThe GlobalConfig class now inherits from Config.\r\nConfigFileHandler now only deals with Config type. It doesn't need to know about GlobalConfig.\r\n\r\nUpdated tests and other code to reflect the changes in the method names and signature.\r\n\r\nAlso, I have added extra test files that test that the new inheritance framework works with other types of Config subclasses. These can be deleted before the PR is merged, since the tested Config subclass does not exist in current master. It's just as proof of concept.","created_at":"2016-02-20T18:29:59Z","updated_at":"2016-03-15T12:59:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bc4dc994700a0fb82cbd7140bee03a419a668313","assignee":{"login":"HansNewbie","id":3381536,"avatar_url":"https://avatars.githubusercontent.com/u/3381536?v=3","gravatar_id":"","url":"https://api.github.com/users/HansNewbie","html_url":"https://github.com/HansNewbie","followers_url":"https://api.github.com/users/HansNewbie/followers","following_url":"https://api.github.com/users/HansNewbie/following{/other_user}","gists_url":"https://api.github.com/users/HansNewbie/gists{/gist_id}","starred_url":"https://api.github.com/users/HansNewbie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HansNewbie/subscriptions","organizations_url":"https://api.github.com/users/HansNewbie/orgs","repos_url":"https://api.github.com/users/HansNewbie/repos","events_url":"https://api.github.com/users/HansNewbie/events{/privacy}","received_events_url":"https://api.github.com/users/HansNewbie/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/HubTurbo/HubTurbo/milestones/55","html_url":"https://github.com/HubTurbo/HubTurbo/milestones/V3.24","labels_url":"https://api.github.com/repos/HubTurbo/HubTurbo/milestones/55/labels","id":1630740,"number":55,"title":"V3.24","description":"","creator":{"login":"dariusf","id":4328341,"avatar_url":"https://avatars.githubusercontent.com/u/4328341?v=3","gravatar_id":"","url":"https://api.github.com/users/dariusf","html_url":"https://github.com/dariusf","followers_url":"https://api.github.com/users/dariusf/followers","following_url":"https://api.github.com/users/dariusf/following{/other_user}","gists_url":"https://api.github.com/users/dariusf/gists{/gist_id}","starred_url":"https://api.github.com/users/dariusf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dariusf/subscriptions","organizations_url":"https://api.github.com/users/dariusf/orgs","repos_url":"https://api.github.com/users/dariusf/repos","events_url":"https://api.github.com/users/dariusf/events{/privacy}","received_events_url":"https://api.github.com/users/dariusf/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":0,"state":"open","created_at":"2016-03-08T14:59:06Z","updated_at":"2016-03-15T09:14:27Z","due_on":"2016-03-21T16:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1276/commits","review_comments_url":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1276/comments","review_comment_url":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/HubTurbo/HubTurbo/issues/1276/comments","statuses_url":"https://api.github.com/repos/HubTurbo/HubTurbo/statuses/3c05dbf3487ab3ac722eac484ad6eacc1966f8b0","head":{"label":"nicholaslum444:1272-generalise-configfilehandler","ref":"1272-generalise-configfilehandler","sha":"3c05dbf3487ab3ac722eac484ad6eacc1966f8b0","user":{"login":"nicholaslum444","id":7083004,"avatar_url":"https://avatars.githubusercontent.com/u/7083004?v=3","gravatar_id":"","url":"https://api.github.com/users/nicholaslum444","html_url":"https://github.com/nicholaslum444","followers_url":"https://api.github.com/users/nicholaslum444/followers","following_url":"https://api.github.com/users/nicholaslum444/following{/other_user}","gists_url":"https://api.github.com/users/nicholaslum444/gists{/gist_id}","starred_url":"https://api.github.com/users/nicholaslum444/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicholaslum444/subscriptions","organizations_url":"https://api.github.com/users/nicholaslum444/orgs","repos_url":"https://api.github.com/users/nicholaslum444/repos","events_url":"https://api.github.com/users/nicholaslum444/events{/privacy}","received_events_url":"https://api.github.com/users/nicholaslum444/received_events","type":"User","site_admin":false},"repo":{"id":45123547,"name":"HubTurbo","full_name":"nicholaslum444/HubTurbo","owner":{"login":"nicholaslum444","id":7083004,"avatar_url":"https://avatars.githubusercontent.com/u/7083004?v=3","gravatar_id":"","url":"https://api.github.com/users/nicholaslum444","html_url":"https://github.com/nicholaslum444","followers_url":"https://api.github.com/users/nicholaslum444/followers","following_url":"https://api.github.com/users/nicholaslum444/following{/other_user}","gists_url":"https://api.github.com/users/nicholaslum444/gists{/gist_id}","starred_url":"https://api.github.com/users/nicholaslum444/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicholaslum444/subscriptions","organizations_url":"https://api.github.com/users/nicholaslum444/orgs","repos_url":"https://api.github.com/users/nicholaslum444/repos","events_url":"https://api.github.com/users/nicholaslum444/events{/privacy}","received_events_url":"https://api.github.com/users/nicholaslum444/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nicholaslum444/HubTurbo","description":"A companion to GitHub for your desktop","fork":true,"url":"https://api.github.com/repos/nicholaslum444/HubTurbo","forks_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/forks","keys_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/teams","hooks_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/hooks","issue_events_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/issues/events{/number}","events_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/events","assignees_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/assignees{/user}","branches_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/branches{/branch}","tags_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/tags","blobs_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/git/refs{/sha}","trees_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/statuses/{sha}","languages_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/languages","stargazers_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/stargazers","contributors_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/contributors","subscribers_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/subscribers","subscription_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/subscription","commits_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/commits{/sha}","git_commits_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/git/commits{/sha}","comments_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/comments{/number}","issue_comment_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/issues/comments{/number}","contents_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/contents/{+path}","compare_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/merges","archive_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/downloads","issues_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/issues{/number}","pulls_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/pulls{/number}","milestones_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/milestones{/number}","notifications_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/labels{/name}","releases_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/releases{/id}","deployments_url":"https://api.github.com/repos/nicholaslum444/HubTurbo/deployments","created_at":"2015-10-28T15:47:51Z","updated_at":"2016-01-13T09:52:07Z","pushed_at":"2016-03-15T10:14:14Z","git_url":"git://github.com/nicholaslum444/HubTurbo.git","ssh_url":"git@github.com:nicholaslum444/HubTurbo.git","clone_url":"https://github.com/nicholaslum444/HubTurbo.git","svn_url":"https://github.com/nicholaslum444/HubTurbo","homepage":"http://hubturbo.info","size":133491,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"HubTurbo:master","ref":"master","sha":"363405c8b16d18317f9479561b2202d1cf69c949","user":{"login":"HubTurbo","id":7955871,"avatar_url":"https://avatars.githubusercontent.com/u/7955871?v=3","gravatar_id":"","url":"https://api.github.com/users/HubTurbo","html_url":"https://github.com/HubTurbo","followers_url":"https://api.github.com/users/HubTurbo/followers","following_url":"https://api.github.com/users/HubTurbo/following{/other_user}","gists_url":"https://api.github.com/users/HubTurbo/gists{/gist_id}","starred_url":"https://api.github.com/users/HubTurbo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HubTurbo/subscriptions","organizations_url":"https://api.github.com/users/HubTurbo/orgs","repos_url":"https://api.github.com/users/HubTurbo/repos","events_url":"https://api.github.com/users/HubTurbo/events{/privacy}","received_events_url":"https://api.github.com/users/HubTurbo/received_events","type":"Organization","site_admin":false},"repo":{"id":20919534,"name":"HubTurbo","full_name":"HubTurbo/HubTurbo","owner":{"login":"HubTurbo","id":7955871,"avatar_url":"https://avatars.githubusercontent.com/u/7955871?v=3","gravatar_id":"","url":"https://api.github.com/users/HubTurbo","html_url":"https://github.com/HubTurbo","followers_url":"https://api.github.com/users/HubTurbo/followers","following_url":"https://api.github.com/users/HubTurbo/following{/other_user}","gists_url":"https://api.github.com/users/HubTurbo/gists{/gist_id}","starred_url":"https://api.github.com/users/HubTurbo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HubTurbo/subscriptions","organizations_url":"https://api.github.com/users/HubTurbo/orgs","repos_url":"https://api.github.com/users/HubTurbo/repos","events_url":"https://api.github.com/users/HubTurbo/events{/privacy}","received_events_url":"https://api.github.com/users/HubTurbo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/HubTurbo/HubTurbo","description":"A companion to GitHub for your desktop","fork":false,"url":"https://api.github.com/repos/HubTurbo/HubTurbo","forks_url":"https://api.github.com/repos/HubTurbo/HubTurbo/forks","keys_url":"https://api.github.com/repos/HubTurbo/HubTurbo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HubTurbo/HubTurbo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HubTurbo/HubTurbo/teams","hooks_url":"https://api.github.com/repos/HubTurbo/HubTurbo/hooks","issue_events_url":"https://api.github.com/repos/HubTurbo/HubTurbo/issues/events{/number}","events_url":"https://api.github.com/repos/HubTurbo/HubTurbo/events","assignees_url":"https://api.github.com/repos/HubTurbo/HubTurbo/assignees{/user}","branches_url":"https://api.github.com/repos/HubTurbo/HubTurbo/branches{/branch}","tags_url":"https://api.github.com/repos/HubTurbo/HubTurbo/tags","blobs_url":"https://api.github.com/repos/HubTurbo/HubTurbo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HubTurbo/HubTurbo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HubTurbo/HubTurbo/git/refs{/sha}","trees_url":"https://api.github.com/repos/HubTurbo/HubTurbo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HubTurbo/HubTurbo/statuses/{sha}","languages_url":"https://api.github.com/repos/HubTurbo/HubTurbo/languages","stargazers_url":"https://api.github.com/repos/HubTurbo/HubTurbo/stargazers","contributors_url":"https://api.github.com/repos/HubTurbo/HubTurbo/contributors","subscribers_url":"https://api.github.com/repos/HubTurbo/HubTurbo/subscribers","subscription_url":"https://api.github.com/repos/HubTurbo/HubTurbo/subscription","commits_url":"https://api.github.com/repos/HubTurbo/HubTurbo/commits{/sha}","git_commits_url":"https://api.github.com/repos/HubTurbo/HubTurbo/git/commits{/sha}","comments_url":"https://api.github.com/repos/HubTurbo/HubTurbo/comments{/number}","issue_comment_url":"https://api.github.com/repos/HubTurbo/HubTurbo/issues/comments{/number}","contents_url":"https://api.github.com/repos/HubTurbo/HubTurbo/contents/{+path}","compare_url":"https://api.github.com/repos/HubTurbo/HubTurbo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HubTurbo/HubTurbo/merges","archive_url":"https://api.github.com/repos/HubTurbo/HubTurbo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HubTurbo/HubTurbo/downloads","issues_url":"https://api.github.com/repos/HubTurbo/HubTurbo/issues{/number}","pulls_url":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls{/number}","milestones_url":"https://api.github.com/repos/HubTurbo/HubTurbo/milestones{/number}","notifications_url":"https://api.github.com/repos/HubTurbo/HubTurbo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HubTurbo/HubTurbo/labels{/name}","releases_url":"https://api.github.com/repos/HubTurbo/HubTurbo/releases{/id}","deployments_url":"https://api.github.com/repos/HubTurbo/HubTurbo/deployments","created_at":"2014-06-17T10:35:39Z","updated_at":"2016-01-13T06:03:59Z","pushed_at":"2016-03-15T11:14:45Z","git_url":"git://github.com/HubTurbo/HubTurbo.git","ssh_url":"git@github.com:HubTurbo/HubTurbo.git","clone_url":"https://github.com/HubTurbo/HubTurbo.git","svn_url":"https://github.com/HubTurbo/HubTurbo","homepage":"http://hubturbo.info","size":134968,"stargazers_count":15,"watchers_count":15,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":30,"mirror_url":null,"open_issues_count":193,"forks":30,"open_issues":193,"watchers":15,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1276"},"html":{"href":"https://github.com/HubTurbo/HubTurbo/pull/1276"},"issue":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/issues/1276"},"comments":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/issues/1276/comments"},"review_comments":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1276/comments"},"review_comment":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1276/commits"},"statuses":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/statuses/3c05dbf3487ab3ac722eac484ad6eacc1966f8b0"}}}}