protected function getFileHandle($fullPath, $mode)
    {
        $key = md5($fullPath.$mode);
        if (array_key_exists($key, $this->openFileHandles)) {
            $handle = $this->openFileHandles[$key];
        } else {
            $handle = fopen($fullPath, $mode);
            $this->openFileHandles[$key] = $handle;
        }

        if ('stream' !== get_resource_type($handle)) {
            throw new \Exception('The file handle is not a file stream!');
        }

        if (false !== strpos($mode, 'w')) {
            if ('stream' === !is_writeable($fullPath)) {
                throw new \Exception('The file handle in the context is not writeable!');
            }
        }

        return $handle;
    }