title: Java - read an array of bytes from an InputStream until a certain character
body: <p>i need to read an Base64 encoded array of bytes from an inputstream.</p>
  
  <p>I have to stop reading when I reach a \n character in the decoded string, i cannot find an efficient way to do this.</p>
  
  <p>Now i ended with something like this but it does not work as intended because it's too easy it catches an exception and messes all up...</p>
  
  <pre><code>byte buffer[] = new byte[2048];
      byte results[] = new byte[2048];
      String totalResult = null;
      try {
          int bytes_read = is.read(buffer);
          while (buffer[bytes_read - 1] != '\n') {
              bytes_read = is.read(buffer);
              String app = new String(buffer, 0, bytes_read);
              totalResult += app;
  
          }
          String response = Base64.getDecoder().decode(totalResult).toString();
  </code></pre>
  
  <p>Any idea? The input Stream does not close, so i need to get data from it and separated by '\n'</p>