Here is a quick “cut” from one of my working projects. I changed file to ByteArrayOutputStream as you asked, so take this as an example.
Note, that I quickly changed it in a text editor, so mispells could be present here, but in general this shows how to work with a file uploader. No matter, want you upload into a file or byte array - you simply create an appropriate output stream object and return it to uploader when asked - it will do the rest.
public class UploadTest extends VerticalLayout implements Receiver, Upload.SucceededListener
{
private Upload uploader = new Upload ( "Upload document", this );
ByteArrayOutputStream tmpFile = null;
public IrbisView ()
{
super ();
setMargin ( false );
setSpacing ( true );
uploader.addListener ( ( Upload.SucceededListener ) this );
}
public OutputStream receiveUpload ( String filename, String MIMEType )
{
try
{
tmpFile = new ByteArrayOutputStream();
return tmpFile;
}
catch ( IOException ex )
{
ex.printStackTrace ();
throw new RuntimeException ( ex );
}
}
public void uploadSucceeded ( SucceededEvent event )
{
if ( tmpFile != null)
{
System.out.println ( tmpFile.toByteArray() );
}
}
}