public void readResponse(InputStream in, long length) throws IOException {
        final byte[] resourceData;
        if (length == -1) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            int nextByte;
            while ( (nextByte = in.read()) != -1) {
                baos.write(nextByte);
            }
            resourceData = baos.toByteArray();
        }
        else {
            resourceData = new byte[(int)length];
            DataInputStream din = new DataInputStream(in);
            din.readFully(resourceData);
        }
        
        //notify the listener
        notifySuccess(resourceData);
        
        try {
            WFFileConnection file = m_persistence.openFile(m_fullFilePath);
            if(LOG.isDebug()) {
                LOG.debug("ResourceRequestTask.readResponse()", 
                        "writing to: "+m_fullFilePath);
            }
            file.openDataOutputStream().write(resourceData);
            file.close();
            m_resMgr.addResourceToCacheList(
                    m_firstRequest.getResourceName(), m_firstRequest.getRequestType());
        } catch (PermissionsException e) {
            if(LOG.isError()) {
                LOG.error("ResourceRequestTask.readResponse()", e);
            }
            error(new UnexpectedError(
                    "PermissionsException while opening "+m_fullFilePath, e));
        }
    }