/*******************************************************************************
* Copyright (C) 2016 Kwaku Twumasi-Afriyie <kwaku.twumasi@quakearts.com>.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Kwaku Twumasi-Afriyie <kwaku.twumasi@quakearts.com> - initial API and implementation
 ******************************************************************************/
package com.quakearts.webapp.facelets.bootstrap.utils;

import static com.quakearts.webapp.facelets.bootstrap.renderkit.RenderKitUtils.*;

import java.io.IOException;
import java.io.InputStream;

import javax.servlet.http.Part;

public class BootFileUpload {
	private String fileName;
	private byte[] data;
	
	public String getFileName() {
		return fileName;
	}
	
	public byte[] getData() {
		return data;
	}
	
	public BootFileUpload(String fileName, Part filePart) {
		this.fileName = fileName;
		data = new byte[(int)filePart.getSize()];
		try(InputStream is=filePart.getInputStream()) {
			is.read(data);
		} catch (IOException e) {
			LOGGER.warning("Exception of type " + e.getClass().getName()
					+ " was thrown. Message is " + e.getMessage()
					+ ". Exception occured whiles loading input file "+fileName);
		}
	}
		
}

@@ -917,16 +917,41 @@
  data;%0D%0A
+%09private Part filePart;%0D%0A
 %09%0D%0A%09publ
@@ -1038,116 +1038,28 @@
 %0D%0A%09%09
-return data;%0D%0A%09%7D%0D%0A%09%0D%0A%09public BootFileUpload(String fileName, Part filePart) %7B%0D%0A%09%09this.fileName = fileName;%0D%0A
+if(data == null)%7B%0D%0A%09
 %09%09da
@@ -1099,16 +1099,17 @@
 ze()%5D;%0D%0A
+%09
 %09%09try(In
@@ -1154,16 +1154,17 @@
 ) %7B%0D%0A%09%09%09
+%09
 is.read(
@@ -1171,16 +1171,17 @@
 data);%0D%0A
+%09
 %09%09%7D catc
@@ -1201,16 +1201,17 @@
 n e) %7B%0D%0A
+%09
 %09%09%09LOGGE
@@ -1272,16 +1272,17 @@
 )%0D%0A%09%09%09%09%09
+%09
 + %22 was 
@@ -1316,24 +1316,25 @@
 tMessage()%0D%0A
+%09
 %09%09%09%09%09+ %22. Ex
@@ -1391,17 +1391,219 @@
 me);%0D%0A%09%09
-%7D
+%09%7D%0D%0A%09%09%7D%0D%0A%09%09return data;%0D%0A%09%7D%0D%0A%09%0D%0A%09public Part getFilePart() %7B%0D%0A%09%09return filePart;%0D%0A%09%7D%0D%0A%09%0D%0A%09public BootFileUpload(String fileName, Part filePart) %7B%0D%0A%09%09this.fileName = fileName;%0D%0A%09%09this.filePart = filePart;
 %0D%0A%09%7D%0D%0A%09%09

Make BootFileUpload pass InputStream to user