package com.workfusion.odf.impl.converter.excel2html;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

public class ToHtmlConverter {

    public byte[] convertToHTML(final byte[] content){
        try(
                InputStream input = new ByteArrayInputStream(content);
                ByteArrayOutputStream output = new ByteArrayOutputStream();
                PrintWriter printWriter = new PrintWriter(output)
        ) {

            ToHtml toHtml = ToHtml.create(input, printWriter);
            toHtml.setCompleteHTML(true);
            toHtml.printPage();
            return output.toByteArray();//StandardCharsets.UTF_8.name()

        } catch (IOException exception) {
            throw new RuntimeException("Could not convert excel file to HTML",exception);
        }
    }

}
