public function read($len = null)
    {
        if (!class_exists('Tidy')) {
            throw new BuildException("You must enable the 'tidy' extension in your PHP configuration in order to use the Tidy filter.");
        }

        if (!$this->getInitialized()) {
            $this->_initialize();
            $this->setInitialized(true);
        }

        $buffer = $this->in->read($len);
        if ($buffer === -1) {
            return -1;
        }

        $config = $this->getDistilledConfig();

        $tidy = new Tidy();
        $tidy->parseString($buffer, $config, $this->encoding);
        $tidy->cleanRepair();

        return tidy_get_output($tidy);
    }