use of com.salesmanager.core.model.content.InputContentFile in project shopizer by shopizer-ecommerce.
the class StaticContentTest method createImage.
@Test
public void createImage() throws ServiceException, FileNotFoundException, IOException {
MerchantStore store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
final File file1 = new File(IMAGE_FILE);
if (!file1.exists() || !file1.canRead()) {
throw new ServiceException("Can't read" + file1.getAbsolutePath());
}
final byte[] is = IOUtils.toByteArray(new FileInputStream(file1));
final ByteArrayInputStream inputStream = new ByteArrayInputStream(is);
final InputContentFile cmsContentImage = new InputContentFile();
cmsContentImage.setFileName(file1.getName());
cmsContentImage.setFile(inputStream);
cmsContentImage.setFileContentType(FileContentType.IMAGE);
// Add image
contentService.addContentFile(store.getCode(), cmsContentImage);
// get image
OutputContentFile image = contentService.getContentFile(store.getCode(), FileContentType.IMAGE, file1.getName());
// print image
OutputStream outputStream = new FileOutputStream(OUTPUT_FOLDER + image.getFileName());
ByteArrayOutputStream baos = image.getFile();
baos.writeTo(outputStream);
// remove image
contentService.removeFile(store.getCode(), FileContentType.IMAGE, file1.getName());
}
Aggregations