Example usage for com.liferay.portal.kernel.repository.model FileEntry getContentStream

List of usage examples for com.liferay.portal.kernel.repository.model FileEntry getContentStream

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.repository.model FileEntry getContentStream.

Prototype

@JSON(include = false)
public InputStream getContentStream() throws PortalException;

Source Link

Document

Returns the content stream of the current file version.

Usage

From source file:au.com.permeance.liferay.portlet.documentlibrary.service.impl.DLFolderExportZipHelper.java

License:Open Source License

/**
 * Adds a file entry as a ZIP entry./*from  w w  w  .  j a  v  a2  s  .  c o m*/
 *
 * @param fileEntry file entry
 * @param folderPath folder path
 * @param zipWriter ZIP writer
 * 
 * @throws PortalException
 * @throws SystemException
 * @throws IOException
 */
public static void exportFileEntryToZipWriter(FileEntry fileEntry, String folderPath, ZipWriter zipWriter)
        throws PortalException, SystemException, IOException {

    InputStream fileInputStream = null;
    try {

        String zipEntryName = buildZipEntryName(fileEntry, folderPath, zipWriter);
        fileInputStream = fileEntry.getContentStream();
        zipWriter.addEntry(zipEntryName, fileInputStream);

    } catch (Exception e) {

        String zipWriterLabel = zipWriter.getPath();

        String msg = "Error exporting file entry " + fileEntry + " to ZIP writer " + zipWriterLabel + " : "
                + e.getMessage();

        s_log.error(msg, e);

        if (e instanceof PortalException) {
            throw (PortalException) e;

        } else if (e instanceof SystemException) {
            throw (SystemException) e;

        } else if (e instanceof IOException) {
            throw (IOException) e;

        } else {
            throw new PortalException(msg, e);
        }

    } finally {
        try {
            if (fileInputStream != null) {
                fileInputStream.close();
                fileInputStream = null;
            }
        } catch (Exception e) {
        }
    }
}

From source file:com.liferay.blogs.attachments.test.BaseBlogsEntryImageTestCase.java

License:Open Source License

@Test
public void testAddImage() throws Exception {
    BlogsEntry blogsEntry = addBlogsEntry((ImageSelector) null);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId(),
            user.getUserId());/*  w w  w  .  ja  v a 2s .co m*/

    FileEntry fileEntry = getTempFileEntry(user.getUserId(), "image1.jpg", serviceContext);

    ImageSelector imageSelector = new ImageSelector(FileUtil.getBytes(fileEntry.getContentStream()),
            fileEntry.getTitle(), fileEntry.getMimeType(), IMAGE_CROP_REGION);

    addImage(blogsEntry.getEntryId(), imageSelector);

    blogsEntry = BlogsEntryLocalServiceUtil.getEntry(blogsEntry.getEntryId());

    FileEntry imageFileEntry = PortletFileRepositoryUtil.getPortletFileEntry(getImageFileEntryId(blogsEntry));

    Assert.assertEquals("image1.jpg", imageFileEntry.getTitle());
}

From source file:com.liferay.blogs.attachments.test.BlogsEntryAttachmentFileEntryHelperTest.java

License:Open Source License

@Test
public void testAddBlogsEntryAttachmentFileEntries() throws Exception {
    FileEntry tempFileEntry = TempFileEntryUtil.addTempFileEntry(_group.getGroupId(), _user.getUserId(),
            _TEMP_FOLDER_NAME, "image.jpg", getInputStream(), ContentTypes.IMAGE_JPEG);

    List<BlogsEntryAttachmentFileEntryReference> blogsEntryAttachmentFileEntryReferences = getBlogsEntryAttachmentFileEntryReferences(
            tempFileEntry);/*from www.  j  a  va2  s.c om*/

    Assert.assertEquals(1, blogsEntryAttachmentFileEntryReferences.size());

    BlogsEntryAttachmentFileEntryReference blogsEntryAttachmentFileEntryReference = blogsEntryAttachmentFileEntryReferences
            .get(0);

    Assert.assertEquals(tempFileEntry.getFileEntryId(),
            blogsEntryAttachmentFileEntryReference.getTempBlogsEntryAttachmentFileEntryId());

    FileEntry fileEntry = blogsEntryAttachmentFileEntryReference.getBlogsEntryAttachmentFileEntry();

    Assert.assertEquals(tempFileEntry.getTitle(), fileEntry.getTitle());
    Assert.assertEquals(tempFileEntry.getMimeType(), fileEntry.getMimeType());
    Assert.assertEquals(DigesterUtil.digestBase64(tempFileEntry.getContentStream()),
            DigesterUtil.digestBase64(fileEntry.getContentStream()));
}

From source file:com.liferay.blogs.attachments.test.BlogsEntryCoverImageTest.java

License:Open Source License

@Override
protected BlogsEntry addBlogsEntry(String imageTitle) throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId(),
            user.getUserId());/*from  ww  w . j a  v a 2s  .  c om*/

    FileEntry fileEntry = getTempFileEntry(user.getUserId(), imageTitle, serviceContext);

    ImageSelector imageSelector = new ImageSelector(FileUtil.getBytes(fileEntry.getContentStream()),
            fileEntry.getTitle(), fileEntry.getMimeType(), IMAGE_CROP_REGION);

    return addBlogsEntry(imageSelector);
}

From source file:com.liferay.blogs.attachments.test.BlogsEntryCoverImageTest.java

License:Open Source License

@Override
protected BlogsEntry updateBlogsEntry(long blogsEntryId, String imageTitle) throws Exception {

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId(),
            user.getUserId());/*w ww . j  av a  2  s  .c o  m*/

    FileEntry fileEntry = getTempFileEntry(user.getUserId(), imageTitle, serviceContext);

    ImageSelector imageSelector = new ImageSelector(FileUtil.getBytes(fileEntry.getContentStream()),
            fileEntry.getTitle(), fileEntry.getMimeType(), IMAGE_CROP_REGION);

    return updateBlogsEntry(blogsEntryId, imageSelector);
}

From source file:com.liferay.blogs.attachments.test.BlogsEntrySmallImageTest.java

License:Open Source License

@Override
protected BlogsEntry addBlogsEntry(String imageTitle) throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId(),
            user.getUserId());/*ww  w .  j av  a2 s . c  o m*/

    FileEntry fileEntry = getTempFileEntry(user.getUserId(), imageTitle, serviceContext);

    ImageSelector imageSelector = new ImageSelector(FileUtil.getBytes(fileEntry.getContentStream()),
            fileEntry.getTitle(), fileEntry.getMimeType(), StringPool.BLANK);

    return addBlogsEntry(imageSelector);
}

From source file:com.liferay.blogs.attachments.test.BlogsEntrySmallImageTest.java

License:Open Source License

@Override
protected BlogsEntry updateBlogsEntry(long blogsEntryId, String coverImageTitle) throws Exception {

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId(),
            user.getUserId());/*from  w ww  .j  a v  a 2  s .co m*/

    FileEntry fileEntry = getTempFileEntry(user.getUserId(), coverImageTitle, serviceContext);

    ImageSelector imageSelector = new ImageSelector(FileUtil.getBytes(fileEntry.getContentStream()),
            fileEntry.getTitle(), fileEntry.getMimeType(), StringPool.BLANK);

    return updateBlogsEntry(blogsEntryId, imageSelector);
}

From source file:com.liferay.blogs.service.test.BlogsEntryLocalServiceTest.java

License:Open Source License

@Test
public void testAddOriginalImageInVisibleImageFolder() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId(),
            _user.getUserId());/*from w w  w.  j  av  a2 s.c  o m*/

    BlogsEntry blogsEntry = BlogsEntryLocalServiceUtil.addEntry(_user.getUserId(),
            RandomTestUtil.randomString(), RandomTestUtil.randomString(), serviceContext);

    FileEntry tempFileEntry = getTempFileEntry(_user.getUserId(), _group.getGroupId(), "image.jpg");

    ImageSelector imageSelector = new ImageSelector(FileUtil.getBytes(tempFileEntry.getContentStream()),
            tempFileEntry.getTitle(), tempFileEntry.getMimeType(), StringPool.BLANK);

    long originalImageFileEntryId = BlogsEntryLocalServiceUtil.addOriginalImageFileEntry(_user.getUserId(),
            _group.getGroupId(), blogsEntry.getEntryId(), imageSelector);

    FileEntry portletFileEntry = PortletFileRepositoryUtil.getPortletFileEntry(originalImageFileEntryId);

    Folder folder = portletFileEntry.getFolder();

    Assert.assertEquals(BlogsConstants.SERVICE_NAME, folder.getName());
}

From source file:com.liferay.blogs.util.BlogsEntryAttachmentFileEntryUtil.java

License:Open Source License

public static List<BlogsEntryAttachmentFileEntryReference> addBlogsEntryAttachmentFileEntries(long groupId,
        long userId, long blogsEntryId, long folderId, List<FileEntry> tempFileEntries) throws PortalException {

    List<BlogsEntryAttachmentFileEntryReference> blogsEntryAttachmentFileEntryReferences = new ArrayList<>();

    for (FileEntry tempFileEntry : tempFileEntries) {
        FileEntry blogsEntryAttachmentFileEntry = addBlogsEntryAttachmentFileEntry(groupId, userId,
                blogsEntryId, folderId, tempFileEntry.getTitle(), tempFileEntry.getMimeType(),
                tempFileEntry.getContentStream());

        blogsEntryAttachmentFileEntryReferences.add(new BlogsEntryAttachmentFileEntryReferenceAdapter(
                tempFileEntry.getFileEntryId(), blogsEntryAttachmentFileEntry));
    }/*from  ww  w  .j  a va2s  .  c o  m*/

    return blogsEntryAttachmentFileEntryReferences;
}

From source file:com.liferay.blogs.util.BlogsEntryImageSelectorHelper.java

License:Open Source License

public ImageSelector getImageSelector() throws Exception {
    if (_imageFileEntryId != _oldImageFileEntryId) {
        if (_imageFileEntryId != 0) {
            FileEntry fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(_imageFileEntryId);

            _fileEntryTempFile = fileEntry.isRepositoryCapabilityProvided(TemporaryFileEntriesCapability.class);

            return new ImageSelector(FileUtil.getBytes(fileEntry.getContentStream()), fileEntry.getFileName(),
                    fileEntry.getMimeType(), _imageCropRegion);
        } else {/*from w w  w  .  j  a  v  a 2 s .c  o  m*/
            return new ImageSelector();
        }
    } else if (!_imageURL.equals(_oldImageURL)) {
        return new ImageSelector(_imageURL);
    }

    return null;
}