{"action":"created","comment":{"url":"https://api.github.com/repos/RestComm/mediaserver/pulls/comments/64213159","id":64213159,"diff_hunk":"@@ -57,109 +52,100 @@\n     private int sizeOfData;\n     private boolean first = true;\n     \n-    private ReadableByteChannel rbChannel;\n-    private ByteBuffer buff;\n-   \n+    /*Buffer, Channel, Header */\n     private final static int BUFFER_SIZE = 128;\n+    private ReadableByteChannel rbChannel;\n+    private ByteBuffer buff = ByteBuffer.allocate(BUFFER_SIZE);\n+    private byte[] header = new byte[46];\n+    private byte[] headerEnd = null;\n+    int buffPos = 0;\n     \n-    // Padding for different stream types.\n+    /*Padding for different stream types.*/\n     private final static byte PCM_PADDING_BYTE = 0;\n     private final static byte ALAW_PADDING_BYTE = (byte) 0xD5;\n     private final static byte ULAW_PADDING_BYTE = (byte) 0xFF;\n-\n     private final static byte[] factBytes = new byte[] { 0x66, 0x61, 0x63, 0x74 };\n     private byte paddingByte = PCM_PADDING_BYTE;\n     private static final Logger logger = Logger.getLogger(WavTrackImpl.class);\n     \n+    \n     public WavTrackImpl (URL url) throws IOException, UnsupportedAudioFileException {\n         \n-        rbChannel=Channels.newChannel(url.openStream());\n-        buff = ByteBuffer.allocate(BUFFER_SIZE); \n-        \n-        getAudioFormat(rbChannel);\n-        if (format == null) {\n-            throw new UnsupportedAudioFileException();\n-        }\n+        setRbChannel(url.openStream());\n+        getAudioFormat(getRbChannel());\n        \n     }\n+    \n+    /**\n+        Reads data from channel into buffer and transfers data to header[] array.\n+        bytesRead in this case (using bulk method) returns the amount which is available\n+        and not the number of actually read bytes. The buffer position must be set to some offset.\n+        The offset in the bulk method is the offset in the array where the data is stored.\n+        Before getting the data in the array, the whole channel is read (bytesReadFromChannel),\n+        to avoid BufferUnderflow. \n+    */\n \n-    private void getAudioFormat(ReadableByteChannel rbc) throws IOException {\n-        byte[] header = new byte[36];\n-        byte[] headerEnd = null;\n-       \n-        int bytesReadFromChannel = 0 ;\n+    private void getAudioFormat(ReadableByteChannel rbc) throws IOException, UnsupportedAudioFileException {\n+        \n         int bytesRead = 0;\n-        int count = 0;\n+        int bytesCount = 0;\n+        int byteIndex = 0;\n+        int bytesReadFromChannel=rbc.read(getBuff());\n         \n-        bytesReadFromChannel=rbc.read(buff);\n-        buff.clear();\n+        setBuffPos(0);\n         \n-        while (count < 36 && buff.remaining() > 0) {\n-            //count=rbc.read(buffer);\n-            header[count]=buff.get(count);\n-            count++;\n+        while (bytesCount < getHeader().length && getBuff().remaining() > 0) {","path":"resources/mediaplayer/src/main/java/org/mobicents/media/server/impl/resource/mediaplayer/audio/wav/WavTrackImpl.java","position":null,"original_position":99,"commit_id":"b7e0e3c949cfb92729b63c0f823faddcf8de2ea4","original_commit_id":"b7e0e3c949cfb92729b63c0f823faddcf8de2ea4","user":{"login":"hrosa","id":7796608,"avatar_url":"https://avatars.githubusercontent.com/u/7796608?v=3","gravatar_id":"","url":"https://api.github.com/users/hrosa","html_url":"https://github.com/hrosa","followers_url":"https://api.github.com/users/hrosa/followers","following_url":"https://api.github.com/users/hrosa/following{/other_user}","gists_url":"https://api.github.com/users/hrosa/gists{/gist_id}","starred_url":"https://api.github.com/users/hrosa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hrosa/subscriptions","organizations_url":"https://api.github.com/users/hrosa/orgs","repos_url":"https://api.github.com/users/hrosa/repos","events_url":"https://api.github.com/users/hrosa/events{/privacy}","received_events_url":"https://api.github.com/users/hrosa/received_events","type":"User","site_admin":false},"body":"Do we really need this while cycle, now that we're doing bulk operations??","created_at":"2016-05-23T12:25:31Z","updated_at":"2016-05-23T12:25:31Z","html_url":"https://github.com/RestComm/mediaserver/pull/157#discussion_r64213159","pull_request_url":"https://api.github.com/repos/RestComm/mediaserver/pulls/157","_links":{"self":{"href":"https://api.github.com/repos/RestComm/mediaserver/pulls/comments/64213159"},"html":{"href":"https://github.com/RestComm/mediaserver/pull/157#discussion_r64213159"},"pull_request":{"href":"https://api.github.com/repos/RestComm/mediaserver/pulls/157"}}},"pull_request":{"url":"https://api.github.com/repos/RestComm/mediaserver/pulls/157","id":70333538,"html_url":"https://github.com/RestComm/mediaserver/pull/157","diff_url":"https://github.com/RestComm/mediaserver/pull/157.diff","patch_url":"https://github.com/RestComm/mediaserver/pull/157.patch","issue_url":"https://api.github.com/repos/RestComm/mediaserver/issues/157","number":157,"state":"open","locked":false,"title":"Issue #45. InputStream replaced with NIO channel.","user":{"login":"atika2k","id":14049311,"avatar_url":"https://avatars.githubusercontent.com/u/14049311?v=3","gravatar_id":"","url":"https://api.github.com/users/atika2k","html_url":"https://github.com/atika2k","followers_url":"https://api.github.com/users/atika2k/followers","following_url":"https://api.github.com/users/atika2k/following{/other_user}","gists_url":"https://api.github.com/users/atika2k/gists{/gist_id}","starred_url":"https://api.github.com/users/atika2k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atika2k/subscriptions","organizations_url":"https://api.github.com/users/atika2k/orgs","repos_url":"https://api.github.com/users/atika2k/repos","events_url":"https://api.github.com/users/atika2k/events{/privacy}","received_events_url":"https://api.github.com/users/atika2k/received_events","type":"User","site_admin":false},"body":"The packet reading  is done by non-blocking ReadableByteChannel and ByteBuffer.","created_at":"2016-05-17T10:29:32Z","updated_at":"2016-05-23T12:25:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8acf949d727a5e08737c46ad6dfd9c3cccf48980","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/RestComm/mediaserver/pulls/157/commits","review_comments_url":"https://api.github.com/repos/RestComm/mediaserver/pulls/157/comments","review_comment_url":"https://api.github.com/repos/RestComm/mediaserver/pulls/comments{/number}","comments_url":"https://api.github.com/repos/RestComm/mediaserver/issues/157/comments","statuses_url":"https://api.github.com/repos/RestComm/mediaserver/statuses/b7e0e3c949cfb92729b63c0f823faddcf8de2ea4","head":{"label":"atika2k:atika_issue45","ref":"atika_issue45","sha":"b7e0e3c949cfb92729b63c0f823faddcf8de2ea4","user":{"login":"atika2k","id":14049311,"avatar_url":"https://avatars.githubusercontent.com/u/14049311?v=3","gravatar_id":"","url":"https://api.github.com/users/atika2k","html_url":"https://github.com/atika2k","followers_url":"https://api.github.com/users/atika2k/followers","following_url":"https://api.github.com/users/atika2k/following{/other_user}","gists_url":"https://api.github.com/users/atika2k/gists{/gist_id}","starred_url":"https://api.github.com/users/atika2k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atika2k/subscriptions","organizations_url":"https://api.github.com/users/atika2k/orgs","repos_url":"https://api.github.com/users/atika2k/repos","events_url":"https://api.github.com/users/atika2k/events{/privacy}","received_events_url":"https://api.github.com/users/atika2k/received_events","type":"User","site_admin":false},"repo":{"id":59007045,"name":"mediaserver","full_name":"atika2k/mediaserver","owner":{"login":"atika2k","id":14049311,"avatar_url":"https://avatars.githubusercontent.com/u/14049311?v=3","gravatar_id":"","url":"https://api.github.com/users/atika2k","html_url":"https://github.com/atika2k","followers_url":"https://api.github.com/users/atika2k/followers","following_url":"https://api.github.com/users/atika2k/following{/other_user}","gists_url":"https://api.github.com/users/atika2k/gists{/gist_id}","starred_url":"https://api.github.com/users/atika2k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atika2k/subscriptions","organizations_url":"https://api.github.com/users/atika2k/orgs","repos_url":"https://api.github.com/users/atika2k/repos","events_url":"https://api.github.com/users/atika2k/events{/privacy}","received_events_url":"https://api.github.com/users/atika2k/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/atika2k/mediaserver","description":"RMS - Restcomm Media Server for Real Time Cloud Communications","fork":true,"url":"https://api.github.com/repos/atika2k/mediaserver","forks_url":"https://api.github.com/repos/atika2k/mediaserver/forks","keys_url":"https://api.github.com/repos/atika2k/mediaserver/keys{/key_id}","collaborators_url":"https://api.github.com/repos/atika2k/mediaserver/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/atika2k/mediaserver/teams","hooks_url":"https://api.github.com/repos/atika2k/mediaserver/hooks","issue_events_url":"https://api.github.com/repos/atika2k/mediaserver/issues/events{/number}","events_url":"https://api.github.com/repos/atika2k/mediaserver/events","assignees_url":"https://api.github.com/repos/atika2k/mediaserver/assignees{/user}","branches_url":"https://api.github.com/repos/atika2k/mediaserver/branches{/branch}","tags_url":"https://api.github.com/repos/atika2k/mediaserver/tags","blobs_url":"https://api.github.com/repos/atika2k/mediaserver/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/atika2k/mediaserver/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/atika2k/mediaserver/git/refs{/sha}","trees_url":"https://api.github.com/repos/atika2k/mediaserver/git/trees{/sha}","statuses_url":"https://api.github.com/repos/atika2k/mediaserver/statuses/{sha}","languages_url":"https://api.github.com/repos/atika2k/mediaserver/languages","stargazers_url":"https://api.github.com/repos/atika2k/mediaserver/stargazers","contributors_url":"https://api.github.com/repos/atika2k/mediaserver/contributors","subscribers_url":"https://api.github.com/repos/atika2k/mediaserver/subscribers","subscription_url":"https://api.github.com/repos/atika2k/mediaserver/subscription","commits_url":"https://api.github.com/repos/atika2k/mediaserver/commits{/sha}","git_commits_url":"https://api.github.com/repos/atika2k/mediaserver/git/commits{/sha}","comments_url":"https://api.github.com/repos/atika2k/mediaserver/comments{/number}","issue_comment_url":"https://api.github.com/repos/atika2k/mediaserver/issues/comments{/number}","contents_url":"https://api.github.com/repos/atika2k/mediaserver/contents/{+path}","compare_url":"https://api.github.com/repos/atika2k/mediaserver/compare/{base}...{head}","merges_url":"https://api.github.com/repos/atika2k/mediaserver/merges","archive_url":"https://api.github.com/repos/atika2k/mediaserver/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/atika2k/mediaserver/downloads","issues_url":"https://api.github.com/repos/atika2k/mediaserver/issues{/number}","pulls_url":"https://api.github.com/repos/atika2k/mediaserver/pulls{/number}","milestones_url":"https://api.github.com/repos/atika2k/mediaserver/milestones{/number}","notifications_url":"https://api.github.com/repos/atika2k/mediaserver/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/atika2k/mediaserver/labels{/name}","releases_url":"https://api.github.com/repos/atika2k/mediaserver/releases{/id}","deployments_url":"https://api.github.com/repos/atika2k/mediaserver/deployments","created_at":"2016-05-17T09:03:44Z","updated_at":"2016-05-17T09:03:49Z","pushed_at":"2016-05-21T21:54:46Z","git_url":"git://github.com/atika2k/mediaserver.git","ssh_url":"git@github.com:atika2k/mediaserver.git","clone_url":"https://github.com/atika2k/mediaserver.git","svn_url":"https://github.com/atika2k/mediaserver","homepage":"","size":88492,"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":"RestComm:master","ref":"master","sha":"3ff8290f11fee13b321100eb25a7b0a8be8d1d95","user":{"login":"RestComm","id":667380,"avatar_url":"https://avatars.githubusercontent.com/u/667380?v=3","gravatar_id":"","url":"https://api.github.com/users/RestComm","html_url":"https://github.com/RestComm","followers_url":"https://api.github.com/users/RestComm/followers","following_url":"https://api.github.com/users/RestComm/following{/other_user}","gists_url":"https://api.github.com/users/RestComm/gists{/gist_id}","starred_url":"https://api.github.com/users/RestComm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RestComm/subscriptions","organizations_url":"https://api.github.com/users/RestComm/orgs","repos_url":"https://api.github.com/users/RestComm/repos","events_url":"https://api.github.com/users/RestComm/events{/privacy}","received_events_url":"https://api.github.com/users/RestComm/received_events","type":"Organization","site_admin":false},"repo":{"id":5455433,"name":"mediaserver","full_name":"RestComm/mediaserver","owner":{"login":"RestComm","id":667380,"avatar_url":"https://avatars.githubusercontent.com/u/667380?v=3","gravatar_id":"","url":"https://api.github.com/users/RestComm","html_url":"https://github.com/RestComm","followers_url":"https://api.github.com/users/RestComm/followers","following_url":"https://api.github.com/users/RestComm/following{/other_user}","gists_url":"https://api.github.com/users/RestComm/gists{/gist_id}","starred_url":"https://api.github.com/users/RestComm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RestComm/subscriptions","organizations_url":"https://api.github.com/users/RestComm/orgs","repos_url":"https://api.github.com/users/RestComm/repos","events_url":"https://api.github.com/users/RestComm/events{/privacy}","received_events_url":"https://api.github.com/users/RestComm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/RestComm/mediaserver","description":"RMS - Restcomm Media Server for Real Time Cloud Communications","fork":false,"url":"https://api.github.com/repos/RestComm/mediaserver","forks_url":"https://api.github.com/repos/RestComm/mediaserver/forks","keys_url":"https://api.github.com/repos/RestComm/mediaserver/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RestComm/mediaserver/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RestComm/mediaserver/teams","hooks_url":"https://api.github.com/repos/RestComm/mediaserver/hooks","issue_events_url":"https://api.github.com/repos/RestComm/mediaserver/issues/events{/number}","events_url":"https://api.github.com/repos/RestComm/mediaserver/events","assignees_url":"https://api.github.com/repos/RestComm/mediaserver/assignees{/user}","branches_url":"https://api.github.com/repos/RestComm/mediaserver/branches{/branch}","tags_url":"https://api.github.com/repos/RestComm/mediaserver/tags","blobs_url":"https://api.github.com/repos/RestComm/mediaserver/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RestComm/mediaserver/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RestComm/mediaserver/git/refs{/sha}","trees_url":"https://api.github.com/repos/RestComm/mediaserver/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RestComm/mediaserver/statuses/{sha}","languages_url":"https://api.github.com/repos/RestComm/mediaserver/languages","stargazers_url":"https://api.github.com/repos/RestComm/mediaserver/stargazers","contributors_url":"https://api.github.com/repos/RestComm/mediaserver/contributors","subscribers_url":"https://api.github.com/repos/RestComm/mediaserver/subscribers","subscription_url":"https://api.github.com/repos/RestComm/mediaserver/subscription","commits_url":"https://api.github.com/repos/RestComm/mediaserver/commits{/sha}","git_commits_url":"https://api.github.com/repos/RestComm/mediaserver/git/commits{/sha}","comments_url":"https://api.github.com/repos/RestComm/mediaserver/comments{/number}","issue_comment_url":"https://api.github.com/repos/RestComm/mediaserver/issues/comments{/number}","contents_url":"https://api.github.com/repos/RestComm/mediaserver/contents/{+path}","compare_url":"https://api.github.com/repos/RestComm/mediaserver/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RestComm/mediaserver/merges","archive_url":"https://api.github.com/repos/RestComm/mediaserver/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RestComm/mediaserver/downloads","issues_url":"https://api.github.com/repos/RestComm/mediaserver/issues{/number}","pulls_url":"https://api.github.com/repos/RestComm/mediaserver/pulls{/number}","milestones_url":"https://api.github.com/repos/RestComm/mediaserver/milestones{/number}","notifications_url":"https://api.github.com/repos/RestComm/mediaserver/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RestComm/mediaserver/labels{/name}","releases_url":"https://api.github.com/repos/RestComm/mediaserver/releases{/id}","deployments_url":"https://api.github.com/repos/RestComm/mediaserver/deployments","created_at":"2012-08-17T17:45:39Z","updated_at":"2016-05-14T01:34:24Z","pushed_at":"2016-05-21T21:54:46Z","git_url":"git://github.com/RestComm/mediaserver.git","ssh_url":"git@github.com:RestComm/mediaserver.git","clone_url":"https://github.com/RestComm/mediaserver.git","svn_url":"https://github.com/RestComm/mediaserver","homepage":"","size":89063,"stargazers_count":40,"watchers_count":40,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":39,"mirror_url":null,"open_issues_count":75,"forks":39,"open_issues":75,"watchers":40,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/RestComm/mediaserver/pulls/157"},"html":{"href":"https://github.com/RestComm/mediaserver/pull/157"},"issue":{"href":"https://api.github.com/repos/RestComm/mediaserver/issues/157"},"comments":{"href":"https://api.github.com/repos/RestComm/mediaserver/issues/157/comments"},"review_comments":{"href":"https://api.github.com/repos/RestComm/mediaserver/pulls/157/comments"},"review_comment":{"href":"https://api.github.com/repos/RestComm/mediaserver/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/RestComm/mediaserver/pulls/157/commits"},"statuses":{"href":"https://api.github.com/repos/RestComm/mediaserver/statuses/b7e0e3c949cfb92729b63c0f823faddcf8de2ea4"}}}}
{"actor":{"display_login":"hrosa"}}