code: private void flushURLConnection(URLConnection conn) {
          byte[] buf = new byte[1024];
          try {
              InputStream is = conn.getInputStream();
              while (is.read(buf) >= 0) {
                  // Ignore
              }
              is.close();
          } catch (IOException e) {
              try {
                  InputStream es = ((HttpURLConnection) conn).getErrorStream();
                  if (es != null) {
                      while (es.read(buf) >= 0) {
                          // Ignore
                      }
                      es.close();
                  }
              } catch (IOException ex) {
                  // Ignore
              }
          }
      }
docs: Flush the supplied {@link URLConnection} input and close the
  connection nicely.
  
  @param conn the connection to flush/close