title: Stream closed exception in java
body: <p>Please look at what I have done</p>
  
  <pre><code>private InputSource getContent(String fName) throws SAXException, IOException, ServiceException {
          // Some code here
          if(currentNodeRef != null)
          {
              ContentReader reader = contentService.getReader(currentNodeRef,ContentModel.PROP_CONTENT);
  
              InputStream inputStream = null;
               try 
               {  
                      inputStream = new BufferedInputStream(reader.getContentInputStream(),16384);
  
                      return new InputSource(inputStream);
               }
               finally
               {
                   if(inputStream!=null)
                      try 
                      {
                          inputStream.close();
                      } catch (IOException e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                      }
               }
          }
          return new InputSource();
  }
  </code></pre>
  
  <p>In my parseDocument method I called the above method.</p>
  
  <pre><code>parseDocRoot(getContent(fName),path);
  </code></pre>
  
  <p>In parseDocRoot</p>
  
  <pre><code>public  void parseDocRoot (InputSource ins, String path) throws SAXException, IOException,
    ParserConfigurationException, ServiceException
    {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
              builder.setEntityResolver(new EntityResolver() {
                  public InputSource resolveEntity(String publicId, String systemId)
                          throws SAXException, IOException {
                       return new InputSource(new ByteArrayInputStream(new byte[0])); 
                  }
              });
          Document doc = builder.parse(ins);
          NodeList list = doc.getChildNodes();
          parseDocument(list,path);
    }
  </code></pre>
  
  <p>I got a error Saying that Stream Not closed and while debugging the above code I found that the error is on the line </p>
  
  <pre><code>Document doc = builder.parse(ins);
  </code></pre>
  
  <p>Please help me finding the solution.</p>