Search in sources :

Example 1 with FileBuffer

use of com.vaadin.flow.component.upload.receivers.FileBuffer in project flow-components by vaadin.

the class FileBufferTest method shouldBeAbleToReadFileAfterReceiving.

@Test
public void shouldBeAbleToReadFileAfterReceiving() throws IOException {
    FileBuffer fileBuffer = new FileBuffer();
    final String data = "Upload data";
    final byte[] dataBytes = data.getBytes(Charset.defaultCharset());
    try (OutputStream os = fileBuffer.receiveUpload("uploadData", "text")) {
        os.write(dataBytes);
    }
    final String readData = IOUtils.toString(fileBuffer.getInputStream(), Charset.defaultCharset());
    Assert.assertEquals(data, readData);
}
Also used : FileBuffer(com.vaadin.flow.component.upload.receivers.FileBuffer) OutputStream(java.io.OutputStream) Test(org.junit.Test)

Example 2 with FileBuffer

use of com.vaadin.flow.component.upload.receivers.FileBuffer in project flow-components by vaadin.

the class FileBufferView method createSingleFileUpload.

private static Div createSingleFileUpload() {
    final FileBuffer buffer = new FileBuffer();
    final Upload singleFileUpload = new Upload(buffer);
    singleFileUpload.setId("single-upload");
    singleFileUpload.setMaxFiles(1);
    return setupUploadSection(singleFileUpload, e -> buffer.getInputStream());
}
Also used : FileBuffer(com.vaadin.flow.component.upload.receivers.FileBuffer) MultiFileBuffer(com.vaadin.flow.component.upload.receivers.MultiFileBuffer) Upload(com.vaadin.flow.component.upload.Upload)

Aggregations

FileBuffer (com.vaadin.flow.component.upload.receivers.FileBuffer)2 Upload (com.vaadin.flow.component.upload.Upload)1 MultiFileBuffer (com.vaadin.flow.component.upload.receivers.MultiFileBuffer)1 OutputStream (java.io.OutputStream)1 Test (org.junit.Test)1