List of usage examples for com.liferay.portal.kernel.repository.model FileVersion getContentStream
public InputStream getContentStream(boolean incrementCounter) throws PortalException;
From source file:com.liferay.adaptive.media.image.internal.handler.AdaptiveMediaImageRequestHandler.java
License:Open Source License
private AdaptiveMedia<AdaptiveMediaImageProcessor> _createRawAdaptiveMedia(FileVersion fileVersion) throws PortalException { Map<String, String> properties = new HashMap<>(); AdaptiveMediaAttribute<Object, String> fileName = AdaptiveMediaAttribute.fileName(); properties.put(fileName.getName(), fileVersion.getFileName()); AdaptiveMediaAttribute<Object, String> contentType = AdaptiveMediaAttribute.contentType(); properties.put(contentType.getName(), fileVersion.getMimeType()); AdaptiveMediaAttribute<Object, Integer> contentLength = AdaptiveMediaAttribute.contentLength(); properties.put(contentLength.getName(), String.valueOf(fileVersion.getSize())); return new AdaptiveMediaImage(() -> { try {/*from ww w.j a v a 2 s . co m*/ return fileVersion.getContentStream(false); } catch (PortalException pe) { throw new AdaptiveMediaRuntimeException(pe); } }, AdaptiveMediaImageAttributeMapping.fromProperties(properties), null); }
From source file:com.liferay.adaptive.media.image.internal.handler.AdaptiveMediaImageRequestHandlerTest.java
License:Open Source License
private AdaptiveMedia<AdaptiveMediaImageProcessor> _createAdaptiveMedia(FileVersion fileVersion, AdaptiveMediaImageConfigurationEntry configurationEntry) throws Exception { Map<String, String> properties = new HashMap<>(); AdaptiveMediaAttribute<Object, String> configurationUuid = AdaptiveMediaAttribute.configurationUuid(); properties.put(configurationUuid.getName(), configurationEntry.getUUID()); AdaptiveMediaAttribute<Object, String> fileName = AdaptiveMediaAttribute.fileName(); properties.put(fileName.getName(), fileVersion.getFileName()); AdaptiveMediaAttribute<Object, String> contentType = AdaptiveMediaAttribute.contentType(); properties.put(contentType.getName(), fileVersion.getMimeType()); AdaptiveMediaAttribute<Object, Integer> contentLength = AdaptiveMediaAttribute.contentLength(); properties.put(contentLength.getName(), String.valueOf(fileVersion.getSize())); Map<String, String> configurationEntryProperties = configurationEntry.getProperties(); properties.put(AdaptiveMediaImageAttribute.IMAGE_WIDTH.getName(), configurationEntryProperties.get("max-width")); properties.put(AdaptiveMediaImageAttribute.IMAGE_HEIGHT.getName(), configurationEntryProperties.get("max-height")); return new AdaptiveMediaImage(() -> { try {//from w w w . j av a 2 s. c o m return fileVersion.getContentStream(false); } catch (PortalException pe) { throw new AdaptiveMediaRuntimeException(pe); } }, AdaptiveMediaImageAttributeMapping.fromProperties(properties), null); }
From source file:com.liferay.adaptive.media.image.internal.handler.AdaptiveMediaImageRequestHandlerTest.java
License:Open Source License
private FileVersion _getFileVersion() throws PortalException { FileVersion fileVersion = Mockito.mock(FileVersion.class); Mockito.when(fileVersion.getCompanyId()).thenReturn(1234L); Mockito.when(fileVersion.getContentStream(false)).thenReturn(Mockito.mock(InputStream.class)); Mockito.when(fileVersion.getMimeType()).thenReturn("image/jpg"); Mockito.when(fileVersion.getFileName()).thenReturn("fileName"); Mockito.when(fileVersion.getSize()).thenReturn(2048L); return fileVersion; }
From source file:com.liferay.adaptive.media.image.internal.handler.AMImageRequestHandler.java
License:Open Source License
private AdaptiveMedia<AMImageProcessor> _createRawAdaptiveMedia(FileVersion fileVersion) throws PortalException { Map<String, String> properties = new HashMap<>(); AMAttribute<Object, String> fileNameAMAttribute = AMAttribute.getFileNameAMAttribute(); properties.put(fileNameAMAttribute.getName(), fileVersion.getFileName()); AMAttribute<Object, String> contentTypeAMAttribute = AMAttribute.getContentTypeAMAttribute(); properties.put(contentTypeAMAttribute.getName(), fileVersion.getMimeType()); AMAttribute<Object, Long> contentLengthAMAttribute = AMAttribute.getContentLengthAMAttribute(); properties.put(contentLengthAMAttribute.getName(), String.valueOf(fileVersion.getSize())); return new AMImage(() -> { try {/* w w w . j a va 2s . co m*/ return fileVersion.getContentStream(false); } catch (PortalException pe) { throw new AMRuntimeException(pe); } }, AMImageAttributeMapping.fromProperties(properties), null); }
From source file:com.liferay.adaptive.media.image.internal.handler.AMImageRequestHandlerTest.java
License:Open Source License
private AdaptiveMedia<AMImageProcessor> _createAdaptiveMedia(FileVersion fileVersion, AMImageConfigurationEntry amImageConfigurationEntry) throws Exception { Map<String, String> properties = new HashMap<>(); AMAttribute<Object, String> configurationUuidAMAttribute = AMAttribute.getConfigurationUuidAMAttribute(); properties.put(configurationUuidAMAttribute.getName(), amImageConfigurationEntry.getUUID()); AMAttribute<Object, String> fileNameAMAttribute = AMAttribute.getFileNameAMAttribute(); properties.put(fileNameAMAttribute.getName(), fileVersion.getFileName()); AMAttribute<Object, String> contentTypeAMAttribute = AMAttribute.getContentTypeAMAttribute(); properties.put(contentTypeAMAttribute.getName(), fileVersion.getMimeType()); AMAttribute<Object, Long> contentLengthAMAttribute = AMAttribute.getContentLengthAMAttribute(); properties.put(contentLengthAMAttribute.getName(), String.valueOf(fileVersion.getSize())); Map<String, String> configurationEntryProperties = amImageConfigurationEntry.getProperties(); properties.put(AMImageAttribute.AM_IMAGE_ATTRIBUTE_WIDTH.getName(), configurationEntryProperties.get("max-width")); properties.put(AMImageAttribute.AM_IMAGE_ATTRIBUTE_HEIGHT.getName(), configurationEntryProperties.get("max-height")); return new AMImage(() -> { try {// ww w . j a v a 2s.co m return fileVersion.getContentStream(false); } catch (PortalException pe) { throw new AMRuntimeException(pe); } }, AMImageAttributeMapping.fromProperties(properties), null); }
From source file:com.liferay.adaptive.media.image.internal.scaler.AMDefaultImageScaler.java
License:Open Source License
private InputStream _getInputStream(FileVersion fileVersion) { try {/* w w w . j a v a2 s. c om*/ return fileVersion.getContentStream(false); } catch (PortalException pe) { throw new AMRuntimeException.IOException(pe); } }
From source file:com.liferay.adaptive.media.image.internal.scaler.AMGIFImageScaler.java
License:Open Source License
private File _getFile(FileVersion fileVersion) throws IOException, PortalException { if (fileVersion instanceof LiferayFileVersion) { LiferayFileVersion liferayFileVersion = (LiferayFileVersion) fileVersion; return liferayFileVersion.getFile(false); }/* w ww . ja v a 2 s . c o m*/ try (InputStream inputStream = fileVersion.getContentStream(false)) { return FileUtil.createTempFile(inputStream); } }
From source file:com.liferay.adaptive.media.image.internal.util.ImageProcessor.java
License:Open Source License
private InputStream _getInputStream(FileVersion fileVersion) { try {/* w ww. ja va2s .c om*/ return fileVersion.getContentStream(false); } catch (PortalException pe) { throw new AdaptiveMediaRuntimeException.IOException(pe); } }
From source file:com.liferay.blogs.demo.data.creator.internal.BaseBlogsEntryDemoDataCreator.java
License:Open Source License
private byte[] _getRandomImageBytes(long userId, long groupId) throws IOException, PortalException { if (_blogsEntryImagesFolder == null) { _blogsEntryImagesFolder = rootFolderDemoDataCreator.create(userId, groupId, "Blogs Images"); }/*from w ww .j a va 2 s . co m*/ FileEntry fileEntry = fileEntryDemoDataCreator.create(userId, _blogsEntryImagesFolder.getFolderId()); FileVersion fileVersion = fileEntry.getFileVersion(); return FileUtil.getBytes(fileVersion.getContentStream(false)); }
From source file:com.liferay.compat.hook.webdav.CompatResourceInvocationHandler.java
License:Open Source License
protected InputStream getContentAsStream() throws WebDAVException { try {/*from w ww . j a v a2 s .c o m*/ FileVersion fileVersion = _fileEntry.getLatestFileVersion(); return fileVersion.getContentStream(false); } catch (Exception e) { throw new WebDAVException(e); } }