DownloadStream: Downloaded file format corrupted....

I am downloading a file (using vaadin’s Download Stream)to client’s local system, which works fine. It also saves the file, but the file is corrupted. It displays a message saying’…File is not correctly decoded…" I can never open the file. I checked the encoding style of the input stream, it is set to UTF-8.
I am recieving a bytearrayoutputstream, i am converting it into bytearrayinputstream and passing as a parameter to DownloadStream constructor.

like this…
byte byteArrayOutputStream=ouputStreamFrom.toByteArray();
ByteArrayInputStream inputStream=new ByteArrayInputStream(byteArrayOutputStream);

final DownloadStream ds = new DownloadStream(inputStream, getMIMEType(), getFilename());

Do i have to format the encoding/decoding style before I save it… …Any ideas…
I was following the below thread…

Additional Details…source code…

public class FileDownloadResource extends FileResource {

private static transient final Logger logger = LoggerFactory.getLogger(FileDownloadResource.class);
private ByteArrayOutputStream ouputStreamFromOtherClass;

public FileDownloadResource(File sourceFile, Application application) {
super(sourceFile, application);

public void setByteOutStream(ByteArrayOutputStream ouputStreamFromOtherClass){

public DownloadStream getStream() {
try {
		byte[] byteArrayOutputStream=ouputStreamFromBo.toByteArray();
		ByteArrayInputStream inputStream=new ByteArrayInputStream(byteArrayOutputStream);			
		InputStreamReader streamReader=new InputStreamReader(inputStream);"The encoding style is  : "+streamReader.getEncoding());//log statement
		final DownloadStream ds = new DownloadStream(inputStream, getMIMEType(), getFilename());
		ds.setParameter("Content-Disposition", "attachment; filename="+getFilename());
		return ds;
	} catch (Exception ex) {"IOException occured in getStream method   "+ex.getMessage());
		return null;
}//end of getStream() method


//in the onclick event listener of download button…

FileDownloadResource downloadFile=new FileDownloadResource(
new File(path+File.separatorChar+“VAADIN”+File.separatorChar+“export”+
File.separatorChar+fileName), mainWindow.getApplication());