response.setContentLength(resource.getContentLength());
    public void process(User user, HttpServletRequest request,            HttpServletResponse response, XmldbURI path)            throws ServletException, IOException {                DBBroker broker = null;        DocumentImpl resource = null;        Collection collection = null;                try {            broker = pool.get(user);            resource = broker.getXMLResource(path, Lock.READ_LOCK);                        if(resource == null) {                collection = broker.openCollection(path, Lock.READ_LOCK);                if(collection == null){                    response.sendError(HttpServletResponse.SC_NOT_FOUND);                                    } else {                    collectionListing(broker, collection, request, response);                }                return;            }                        if(!resource.getPermissions().validate(user, Permission.READ)) {                response.sendError(HttpServletResponse.SC_FORBIDDEN,                                    READ_PERMISSION_DENIED);                return;            }                        LockToken token = resource.getMetadata().getLockToken();            if(token!=null && token.isNullResource() ){                response.sendError(HttpServletResponse.SC_NOT_FOUND,                                    "Document is a Null resource and cannot be retrieved");                return;            }                                    DocumentMetadata metadata = resource.getMetadata();            response.setContentType(metadata.getMimeType());            response.addDateHeader("Last-Modified", metadata.getLastModified());                        response.setContentLength(resource.getContentLength());            ServletOutputStream os = response.getOutputStream();                        if(resource.getResourceType() == DocumentImpl.XML_FILE) {                Serializer serializer = broker.getSerializer();                serializer.reset();                try {                    serializer.setProperties(WebDAV.OUTPUT_PROPERTIES);                                        Writer w = new OutputStreamWriter(os,"UTF-8");                    serializer.serialize(resource,w);                    w.flush();                    w.close();                                    } catch (SAXException e) {                    LOG.error(e);                    throw new ServletException(SERIALIZE_ERROR + e.getMessage(), e);                }                            } else {                broker.readBinaryResource((BinaryDocument) resource, os);                os.flush();            }                        os.flush();                    } catch (EXistException e) {            throw new ServletException(SERIALIZE_ERROR + e.getMessage(), e);                    } catch (PermissionDeniedException e) {            LOG.error(e);            response.sendError(HttpServletResponse.SC_FORBIDDEN, READ_PERMISSION_DENIED);            return;                    } finally {            if(resource != null)                resource.getUpdateLock().release(Lock.READ_LOCK);                        if(collection != null)                collection.release();                        pool.release(broker);        }            }