package con.docFlow.vaadin.fileExplorer; import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import org.vaadin.easyuploads.FileBuffer; import org.vaadin.easyuploads.FileFactory; import org.vaadin.easyuploads.MultiFileUpload; import org.vaadin.easyuploads.UploadField; import org.vaadin.easyuploads.UploadField.FieldType; import org.vaadin.easyuploads.UploadField.StorageMode; import com.vaadin.Application; import com.vaadin.data.util.ObjectProperty; import com.vaadin.terminal.Resource; import com.vaadin.terminal.StreamResource; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Component; import com.vaadin.ui.Embedded; import com.vaadin.ui.Label; import com.vaadin.ui.Window; @SuppressWarnings("serial") public class UploadfieldExampleApplication extends Application { private static final String TEMP_FILE_DIR = new File( System.getProperty("java.io.tmpdir")).getPath(); @Override public void init() { final Window mainWindow = new Window("Easy upload tests"); setMainWindow(mainWindow); mainWindow.addComponent(hr()); MultiFileUpload multiFileUpload3 = new SlowMultiFileUpload(); multiFileUpload3.setCaption("MultiFileUpload (simulated slow network)"); multiFileUpload3.setUploadButtonCaption("Choose File(s)"); mainWindow.addComponent(multiFileUpload3); } class SlowMultiFileUpload extends MultiFileUpload { @Override protected void handleFile(File file, String fileName, String mimeType, long length) { String msg = fileName + " uploaded."; getWindow().showNotification(msg); } @Override protected FileBuffer createReceiver() { return new FileBuffer() { @Override public FileFactory getFileFactory() { return SlowMultiFileUpload.this.getFileFactory(); } @Override public OutputStream receiveUpload(String filename, String MIMEType) { final OutputStream receiveUpload = super.receiveUpload( filename, MIMEType); OutputStream slow = new OutputStream() { private int slept; private int written; @Override public void write(int b) throws IOException { receiveUpload.write(b); written++; if (slept < 60000 && written % 1024 == 0) { int sleep = 5; slept += sleep; try { Thread.sleep(sleep); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }; return slow; } }; } } private Component hr() { Label label = new Label("