BoxingByteArrayImageConverter.java 1.26 KB
package com.taover.easyexcel.converters.bytearray;

import com.taover.easyexcel.converters.Converter;
import com.taover.easyexcel.enums.CellDataTypeEnum;
import com.taover.easyexcel.metadata.CellData;
import com.taover.easyexcel.metadata.GlobalConfiguration;
import com.taover.easyexcel.metadata.property.ExcelContentProperty;

/**
 * Boxing Byte array and image converter
 *
 * @author Jiaju Zhuang
 */
public class BoxingByteArrayImageConverter implements Converter<Byte[]> {
    @Override
    public Class supportJavaTypeKey() {
        return Byte[].class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.IMAGE;
    }

    @Override
    public Byte[] convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
        GlobalConfiguration globalConfiguration) {
        throw new UnsupportedOperationException("Cannot convert images to byte arrays");
    }

    @Override
    public CellData convertToExcelData(Byte[] value, ExcelContentProperty contentProperty,
        GlobalConfiguration globalConfiguration) {
        byte[] byteValue = new byte[value.length];
        for (int i = 0; i < value.length; i++) {
            byteValue[i] = value[i];
        }
        return new CellData(byteValue);
    }

}