class SimTextFilePreviewImpl implements FilePreview {

    private final FileHandlerService fileHandlerService;
    private final OtherFilePreviewImpl otherFilePreview;

    public SimTextFilePreviewImpl(FileHandlerService fileHandlerService,OtherFilePreviewImpl otherFilePreview) {
        this.fileHandlerService = fileHandlerService;
        this.otherFilePreview = otherFilePreview;
    }

    @Override
    public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
        String fileName = fileAttribute.getName();
        boolean forceUpdatedCache=fileAttribute.forceUpdatedCache();
        String filePath = fileAttribute.getOriginFilePath();
        if (forceUpdatedCache || !fileHandlerService.listConvertedFiles().containsKey(fileName) || !ConfigConstants.isCacheEnabled()) {
            ReturnResponse<String> response = DownloadUtils.downLoad(fileAttribute, fileName);
            if (response.isFailure()) {
                return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg());
            }
            filePath = response.getContent();
            if (ConfigConstants.isCacheEnabled()) {
                fileHandlerService.addConvertedFile(fileName, filePath);  //加入缓存
            }
            try {
                String  fileData = HtmlUtils.htmlEscape(textData(filePath,fileName));
                model.addAttribute("textData", Base64.encodeBase64String(fileData.getBytes()));
            } catch (IOException e) {
                return otherFilePreview.notSupportedFile(model, fileAttribute, e.getLocalizedMessage());
            }
            return TXT_FILE_PREVIEW_PAGE;
        }
        String  fileData = null;
        try {
            fileData = HtmlUtils.htmlEscape(textData(filePath,fileName));
        } catch (IOException e) {
            e.printStackTrace();
        }
        model.addAttribute("textData", Base64.encodeBase64String(fileData.getBytes()));
        return TXT_FILE_PREVIEW_PAGE;
    }

    private String textData(String filePath,String fileName) throws IOException {<FILL_FUNCTION_BODY>}
}

        File file = new File(filePath);
        if (KkFileUtils.isIllegalFileName(fileName)) {
            return null;
        }
        if (!file.exists() || file.length() == 0) {
            return "";
        } else {
            String charset = EncodingDetects.getJavaEncode(filePath);
            if ("ASCII".equals(charset)) {
                charset = StandardCharsets.US_ASCII.name();
            }
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), charset));
            StringBuilder result = new StringBuilder();
            String line;
            while ((line = br.readLine()) != null) {
                result.append(line).append("\r\n");
            }
            br.close();
            return result.toString();
        }
    
<no_super_class>