TextReadmeReader.java

/*
 * Copyright © 2024-2025 The CTAN Team and individual authors
 *
 * This file is distributed under the 3-clause BSD license.
 * See file LICENSE for details.
 */

package org.ctan.site.services.texarchive.readme;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.file.Files;

/**
 * The class <code>TextReadmeReader</code> contains the reader for text.
 *
 * @author <a href="mailto:gene@ctan.org">Gerd Neugebauer</a>
 */
public class TextReadmeReader extends ReadmeReader {

    /**
     * This is the constructor for <code>TextReadmeReader</code>.
     *
     * @param name the file name
     */
    public TextReadmeReader(String name) {

        super(name);
    }

    /**
     * {@inheritDoc}
     *
     * @see org.ctan.site.services.texarchive.readme.ReadmeReader#read(
     *     java.io.File)
     */
    @Override
    public String read(File file)
            throws UnsupportedEncodingException,
                IOException {

        var content = new String(Files.readAllBytes(file.toPath()), "UTF8")
            .replaceAll("&", "&amp;")
            .replaceAll("<", "&lt;")
            .replaceAll(">", "&gt;");
        return "<pre>" + content + "</pre>";
    }

}