title: java IOException: Broken pipe using HttpHandler to serve mp3. Only with Android browser
body: <p>I am trying to serve an mp3 using HttpHandler and getting a broken pipe. It works with Google Chrome on my mac and my iPad but Android cause the HttpHander to just hang after getting the IOException and I have to restart. Using very simple code and works fine with images and html.</p>
  
  <pre><code>       try {
              String requestURI = t.getRequestURI().toString().substring(1);
  
              if(requestURI.equals("") || requestURI.equals("/"))
                  requestURI = "index.htm";
  
              requestURI = requestURI.replaceAll("%20", " ");
  
              if(requestURI.contains("mp3")) {
                  urlToResource = new File(System.getProperty("user.home") + "/test/" +
                          requestURI).toURI().toURL();
              }
  
              System.out.println("Modified requestURI:" + requestURI);
  
              if(requestURI.contains("mp3")) {
                  sContentType = "audio/mpeg";
              } else if(requestURI.contains("png")) {
                  sContentType = "image/png";
              } else if(requestURI.contains("jpg")) {
                  sContentType = "image/jpg";
              } else if(requestURI.contains("favicon.ico")) {
                  sContentType = "content/unknown";
              } else if(requestURI.contains("css")) {
                  sContentType = "text/css";
              } else {
                  sContentType = "text/html";
              }
  
              if(!requestURI.contains("mp3")) {
                  urlToResource = new File("src/com/daford/web/" + requestURI).toURI().toURL();
              }
  
              if(urlToResource != null) {
                  conn = urlToResource.openConnection();
                  int size = conn.getContentLength();
  
                  System.out.println("file " + requestURI + " size is:" + size);
  
                  inConnectionReader = conn.getInputStream();
                  headers = t.getResponseHeaders();
                  headers.add("Content-Type", sContentType);
                  t.sendResponseHeaders(200, size);
                  os = t.getResponseBody();
                  int iReadByte = inConnectionReader.read();
                  while (iReadByte != -1) {
                      os.write(iReadByte);
                      iReadByte = inConnectionReader.read();
                  }
              } else {
                  headers = t.getResponseHeaders();
                  headers.add("Content-Type", "text/html");
                  String sErrorMessage = "Error getting webpage.";
                  t.sendResponseHeaders(404, sErrorMessage.length());
                  os = t.getResponseBody();
                  os.write(sErrorMessage.getBytes());
              }
  
              if(os != null) {
                  os.close();
              }
  
          } catch (Exception e) {
              e.printStackTrace();
          }
  </code></pre>