{"action":"created","comment":{"url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/pulls/comments/63550750","id":63550750,"diff_hunk":"@@ -0,0 +1,133 @@\n+package nl.tudelft.contextproject.qrgenerator;\n+\n+import java.io.ByteArrayOutputStream;\n+import java.io.FileOutputStream;\n+import java.io.IOException;\n+import java.io.OutputStream;\n+import java.net.InetAddress;\n+import java.net.NetworkInterface;\n+import java.net.SocketException;\n+import java.util.Enumeration;\n+\n+import net.glxn.qrgen.core.image.ImageType;\n+import net.glxn.qrgen.javase.QRCode;\n+import nl.tudelft.contextproject.Main;\n+import nl.tudelft.contextproject.logging.Log;\n+\n+/**\n+ * QR code generator class. \n+ * Singleton that will generate a QR code and place it in {@link #location}.\n+ *\n+ * It possible to automatically try and find the hosting address and generate the QR code with:\n+ * QRGenerator.getInstance().generateQRcode();\n+ * \n+ * or to manually set the URL and generate the QR code with:\n+ * QRGenerator.getInstance().setURL(\"URL string\");\n+ * QRGenerator.getInstance().generateQRcode();\n+ */\n+public final class QRGenerator {\n+\n+\t//Use eager initialization of the singleton.\n+\tprivate static final QRGenerator INSTANCE = new QRGenerator();\n+\n+\t//Location and name of QR image.\n+\tpublic final String location = \"qrcode.png\";\n+\t//Width of QR image.\n+\tpublic final int width = 250;\n+\t//Height of QR image.\n+\tpublic final int heigth = 250;\n+\n+\t//Holds IP of server.\n+\tprivate String hostingAddress;\n+\t//Port number of server.\n+\tprivate int portNumber = Main.PORT_NUMBER;\n+\n+\t/**\n+\t * Private constructor to prevent initialization elsewhere.\n+\t * Will try to find IP.\n+\t */\n+\tprivate QRGenerator() {\n+\t\tsearchForHostAddress();\n+\t}\n+\n+\t/**\n+\t * Get the hosting address as an URL String.\n+\t * @return\n+\t * \t\t\thosting address\n+\t */\n+\tpublic String getURL() {\n+\t\treturn hostingAddress;\n+\t}\n+\n+\t/**\n+\t * Set the hosting address as an URL String.\n+\t * @param url\n+\t * \t\t\t\thosting addres\n+\t */ \n+\tpublic void setURL(String url) {\n+\t\thostingAddress = url;\n+\t}\n+\n+\t/**\n+\t * Get the QRgenerator instance.\n+\t * @return\n+\t * \t\t\tQRgenerator\n+\t */\n+\tpublic static QRGenerator getInstance() {\n+\t\treturn INSTANCE;\n+\t}\n+\n+\t/**\n+\t * Generate a QR code in {@link #location}.\n+\t * First, get the hostingAddress by using the Java InetAddress class.\n+\t * Then, create the QRgen as a ByteArrayOutputStream.\n+\t * And finally write the ByteArrayOutputStream to disk.\n+\t */\n+\tpublic void generateQRcode() {\n+\t\tLog.getLog(\"WebInterface\").info(\"Creating QR code with address: \" + hostingAddress);\n+\t\tByteArrayOutputStream byteArrayOutputStream = QRCode.from(hostingAddress).to(ImageType.PNG).withSize(width, heigth).stream();\n+\n+\t\ttry (OutputStream outputStream = new FileOutputStream(location)) {\n+\t\t\tbyteArrayOutputStream.writeTo(outputStream);\n+\t\t\tLog.getLog(\"WebInterface\").info(\"Created QR code with address: \" + hostingAddress + \" as \" + location);\n+\t\t} catch (IOException e) {\n+\t\t\tLog.getLog(\"WebInterface\").severe(\"Unable to write qr code to disk.\", e);\n+\t\t\te.printStackTrace();\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Set the correct ipv4 address of this computer.\n+\t * This method needs all network interfaces of the computer.\n+\t * It will for each network interface check all the network addresses.\n+\t * The IP address will be among those, so all address that are personally or locally based\n+\t * are filtered out.\n+\t * Please note that you cannot have other network adapters (such from virtual machines)\n+\t * running as they will interfere with the correct adapter. \n+\t */\n+\tprotected void searchForHostAddress() {\n+\t\thostingAddress = \"\";\n+\t\tEnumeration<NetworkInterface> networkInterfaces;\n+\t\ttry {\n+\t\t\tnetworkInterfaces = NetworkInterface.getNetworkInterfaces();\n+\t\t\twhile (networkInterfaces.hasMoreElements()) {\n+\t\t\t\tNetworkInterface e = networkInterfaces.nextElement();\n+\t\t\t\tEnumeration<InetAddress> a = e.getInetAddresses();\n+\n+\t\t\t\twhile (a.hasMoreElements()) {\n+\t\t\t\t\tInetAddress addr = a.nextElement();\n+\t\t\t\t\tString hostAddress = addr.getHostAddress();\n+\t\t\t\t\tif ((!hostAddress.startsWith(\"127.\") \n+\t\t\t\t\t\t\t&& !hostAddress.contains(\":\"))\n+\t\t\t\t\t\t\t&& !hostAddress.startsWith(\"192.168.\")) {","path":"src/main/java/nl/tudelft/contextproject/qrgenerator/QRGenerator.java","position":122,"original_position":122,"commit_id":"995eb4a0601372786ad2b3df553fda6ba9d6d53f","original_commit_id":"995eb4a0601372786ad2b3df553fda6ba9d6d53f","user":{"login":"Taeir","id":668952,"avatar_url":"https://avatars.githubusercontent.com/u/668952?v=3","gravatar_id":"","url":"https://api.github.com/users/Taeir","html_url":"https://github.com/Taeir","followers_url":"https://api.github.com/users/Taeir/followers","following_url":"https://api.github.com/users/Taeir/following{/other_user}","gists_url":"https://api.github.com/users/Taeir/gists{/gist_id}","starred_url":"https://api.github.com/users/Taeir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Taeir/subscriptions","organizations_url":"https://api.github.com/users/Taeir/orgs","repos_url":"https://api.github.com/users/Taeir/repos","events_url":"https://api.github.com/users/Taeir/events{/privacy}","received_events_url":"https://api.github.com/users/Taeir/received_events","type":"User","site_admin":false},"body":"I don't think we want to exclude 192.168.","created_at":"2016-05-17T15:58:37Z","updated_at":"2016-05-17T15:58:37Z","html_url":"https://github.com/Taeir/ContextProject-MIGI2/pull/170#discussion_r63550750","pull_request_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/pulls/170","_links":{"self":{"href":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/pulls/comments/63550750"},"html":{"href":"https://github.com/Taeir/ContextProject-MIGI2/pull/170#discussion_r63550750"},"pull_request":{"href":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/pulls/170"}}},"pull_request":{"url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/pulls/170","id":70380482,"html_url":"https://github.com/Taeir/ContextProject-MIGI2/pull/170","diff_url":"https://github.com/Taeir/ContextProject-MIGI2/pull/170.diff","patch_url":"https://github.com/Taeir/ContextProject-MIGI2/pull/170.patch","issue_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/issues/170","number":170,"state":"open","locked":false,"title":"Feature qrcode","user":{"login":"Diocruel","id":9715288,"avatar_url":"https://avatars.githubusercontent.com/u/9715288?v=3","gravatar_id":"","url":"https://api.github.com/users/Diocruel","html_url":"https://github.com/Diocruel","followers_url":"https://api.github.com/users/Diocruel/followers","following_url":"https://api.github.com/users/Diocruel/following{/other_user}","gists_url":"https://api.github.com/users/Diocruel/gists{/gist_id}","starred_url":"https://api.github.com/users/Diocruel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Diocruel/subscriptions","organizations_url":"https://api.github.com/users/Diocruel/orgs","repos_url":"https://api.github.com/users/Diocruel/repos","events_url":"https://api.github.com/users/Diocruel/events{/privacy}","received_events_url":"https://api.github.com/users/Diocruel/received_events","type":"User","site_admin":false},"body":"QR codes can now be generated! Please refer to the use of the QRGenerator to the javadoc.\r\n\r\nCobertura line coverage is 85%, though it can be argued that these test do not contribute much to actual testing. In order for the QRGenerator to work there is an output file needed and the use of a static final class: the NetworkInterface class. This hard to mock so I think it is okay to do it this way. \r\n\r\nThis item was done early so that @WytzeElhorst can work on his sprint items.\r\n\r\nThis closes #130  , closes #131  , closes #132 \r\n\r\n","created_at":"2016-05-17T15:42:46Z","updated_at":"2016-05-17T15:58:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"14045eb3ba20282146491b1808cc21f255159d58","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/pulls/170/commits","review_comments_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/pulls/170/comments","review_comment_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/issues/170/comments","statuses_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/statuses/995eb4a0601372786ad2b3df553fda6ba9d6d53f","head":{"label":"Taeir:feature-qrcode","ref":"feature-qrcode","sha":"995eb4a0601372786ad2b3df553fda6ba9d6d53f","user":{"login":"Taeir","id":668952,"avatar_url":"https://avatars.githubusercontent.com/u/668952?v=3","gravatar_id":"","url":"https://api.github.com/users/Taeir","html_url":"https://github.com/Taeir","followers_url":"https://api.github.com/users/Taeir/followers","following_url":"https://api.github.com/users/Taeir/following{/other_user}","gists_url":"https://api.github.com/users/Taeir/gists{/gist_id}","starred_url":"https://api.github.com/users/Taeir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Taeir/subscriptions","organizations_url":"https://api.github.com/users/Taeir/orgs","repos_url":"https://api.github.com/users/Taeir/repos","events_url":"https://api.github.com/users/Taeir/events{/privacy}","received_events_url":"https://api.github.com/users/Taeir/received_events","type":"User","site_admin":false},"repo":{"id":56629638,"name":"ContextProject-MIGI2","full_name":"Taeir/ContextProject-MIGI2","owner":{"login":"Taeir","id":668952,"avatar_url":"https://avatars.githubusercontent.com/u/668952?v=3","gravatar_id":"","url":"https://api.github.com/users/Taeir","html_url":"https://github.com/Taeir","followers_url":"https://api.github.com/users/Taeir/followers","following_url":"https://api.github.com/users/Taeir/following{/other_user}","gists_url":"https://api.github.com/users/Taeir/gists{/gist_id}","starred_url":"https://api.github.com/users/Taeir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Taeir/subscriptions","organizations_url":"https://api.github.com/users/Taeir/orgs","repos_url":"https://api.github.com/users/Taeir/repos","events_url":"https://api.github.com/users/Taeir/events{/privacy}","received_events_url":"https://api.github.com/users/Taeir/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Taeir/ContextProject-MIGI2","description":"VR Game","fork":false,"url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2","forks_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/forks","keys_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/teams","hooks_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/hooks","issue_events_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/issues/events{/number}","events_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/events","assignees_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/assignees{/user}","branches_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/branches{/branch}","tags_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/tags","blobs_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/git/refs{/sha}","trees_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/statuses/{sha}","languages_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/languages","stargazers_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/stargazers","contributors_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/contributors","subscribers_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/subscribers","subscription_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/subscription","commits_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/commits{/sha}","git_commits_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/git/commits{/sha}","comments_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/comments{/number}","issue_comment_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/issues/comments{/number}","contents_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/contents/{+path}","compare_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/merges","archive_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/downloads","issues_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/issues{/number}","pulls_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/pulls{/number}","milestones_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/milestones{/number}","notifications_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/labels{/name}","releases_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/releases{/id}","deployments_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/deployments","created_at":"2016-04-19T20:28:13Z","updated_at":"2016-05-13T09:37:37Z","pushed_at":"2016-05-17T15:53:34Z","git_url":"git://github.com/Taeir/ContextProject-MIGI2.git","ssh_url":"git@github.com:Taeir/ContextProject-MIGI2.git","clone_url":"https://github.com/Taeir/ContextProject-MIGI2.git","svn_url":"https://github.com/Taeir/ContextProject-MIGI2","homepage":"","size":26364,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":59,"forks":0,"open_issues":59,"watchers":0,"default_branch":"master"}},"base":{"label":"Taeir:dev-sprint4","ref":"dev-sprint4","sha":"424c88dfe465387823c532354481f3459a512f19","user":{"login":"Taeir","id":668952,"avatar_url":"https://avatars.githubusercontent.com/u/668952?v=3","gravatar_id":"","url":"https://api.github.com/users/Taeir","html_url":"https://github.com/Taeir","followers_url":"https://api.github.com/users/Taeir/followers","following_url":"https://api.github.com/users/Taeir/following{/other_user}","gists_url":"https://api.github.com/users/Taeir/gists{/gist_id}","starred_url":"https://api.github.com/users/Taeir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Taeir/subscriptions","organizations_url":"https://api.github.com/users/Taeir/orgs","repos_url":"https://api.github.com/users/Taeir/repos","events_url":"https://api.github.com/users/Taeir/events{/privacy}","received_events_url":"https://api.github.com/users/Taeir/received_events","type":"User","site_admin":false},"repo":{"id":56629638,"name":"ContextProject-MIGI2","full_name":"Taeir/ContextProject-MIGI2","owner":{"login":"Taeir","id":668952,"avatar_url":"https://avatars.githubusercontent.com/u/668952?v=3","gravatar_id":"","url":"https://api.github.com/users/Taeir","html_url":"https://github.com/Taeir","followers_url":"https://api.github.com/users/Taeir/followers","following_url":"https://api.github.com/users/Taeir/following{/other_user}","gists_url":"https://api.github.com/users/Taeir/gists{/gist_id}","starred_url":"https://api.github.com/users/Taeir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Taeir/subscriptions","organizations_url":"https://api.github.com/users/Taeir/orgs","repos_url":"https://api.github.com/users/Taeir/repos","events_url":"https://api.github.com/users/Taeir/events{/privacy}","received_events_url":"https://api.github.com/users/Taeir/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Taeir/ContextProject-MIGI2","description":"VR Game","fork":false,"url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2","forks_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/forks","keys_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/teams","hooks_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/hooks","issue_events_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/issues/events{/number}","events_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/events","assignees_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/assignees{/user}","branches_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/branches{/branch}","tags_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/tags","blobs_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/git/refs{/sha}","trees_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/statuses/{sha}","languages_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/languages","stargazers_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/stargazers","contributors_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/contributors","subscribers_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/subscribers","subscription_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/subscription","commits_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/commits{/sha}","git_commits_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/git/commits{/sha}","comments_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/comments{/number}","issue_comment_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/issues/comments{/number}","contents_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/contents/{+path}","compare_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/merges","archive_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/downloads","issues_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/issues{/number}","pulls_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/pulls{/number}","milestones_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/milestones{/number}","notifications_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/labels{/name}","releases_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/releases{/id}","deployments_url":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/deployments","created_at":"2016-04-19T20:28:13Z","updated_at":"2016-05-13T09:37:37Z","pushed_at":"2016-05-17T15:53:34Z","git_url":"git://github.com/Taeir/ContextProject-MIGI2.git","ssh_url":"git@github.com:Taeir/ContextProject-MIGI2.git","clone_url":"https://github.com/Taeir/ContextProject-MIGI2.git","svn_url":"https://github.com/Taeir/ContextProject-MIGI2","homepage":"","size":26364,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":59,"forks":0,"open_issues":59,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/pulls/170"},"html":{"href":"https://github.com/Taeir/ContextProject-MIGI2/pull/170"},"issue":{"href":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/issues/170"},"comments":{"href":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/issues/170/comments"},"review_comments":{"href":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/pulls/170/comments"},"review_comment":{"href":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/pulls/170/commits"},"statuses":{"href":"https://api.github.com/repos/Taeir/ContextProject-MIGI2/statuses/995eb4a0601372786ad2b3df553fda6ba9d6d53f"}}}}