private void readAndValidateRecordFile(
        Integer recordKey, String xmlPath, String formatPrefix, String state,
        Connection conn) {
        File recordFile = _cache.getFile(xmlPath);
        ValidationInfo validationInfo = null;
        BufferedReader reader = null;
        StringBuffer contentBuffer = new StringBuffer();
        try {
            reader =
                new BufferedReader(new InputStreamReader(new FileInputStream(
                    recordFile), "UTF-8"));
            String line = reader.readLine();
            while (line != null) {
                contentBuffer.append(line);
                line = reader.readLine();
            }
            String content = contentBuffer.toString();
            if (content.indexOf("<header status=\"deleted\">") == -1) {
                // read xml content from oai record
                int tmpIndex = content.indexOf("<metadata>");
                int startIndex = tmpIndex + 10;
                int endIndex = content.length() - 21;
                String xml = content.substring(startIndex, endIndex);
                xml = xml.trim();
                validationInfo = _validator.validate(formatPrefix, xml);

                if (validationInfo.getResult().equals(ValidationResult.invalid)) {
                    _db.deleteRecord(conn, recordKey.intValue(), xmlPath);
                }
                else if (!validationInfo.getResult().toString().equals(state)) {
                    _db.changeRecordState(recordKey.intValue(), validationInfo
                        .getResult().toString(), conn);
                }
                if (!validationInfo.getResult().equals(ValidationResult.valid)) {
                    _LOG.warn("Failed to validate record", validationInfo
                        .getFailReason());
                }
            }
        }
        catch (Exception e) {
            _LOG.info("Error reading from file: " + xmlPath);
            throw new ServerException("Error reading from file: " + xmlPath, e);

        }
        finally {
            if (reader != null)
                try {
                    reader.close();
                }
                catch (Exception e) {
                }
        }
    }