com.firstbanknigeria.ofsaaenhancers.UI.AdjustmentFileProcessor.java Source code

Java tutorial

Introduction

Here is the source code for com.firstbanknigeria.ofsaaenhancers.UI.AdjustmentFileProcessor.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.firstbanknigeria.ofsaaenhancers.UI;

import com.logix.utils.excel.ExcelProcessor;
import com.vaadin.ui.Upload;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;

/**
 *
 * @author mex
 */
public class AdjustmentFileProcessor implements Upload.Receiver, Upload.SucceededListener {

    ByteArrayOutputStream outStream;
    AdjustmentUI adjustmentUI;

    @Override
    public OutputStream receiveUpload(String filename, String mimeType) {
        System.out.println("byte stream");
        outStream = new ByteArrayOutputStream();
        return outStream;
    }

    @Override
    public void uploadSucceeded(Upload.SucceededEvent event) {

        try {
            ExcelProcessor excel = new ExcelProcessor(new ByteArrayInputStream(outStream.toByteArray()));
            List<List<String>> excelSheet = excel.getExcelSheet(0);
            adjustmentUI.setExcelContents(excelSheet);
        } catch (IOException ex) {
            Logger.getLogger(AdjustmentFileProcessor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvalidFormatException ex) {
            Logger.getLogger(AdjustmentFileProcessor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void setAdjustmentUI(AdjustmentUI adjustmentUI) {
        this.adjustmentUI = adjustmentUI;
    }

}