Example usage for com.liferay.portal.kernel.io ByteArrayFileInputStream ByteArrayFileInputStream

List of usage examples for com.liferay.portal.kernel.io ByteArrayFileInputStream ByteArrayFileInputStream

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.io ByteArrayFileInputStream ByteArrayFileInputStream.

Prototype

public ByteArrayFileInputStream(File file, int threshold) 

Source Link

Usage

From source file:com.liferay.portlet.layoutsadmin.action.EditLayoutSetAction.java

License:Open Source License

protected void updateLogo(ActionRequest actionRequest, long liveGroupId, long stagingGroupId,
        boolean privateLayout, boolean hasLogo) throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    boolean useLogo = ParamUtil.getBoolean(actionRequest, "useLogo");

    InputStream inputStream = null;

    try {//from  w w  w  . ja  v  a 2s . co m
        File file = uploadPortletRequest.getFile("logoFileName");

        if (useLogo && !file.exists()) {
            if (hasLogo) {
                return;
            }

            throw new UploadException("No logo uploaded for use");
        }

        if (file.exists()) {
            inputStream = new ByteArrayFileInputStream(file, 1024);
        }

        if (inputStream != null) {
            inputStream.mark(0);
        }

        LayoutSetServiceUtil.updateLogo(liveGroupId, privateLayout, useLogo, inputStream, false);

        if (inputStream != null) {
            inputStream.reset();
        }

        if (stagingGroupId > 0) {
            LayoutSetServiceUtil.updateLogo(stagingGroupId, privateLayout, useLogo, inputStream, false);
        }
    } finally {
        StreamUtil.cleanUp(inputStream);
    }
}

From source file:com.liferay.portlet.usersadmin.action.EditOrganizationLogoAction.java

License:Open Source License

protected void updateLogo(ActionRequest actionRequest) throws Exception {
    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    long groupId = ParamUtil.getLong(uploadPortletRequest, "groupId");

    InputStream inputStream = null;

    try {// w  ww .  j av  a 2s.  c o  m
        File file = uploadPortletRequest.getFile("fileName");

        inputStream = new ByteArrayFileInputStream(file, 1024);

        inputStream.mark(0);

        LayoutSetServiceUtil.updateLogo(groupId, true, true, inputStream, false);

        inputStream.reset();

        LayoutSetServiceUtil.updateLogo(groupId, false, true, inputStream, false);
    } finally {
        StreamUtil.cleanUp(inputStream);
    }
}