{"action":"created","issue":{"url":"https://api.github.com/repos/yegor256/takes/issues/205","labels_url":"https://api.github.com/repos/yegor256/takes/issues/205/labels{/name}","comments_url":"https://api.github.com/repos/yegor256/takes/issues/205/comments","events_url":"https://api.github.com/repos/yegor256/takes/issues/205/events","html_url":"https://github.com/yegor256/takes/issues/205","id":70235431,"number":205,"title":"stream reading is too slow","user":{"login":"yegor256","id":526301,"avatar_url":"https://avatars.githubusercontent.com/u/526301?v=3","gravatar_id":"","url":"https://api.github.com/users/yegor256","html_url":"https://github.com/yegor256","followers_url":"https://api.github.com/users/yegor256/followers","following_url":"https://api.github.com/users/yegor256/following{/other_user}","gists_url":"https://api.github.com/users/yegor256/gists{/gist_id}","starred_url":"https://api.github.com/users/yegor256/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yegor256/subscriptions","organizations_url":"https://api.github.com/users/yegor256/orgs","repos_url":"https://api.github.com/users/yegor256/repos","events_url":"https://api.github.com/users/yegor256/events{/privacy}","received_events_url":"https://api.github.com/users/yegor256/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/yegor256/takes/labels/30%20mins","name":"30 mins","color":"eb6421"},{"url":"https://api.github.com/repos/yegor256/takes/labels/@ikhvostenkov","name":"@ikhvostenkov","color":"009801"},{"url":"https://api.github.com/repos/yegor256/takes/labels/bug","name":"bug","color":"c0c0c0"},{"url":"https://api.github.com/repos/yegor256/takes/labels/DEV","name":"DEV","color":"bfd4f3"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/yegor256/takes/milestones/1","html_url":"https://github.com/yegor256/takes/milestones/1.0","labels_url":"https://api.github.com/repos/yegor256/takes/milestones/1/labels","id":1069705,"number":1,"title":"1.0","description":"first fully working version","creator":{"login":"yegor256","id":526301,"avatar_url":"https://avatars.githubusercontent.com/u/526301?v=3","gravatar_id":"","url":"https://api.github.com/users/yegor256","html_url":"https://github.com/yegor256","followers_url":"https://api.github.com/users/yegor256/followers","following_url":"https://api.github.com/users/yegor256/following{/other_user}","gists_url":"https://api.github.com/users/yegor256/gists{/gist_id}","starred_url":"https://api.github.com/users/yegor256/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yegor256/subscriptions","organizations_url":"https://api.github.com/users/yegor256/orgs","repos_url":"https://api.github.com/users/yegor256/repos","events_url":"https://api.github.com/users/yegor256/events{/privacy}","received_events_url":"https://api.github.com/users/yegor256/received_events","type":"User","site_admin":false},"open_issues":32,"closed_issues":22,"state":"open","created_at":"2015-04-16T00:55:10Z","updated_at":"2015-05-05T13:24:02Z","due_on":"2015-05-14T07:00:00Z","closed_at":null},"comments":10,"created_at":"2015-04-22T21:09:36Z","updated_at":"2015-05-05T18:19:42Z","closed_at":null,"body":"At the moment, in `RqPrint`, `RsPrint`, `RqMultipart` and in a few other places we're using `InputStream#read()`. This method reads the stream byte by byte. There is nothing wrong in this method, but it's slow on large streams. Let's replace that with `read(byte[])`.\r\n\r\nFull list of places:\r\n\r\n```\r\nSearching 296 files for \".read()\" (case sensitive)\r\n\r\n/Volumes/ssd2/code/takes/src/main/java/org/takes/rq/RqLengthAware.java:\r\n  127          public int read() throws IOException {\r\n  128              --this.more;\r\n  129:             return this.origin.read();\r\n  130          }\r\n  131      }\r\n\r\n/Volumes/ssd2/code/takes/src/main/java/org/takes/rq/RqLive.java:\r\n   64          final ByteArrayOutputStream baos = new ByteArrayOutputStream();\r\n   65          while (true) {\r\n   66:             final int data = input.read();\r\n   67              if (data < 0) {\r\n   68                  break;\r\n   69              }\r\n   70              if (data == '\\r') {\r\n   71:                 if (input.read() != '\\n') {\r\n   72                      throw new IOException(\"\");\r\n   73                  }\r\n\r\n/Volumes/ssd2/code/takes/src/main/java/org/takes/rq/RqMultipart.java:\r\n  149              RqMultipart.Base.skip(body, boundary.length - 2);\r\n  150              while (body.available() > 0) {\r\n  151:                 if (body.read() == '-') {\r\n  152                      break;\r\n  153                  }\r\n  ...\r\n  194              throws IOException {\r\n  195              for (int idx = 0; idx < skip; ++idx) {\r\n  196:                 stream.read();\r\n  197              }\r\n  198          }\r\n  ...\r\n  235              final ByteArrayOutputStream buf = new ByteArrayOutputStream();\r\n  236              while (body.available() > 0) {\r\n  237:                 final int data = body.read();\r\n  238                  if (data < 0) {\r\n  239                      break;\r\n\r\n/Volumes/ssd2/code/takes/src/main/java/org/takes/rq/RqPrint.java:\r\n  120          final InputStream input = new RqLengthAware(this).body();\r\n  121          while (input.available() > 0) {\r\n  122:             final int data = input.read();\r\n  123              if (data < 0) {\r\n  124                  break;\r\n\r\n/Volumes/ssd2/code/takes/src/main/java/org/takes/rs/RsGzip.java:\r\n   79          try {\r\n   80              while (true) {\r\n   81:                 final int data = input.read();\r\n   82                  if (data < 0) {\r\n   83                      break;\r\n\r\n/Volumes/ssd2/code/takes/src/main/java/org/takes/rs/RsPrint.java:\r\n  159          try {\r\n  160              while (body.available() > 0) {\r\n  161:                 final int data = body.read();\r\n  162                  if (data < 0) {\r\n  163                      break;\r\n\r\n/Volumes/ssd2/code/takes/src/main/java/org/takes/rs/RsXSLT.java:\r\n  170          final ByteArrayOutputStream baos = new ByteArrayOutputStream();\r\n  171          while (true) {\r\n  172:             final int data = input.read();\r\n  173              if (data < 0) {\r\n  174                  break;\r\n```"},"comment":{"url":"https://api.github.com/repos/yegor256/takes/issues/comments/99165133","html_url":"https://github.com/yegor256/takes/issues/205#issuecomment-99165133","issue_url":"https://api.github.com/repos/yegor256/takes/issues/205","id":99165133,"user":{"login":"yegor256","id":526301,"avatar_url":"https://avatars.githubusercontent.com/u/526301?v=3","gravatar_id":"","url":"https://api.github.com/users/yegor256","html_url":"https://github.com/yegor256","followers_url":"https://api.github.com/users/yegor256/followers","following_url":"https://api.github.com/users/yegor256/following{/other_user}","gists_url":"https://api.github.com/users/yegor256/gists{/gist_id}","starred_url":"https://api.github.com/users/yegor256/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yegor256/subscriptions","organizations_url":"https://api.github.com/users/yegor256/orgs","repos_url":"https://api.github.com/users/yegor256/repos","events_url":"https://api.github.com/users/yegor256/events{/privacy}","received_events_url":"https://api.github.com/users/yegor256/received_events","type":"User","site_admin":false},"created_at":"2015-05-05T18:19:42Z","updated_at":"2015-05-05T18:19:42Z","body":"@ikhvostenkov we already have `RqBuffered` and `RsBuffered` for that, but this is not a solution. Still, making 1000 calls to `read()` (even if through buffered input stream) is way slower than a single call to `read(byte[])`"}}