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);
}
}
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"));
}
Aggregations