{"action":"created","comment":{"url":"https://api.github.com/repos/teamed/quiz/pulls/comments/56459591","id":56459591,"diff_hunk":"@@ -2,41 +2,55 @@\n import java.io.FileInputStream;\n import java.io.FileOutputStream;\n import java.io.IOException;\n-/**\n- * This class is thread safe.\n- */\n+\n+\n public class Parser {\n   private File file;\n-  public synchronized void setFile(File f) {\n+  private static int UNICODE_IDENTIFIER = 0x80;\n+\n+  public final synchronized void setFile(File f) {\n     file = f;\n   }\n-  public synchronized File getFile() {\n+\n+  public final synchronized File getFile() {\n     return file;\n   }\n-  public String getContent() throws IOException {\n-    FileInputStream i = new FileInputStream(file);\n-    String output = \"\";\n-    int data;\n-    while ((data = i.read()) > 0) {\n-      output += (char) data;","path":"Parser.java","position":27,"original_position":27,"commit_id":"823d1d6e6a2f24d37bf7258f034ee296ddd63b6b","original_commit_id":"823d1d6e6a2f24d37bf7258f034ee296ddd63b6b","user":{"login":"commandini","id":11979235,"avatar_url":"https://avatars.githubusercontent.com/u/11979235?v=3","gravatar_id":"","url":"https://api.github.com/users/commandini","html_url":"https://github.com/commandini","followers_url":"https://api.github.com/users/commandini/followers","following_url":"https://api.github.com/users/commandini/following{/other_user}","gists_url":"https://api.github.com/users/commandini/gists{/gist_id}","starred_url":"https://api.github.com/users/commandini/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/commandini/subscriptions","organizations_url":"https://api.github.com/users/commandini/orgs","repos_url":"https://api.github.com/users/commandini/repos","events_url":"https://api.github.com/users/commandini/events{/privacy}","received_events_url":"https://api.github.com/users/commandini/received_events","type":"User","site_admin":false},"body":"The methods below (getContent()and getContentWithoutUnicode()) can be removed and instead a single method like this would be better:\r\n\r\n  public final String getContent(File file, String encoding) throws IOException {\r\n    synchronized (file) {\r\n      StringBuilder builder = new StringBuilder();\r\n      BufferedReader in =\r\n          new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding));\r\n\r\n      String str;\r\n\r\n      while ((str = in.readLine()) != null) {\r\n        builder.append(str);\r\n      }\r\n      return builder.toString();\r\n    }\r\n  }\r\n\r\nWhile saving a String to a File, again we should give an encoding as parameter.\r\n\r\nReading/writing should always be done with encoding.","created_at":"2016-03-17T06:08:51Z","updated_at":"2016-03-17T06:08:51Z","html_url":"https://github.com/teamed/quiz/pull/371#discussion_r56459591","pull_request_url":"https://api.github.com/repos/teamed/quiz/pulls/371","_links":{"self":{"href":"https://api.github.com/repos/teamed/quiz/pulls/comments/56459591"},"html":{"href":"https://github.com/teamed/quiz/pull/371#discussion_r56459591"},"pull_request":{"href":"https://api.github.com/repos/teamed/quiz/pulls/371"}}},"pull_request":{"url":"https://api.github.com/repos/teamed/quiz/pulls/371","id":62682557,"html_url":"https://github.com/teamed/quiz/pull/371","diff_url":"https://github.com/teamed/quiz/pull/371.diff","patch_url":"https://github.com/teamed/quiz/pull/371.patch","issue_url":"https://api.github.com/repos/teamed/quiz/issues/371","number":371,"state":"open","locked":false,"title":"Changes made:","user":{"login":"commandini","id":11979235,"avatar_url":"https://avatars.githubusercontent.com/u/11979235?v=3","gravatar_id":"","url":"https://api.github.com/users/commandini","html_url":"https://github.com/commandini","followers_url":"https://api.github.com/users/commandini/followers","following_url":"https://api.github.com/users/commandini/following{/other_user}","gists_url":"https://api.github.com/users/commandini/gists{/gist_id}","starred_url":"https://api.github.com/users/commandini/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/commandini/subscriptions","organizations_url":"https://api.github.com/users/commandini/orgs","repos_url":"https://api.github.com/users/commandini/repos","events_url":"https://api.github.com/users/commandini/events{/privacy}","received_events_url":"https://api.github.com/users/commandini/received_events","type":"User","site_admin":false},"body":"Defined magic hex number (0x80) as a constant and used it.\r\nMade public methods final to allow a better design and prevent classes overriding the default behaviour.\r\nFile reading/writing was not thread-safe, used synchronized blocks to do operations safely on file arguments.\r\nJVM String pool would be potentially polluted with unnecessary String creations in the original code, used StringBuilder instead.","created_at":"2016-03-13T20:40:15Z","updated_at":"2016-03-17T06:08:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8a2cbc956bfd3ea08fe435f00354ceb06ed11354","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/teamed/quiz/pulls/371/commits","review_comments_url":"https://api.github.com/repos/teamed/quiz/pulls/371/comments","review_comment_url":"https://api.github.com/repos/teamed/quiz/pulls/comments{/number}","comments_url":"https://api.github.com/repos/teamed/quiz/issues/371/comments","statuses_url":"https://api.github.com/repos/teamed/quiz/statuses/823d1d6e6a2f24d37bf7258f034ee296ddd63b6b","head":{"label":"commandini:master","ref":"master","sha":"823d1d6e6a2f24d37bf7258f034ee296ddd63b6b","user":{"login":"commandini","id":11979235,"avatar_url":"https://avatars.githubusercontent.com/u/11979235?v=3","gravatar_id":"","url":"https://api.github.com/users/commandini","html_url":"https://github.com/commandini","followers_url":"https://api.github.com/users/commandini/followers","following_url":"https://api.github.com/users/commandini/following{/other_user}","gists_url":"https://api.github.com/users/commandini/gists{/gist_id}","starred_url":"https://api.github.com/users/commandini/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/commandini/subscriptions","organizations_url":"https://api.github.com/users/commandini/orgs","repos_url":"https://api.github.com/users/commandini/repos","events_url":"https://api.github.com/users/commandini/events{/privacy}","received_events_url":"https://api.github.com/users/commandini/received_events","type":"User","site_admin":false},"repo":{"id":53806404,"name":"quiz","full_name":"commandini/quiz","owner":{"login":"commandini","id":11979235,"avatar_url":"https://avatars.githubusercontent.com/u/11979235?v=3","gravatar_id":"","url":"https://api.github.com/users/commandini","html_url":"https://github.com/commandini","followers_url":"https://api.github.com/users/commandini/followers","following_url":"https://api.github.com/users/commandini/following{/other_user}","gists_url":"https://api.github.com/users/commandini/gists{/gist_id}","starred_url":"https://api.github.com/users/commandini/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/commandini/subscriptions","organizations_url":"https://api.github.com/users/commandini/orgs","repos_url":"https://api.github.com/users/commandini/repos","events_url":"https://api.github.com/users/commandini/events{/privacy}","received_events_url":"https://api.github.com/users/commandini/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/commandini/quiz","description":"Quiz","fork":true,"url":"https://api.github.com/repos/commandini/quiz","forks_url":"https://api.github.com/repos/commandini/quiz/forks","keys_url":"https://api.github.com/repos/commandini/quiz/keys{/key_id}","collaborators_url":"https://api.github.com/repos/commandini/quiz/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/commandini/quiz/teams","hooks_url":"https://api.github.com/repos/commandini/quiz/hooks","issue_events_url":"https://api.github.com/repos/commandini/quiz/issues/events{/number}","events_url":"https://api.github.com/repos/commandini/quiz/events","assignees_url":"https://api.github.com/repos/commandini/quiz/assignees{/user}","branches_url":"https://api.github.com/repos/commandini/quiz/branches{/branch}","tags_url":"https://api.github.com/repos/commandini/quiz/tags","blobs_url":"https://api.github.com/repos/commandini/quiz/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/commandini/quiz/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/commandini/quiz/git/refs{/sha}","trees_url":"https://api.github.com/repos/commandini/quiz/git/trees{/sha}","statuses_url":"https://api.github.com/repos/commandini/quiz/statuses/{sha}","languages_url":"https://api.github.com/repos/commandini/quiz/languages","stargazers_url":"https://api.github.com/repos/commandini/quiz/stargazers","contributors_url":"https://api.github.com/repos/commandini/quiz/contributors","subscribers_url":"https://api.github.com/repos/commandini/quiz/subscribers","subscription_url":"https://api.github.com/repos/commandini/quiz/subscription","commits_url":"https://api.github.com/repos/commandini/quiz/commits{/sha}","git_commits_url":"https://api.github.com/repos/commandini/quiz/git/commits{/sha}","comments_url":"https://api.github.com/repos/commandini/quiz/comments{/number}","issue_comment_url":"https://api.github.com/repos/commandini/quiz/issues/comments{/number}","contents_url":"https://api.github.com/repos/commandini/quiz/contents/{+path}","compare_url":"https://api.github.com/repos/commandini/quiz/compare/{base}...{head}","merges_url":"https://api.github.com/repos/commandini/quiz/merges","archive_url":"https://api.github.com/repos/commandini/quiz/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/commandini/quiz/downloads","issues_url":"https://api.github.com/repos/commandini/quiz/issues{/number}","pulls_url":"https://api.github.com/repos/commandini/quiz/pulls{/number}","milestones_url":"https://api.github.com/repos/commandini/quiz/milestones{/number}","notifications_url":"https://api.github.com/repos/commandini/quiz/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/commandini/quiz/labels{/name}","releases_url":"https://api.github.com/repos/commandini/quiz/releases{/id}","deployments_url":"https://api.github.com/repos/commandini/quiz/deployments","created_at":"2016-03-13T20:35:56Z","updated_at":"2016-03-13T20:38:49Z","pushed_at":"2016-03-13T20:38:49Z","git_url":"git://github.com/commandini/quiz.git","ssh_url":"git@github.com:commandini/quiz.git","clone_url":"https://github.com/commandini/quiz.git","svn_url":"https://github.com/commandini/quiz","homepage":"http://www.teamed.io","size":3,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"teamed:master","ref":"master","sha":"611462ec25a8ab9ff8b0b50c6cf528d6ed87be21","user":{"login":"teamed","id":7436563,"avatar_url":"https://avatars.githubusercontent.com/u/7436563?v=3","gravatar_id":"","url":"https://api.github.com/users/teamed","html_url":"https://github.com/teamed","followers_url":"https://api.github.com/users/teamed/followers","following_url":"https://api.github.com/users/teamed/following{/other_user}","gists_url":"https://api.github.com/users/teamed/gists{/gist_id}","starred_url":"https://api.github.com/users/teamed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teamed/subscriptions","organizations_url":"https://api.github.com/users/teamed/orgs","repos_url":"https://api.github.com/users/teamed/repos","events_url":"https://api.github.com/users/teamed/events{/privacy}","received_events_url":"https://api.github.com/users/teamed/received_events","type":"Organization","site_admin":false},"repo":{"id":30189312,"name":"quiz","full_name":"teamed/quiz","owner":{"login":"teamed","id":7436563,"avatar_url":"https://avatars.githubusercontent.com/u/7436563?v=3","gravatar_id":"","url":"https://api.github.com/users/teamed","html_url":"https://github.com/teamed","followers_url":"https://api.github.com/users/teamed/followers","following_url":"https://api.github.com/users/teamed/following{/other_user}","gists_url":"https://api.github.com/users/teamed/gists{/gist_id}","starred_url":"https://api.github.com/users/teamed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teamed/subscriptions","organizations_url":"https://api.github.com/users/teamed/orgs","repos_url":"https://api.github.com/users/teamed/repos","events_url":"https://api.github.com/users/teamed/events{/privacy}","received_events_url":"https://api.github.com/users/teamed/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/teamed/quiz","description":"Quiz","fork":false,"url":"https://api.github.com/repos/teamed/quiz","forks_url":"https://api.github.com/repos/teamed/quiz/forks","keys_url":"https://api.github.com/repos/teamed/quiz/keys{/key_id}","collaborators_url":"https://api.github.com/repos/teamed/quiz/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/teamed/quiz/teams","hooks_url":"https://api.github.com/repos/teamed/quiz/hooks","issue_events_url":"https://api.github.com/repos/teamed/quiz/issues/events{/number}","events_url":"https://api.github.com/repos/teamed/quiz/events","assignees_url":"https://api.github.com/repos/teamed/quiz/assignees{/user}","branches_url":"https://api.github.com/repos/teamed/quiz/branches{/branch}","tags_url":"https://api.github.com/repos/teamed/quiz/tags","blobs_url":"https://api.github.com/repos/teamed/quiz/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/teamed/quiz/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/teamed/quiz/git/refs{/sha}","trees_url":"https://api.github.com/repos/teamed/quiz/git/trees{/sha}","statuses_url":"https://api.github.com/repos/teamed/quiz/statuses/{sha}","languages_url":"https://api.github.com/repos/teamed/quiz/languages","stargazers_url":"https://api.github.com/repos/teamed/quiz/stargazers","contributors_url":"https://api.github.com/repos/teamed/quiz/contributors","subscribers_url":"https://api.github.com/repos/teamed/quiz/subscribers","subscription_url":"https://api.github.com/repos/teamed/quiz/subscription","commits_url":"https://api.github.com/repos/teamed/quiz/commits{/sha}","git_commits_url":"https://api.github.com/repos/teamed/quiz/git/commits{/sha}","comments_url":"https://api.github.com/repos/teamed/quiz/comments{/number}","issue_comment_url":"https://api.github.com/repos/teamed/quiz/issues/comments{/number}","contents_url":"https://api.github.com/repos/teamed/quiz/contents/{+path}","compare_url":"https://api.github.com/repos/teamed/quiz/compare/{base}...{head}","merges_url":"https://api.github.com/repos/teamed/quiz/merges","archive_url":"https://api.github.com/repos/teamed/quiz/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/teamed/quiz/downloads","issues_url":"https://api.github.com/repos/teamed/quiz/issues{/number}","pulls_url":"https://api.github.com/repos/teamed/quiz/pulls{/number}","milestones_url":"https://api.github.com/repos/teamed/quiz/milestones{/number}","notifications_url":"https://api.github.com/repos/teamed/quiz/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/teamed/quiz/labels{/name}","releases_url":"https://api.github.com/repos/teamed/quiz/releases{/id}","deployments_url":"https://api.github.com/repos/teamed/quiz/deployments","created_at":"2015-02-02T13:55:45Z","updated_at":"2016-03-15T00:13:04Z","pushed_at":"2016-03-16T21:09:32Z","git_url":"git://github.com/teamed/quiz.git","ssh_url":"git@github.com:teamed/quiz.git","clone_url":"https://github.com/teamed/quiz.git","svn_url":"https://github.com/teamed/quiz","homepage":"http://www.teamed.io","size":1209,"stargazers_count":13,"watchers_count":13,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":348,"mirror_url":null,"open_issues_count":271,"forks":348,"open_issues":271,"watchers":13,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/teamed/quiz/pulls/371"},"html":{"href":"https://github.com/teamed/quiz/pull/371"},"issue":{"href":"https://api.github.com/repos/teamed/quiz/issues/371"},"comments":{"href":"https://api.github.com/repos/teamed/quiz/issues/371/comments"},"review_comments":{"href":"https://api.github.com/repos/teamed/quiz/pulls/371/comments"},"review_comment":{"href":"https://api.github.com/repos/teamed/quiz/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/teamed/quiz/pulls/371/commits"},"statuses":{"href":"https://api.github.com/repos/teamed/quiz/statuses/823d1d6e6a2f24d37bf7258f034ee296ddd63b6b"}}}}