private String validate(Path path) throws IOException, SAXException {
            if (!used.compareAndSet(false, true)) {
                throw new IllegalStateException("OneOffValidator instances are not reusable");
            }
            try {
                if (Files.notExists(path) || !Files.isReadable(path)) {
                    errorHandler.warning(new SAXParseException(
                            "File not found.", null, path.toString(), -1, -1));
                } else if (isXhtml(path.toFile())) {
                    if (forceHtml) {
                        validator.checkHtmlFile(path.toFile(), true);
                    } else {
                        validator.checkXmlFile(path.toFile());
                    }
                } else if (isHtml(path.toFile())) {
                    validator.checkHtmlFile(path.toFile(), true);
                } else {
                    errorHandler.warning(new SAXParseException(EXTENSION_ERROR, null, path.toString(), -1, -1));
                }
            } catch (SAXException e) {
                errorHandler.warning(new SAXParseException(e.getMessage(), null, path.toString(), -1, -1));
            }

            errorHandler.end(MSG_SUCCESS, MSG_FAIL, "");
            return new String(out.toByteArray(), StandardCharsets.UTF_8);
        }
Self-contained, single use class for encapsulated building of an embedded
validator.
src/nu/validator/client/EmbeddedValidator.java