title: Handling gzipped content on Android
body: <p>I'm trying to parse a file from the web on Android using the DOM method. </p>
  
  <p>The code in question is:</p>
  
  <pre><code>try {
      URL url = new URL("https://www.beatport.com/en-US/xml/content/home/detail/1/welcome_to_beatport");
  
      InputSource is = new InputSource(url.openStream());
  
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();
      Document document = db.parse(is);
      document.getDocumentElement().normalize();
  } catch(Exception e) {
      Log.v(TAG, "Exception = " + e);
  }
  </code></pre>
  
  <p>But I'm getting the following exception:</p>
  
  <pre><code>V/XMLParseTest1(  846):Exception = org.xml.sax.SAXParseException: name expected (position:START_TAG &lt;null&gt;@2:176 in java.io.InputStreamReader@43ea4538) 
  </code></pre>
  
  <p>The file is being handed to me gzipped. I've checked the <code>is</code> object in the debugger and its length is 6733 bytes (the same as the content length of the file in the response headers) however if I save the file to my harddrive from the browser it's size is 59114 bytes. Furthermore if I upload it to my own server which doesn't gzip XML-s when it serves them and set the URL the code runs just fine.</p>
  
  <p>I'm guessing that what happens is that Android tries to parse the gzipped stream.</p>
  
  <p>Is there a way to first unzip the stream? Any other ideas?</p>