Search in sources :

Example 1 with MultiFileBuffer

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

the class MultiFileBufferTest method shouldBeAbleToReadFilesAfterReceiving.

@Test
public void shouldBeAbleToReadFilesAfterReceiving() throws IOException {
    MultiFileBuffer fileBuffer = new MultiFileBuffer();
    TestData[] testData = { new TestData("upload1", "Upload data 1"), new TestData("upload2", "Upload data 2"), new TestData("upload3", "Upload data 3") };
    for (TestData data : testData) {
        final byte[] dataBytes = data.data.getBytes(Charset.defaultCharset());
        try (OutputStream os = fileBuffer.receiveUpload(data.filename, "text")) {
            os.write(dataBytes);
        }
    }
    for (TestData data : testData) {
        final String readData = IOUtils.toString(fileBuffer.getInputStream(data.filename), Charset.defaultCharset());
        Assert.assertEquals(data.data, readData);
    }
}
Also used : OutputStream(java.io.OutputStream) MultiFileBuffer(com.vaadin.flow.component.upload.receivers.MultiFileBuffer) Test(org.junit.Test)

Example 2 with MultiFileBuffer

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

the class FileBufferView method createMultiFileUpload.

private static Div createMultiFileUpload() {
    final MultiFileBuffer buffer = new MultiFileBuffer();
    final Upload multiFileUpload = new Upload(buffer);
    multiFileUpload.setId("multi-upload");
    return setupUploadSection(multiFileUpload, e -> buffer.getInputStream(e.getFileName()));
}
Also used : Upload(com.vaadin.flow.component.upload.Upload) MultiFileBuffer(com.vaadin.flow.component.upload.receivers.MultiFileBuffer)

Aggregations

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