Search in sources :

Example 6 with BinaryFile

use of com.liferay.apio.architect.file.BinaryFile in project com-liferay-apio-architect by liferay.

the class MultipartBodyMessageBodyReader method _storeFileItem.

private void _storeFileItem(FileItem fileItem, Consumer<String> valueConsumer, Consumer<BinaryFile> fileConsumer) throws IOException {
    if (fileItem.isFormField()) {
        InputStream stream = fileItem.getInputStream();
        valueConsumer.accept(Streams.asString(stream));
    } else {
        BinaryFile binaryFile = new BinaryFile(fileItem.getInputStream(), fileItem.getSize(), fileItem.getContentType());
        fileConsumer.accept(binaryFile);
    }
}
Also used : InputStream(java.io.InputStream) BinaryFile(com.liferay.apio.architect.file.BinaryFile)

Example 7 with BinaryFile

use of com.liferay.apio.architect.file.BinaryFile in project com-liferay-apio-architect by liferay.

the class BinaryEndpointTest method testBinaryEndpointWithValidFunctionsReturnInputStream.

@Test
public void testBinaryEndpointWithValidFunctionsReturnInputStream() {
    BinaryEndpoint binaryEndpoint = _getBinaryEndpoint(_representor());
    Try<BinaryFile> binaryFileTry = binaryEndpoint.getCollectionItemBinaryFileTry("", "", "binary");
    BinaryFile binaryFile = binaryFileTry.getUnchecked();
    assertThat(binaryFile.getSize(), is(0L));
    InputStream inputStream = binaryFile.getInputStream();
    String result = Try.fromFallibleWithResources(() -> new BufferedReader(new InputStreamReader(inputStream)), BufferedReader::readLine).getUnchecked();
    assertThat(result, is("Apio"));
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) BinaryFile(com.liferay.apio.architect.file.BinaryFile) Test(org.junit.Test)

Aggregations

BinaryFile (com.liferay.apio.architect.file.BinaryFile)7 InputStream (java.io.InputStream)3 BufferedReader (java.io.BufferedReader)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStreamReader (java.io.InputStreamReader)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 BadRequestException (javax.ws.rs.BadRequestException)2 BOOLEAN (com.liferay.apio.architect.form.FieldType.BOOLEAN)1 BOOLEAN_LIST (com.liferay.apio.architect.form.FieldType.BOOLEAN_LIST)1 DATE (com.liferay.apio.architect.form.FieldType.DATE)1 DATE_LIST (com.liferay.apio.architect.form.FieldType.DATE_LIST)1 DOUBLE (com.liferay.apio.architect.form.FieldType.DOUBLE)1 DOUBLE_LIST (com.liferay.apio.architect.form.FieldType.DOUBLE_LIST)1 FILE (com.liferay.apio.architect.form.FieldType.FILE)1 FILE_LIST (com.liferay.apio.architect.form.FieldType.FILE_LIST)1 LONG (com.liferay.apio.architect.form.FieldType.LONG)1 LONG_LIST (com.liferay.apio.architect.form.FieldType.LONG_LIST)1 STRING (com.liferay.apio.architect.form.FieldType.STRING)1