Java 类com.liferay.portal.kernel.util.StreamUtil 实例源码

项目:ch-inofix-timetracker    文件:ImportTaskRecordsMVCActionCommand.java   
protected void validateFile(ActionRequest actionRequest, ActionResponse actionResponse, String folderName)
        throws Exception {

    _log.info("validateFile()");

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

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

    FileEntry fileEntry = ExportImportHelperUtil.getTempFileEntry(groupId, themeDisplay.getUserId(), folderName);

    InputStream inputStream = null;

    try {
        inputStream = _dlFileEntryLocalService.getFileAsStream(fileEntry.getFileEntryId(), fileEntry.getVersion(),
                false);

        // TODO: validate uploaded file

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
        //
        // if ((weakMissingReferences != null) &&
        // !weakMissingReferences.isEmpty()) {
        //
        // jsonObject.put("warningMessages",
        // StagingUtil.getWarningMessagesJSONArray(themeDisplay.getLocale(),
        // weakMissingReferences));
        // }

        JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
    } finally {
        StreamUtil.cleanUp(inputStream);
    }
}
项目:ch-inofix-contact-manager    文件:ImportContactsMVCActionCommand.java   
protected void validateFile(ActionRequest actionRequest, ActionResponse actionResponse, String folderName)
        throws Exception {

    _log.info("validateFile()");

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

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

    FileEntry fileEntry = ExportImportHelperUtil.getTempFileEntry(groupId, themeDisplay.getUserId(), folderName);

    InputStream inputStream = null;

    try {
        inputStream = _dlFileEntryLocalService.getFileAsStream(fileEntry.getFileEntryId(), fileEntry.getVersion(),
                false);

        // TODO: validate uploaded file

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
        //
        // if ((weakMissingReferences != null) &&
        // !weakMissingReferences.isEmpty()) {
        //
        // jsonObject.put("warningMessages",
        // StagingUtil.getWarningMessagesJSONArray(themeDisplay.getLocale(),
        // weakMissingReferences));
        // }

        JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
    } finally {
        StreamUtil.cleanUp(inputStream);
    }
}
项目:ch-inofix-data-manager    文件:ImportMeasurementsMVCActionCommand.java   
protected void validateFile(ActionRequest actionRequest, ActionResponse actionResponse, String folderName)
        throws Exception {

    _log.info("validateFile()");

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

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

    FileEntry fileEntry = ExportImportHelperUtil.getTempFileEntry(groupId, themeDisplay.getUserId(), folderName);

    InputStream inputStream = null;

    try {
        inputStream = _dlFileEntryLocalService.getFileAsStream(fileEntry.getFileEntryId(), fileEntry.getVersion(),
                false);

        // TODO: validate uploaded file

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
        //
        // if ((weakMissingReferences != null) &&
        // !weakMissingReferences.isEmpty()) {
        //
        // jsonObject.put("warningMessages",
        // StagingUtil.getWarningMessagesJSONArray(themeDisplay.getLocale(),
        // weakMissingReferences));
        // }

        JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
    } finally {
        StreamUtil.cleanUp(inputStream);
    }
}
项目:ch-inofix-timetracker    文件:ImportTaskRecordsMVCActionCommand.java   
protected void addTempFileEntry(ActionRequest actionRequest, String folderName) throws Exception {

        _log.info("addTempFileEntry()");

        UploadPortletRequest uploadPortletRequest = _portal.getUploadPortletRequest(actionRequest);

        checkExceededSizeLimit(uploadPortletRequest);

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

        deleteTempFileEntry(groupId, folderName);

        InputStream inputStream = null;

        try {
            String sourceFileName = uploadPortletRequest.getFileName("file");

            inputStream = uploadPortletRequest.getFileAsStream("file");

            String contentType = uploadPortletRequest.getContentType("file");

            _layoutService.addTempFileEntry(groupId, folderName, sourceFileName, inputStream, contentType);
        } catch (Exception e) {
            UploadException uploadException = (UploadException) actionRequest.getAttribute(WebKeys.UPLOAD_EXCEPTION);

            if (uploadException != null) {
                Throwable cause = uploadException.getCause();

                if (cause instanceof FileUploadBase.IOFileUploadException) {
                    if (_log.isInfoEnabled()) {
                        _log.info("Temporary upload was cancelled");
                    }
                }

                if (uploadException.isExceededFileSizeLimit()) {
                    throw new FileSizeException(cause);
                }

                if (uploadException.isExceededUploadRequestSizeLimit()) {
                    throw new UploadRequestSizeException(cause);
                }
            } else {
                throw e;
            }
        } finally {
            StreamUtil.cleanUp(inputStream);
        }
    }
项目:ch-inofix-timetracker    文件:ImportTaskRecordsMVCActionCommand.java   
protected void importData(ActionRequest actionRequest, String folderName) throws Exception {

        _log.info("importData()");

        ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

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

        FileEntry fileEntry = ExportImportHelperUtil.getTempFileEntry(groupId, themeDisplay.getUserId(), folderName);

        InputStream inputStream = null;

        try {
            inputStream = _dlFileEntryLocalService.getFileAsStream(fileEntry.getFileEntryId(), fileEntry.getVersion(),
                    false);

            importData(actionRequest, fileEntry.getTitle(), inputStream);

            deleteTempFileEntry(groupId, folderName);
        } finally {
            StreamUtil.cleanUp(inputStream);
        }
    }
项目:ch-inofix-contact-manager    文件:ImportContactsMVCActionCommand.java   
protected void addTempFileEntry(ActionRequest actionRequest, String folderName) throws Exception {

        _log.info("addTempFileEntry()");

        UploadPortletRequest uploadPortletRequest = _portal.getUploadPortletRequest(actionRequest);

        checkExceededSizeLimit(uploadPortletRequest);

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

        deleteTempFileEntry(groupId, folderName);

        InputStream inputStream = null;

        try {
            String sourceFileName = uploadPortletRequest.getFileName("file");

            inputStream = uploadPortletRequest.getFileAsStream("file");

            String contentType = uploadPortletRequest.getContentType("file");

            _layoutService.addTempFileEntry(groupId, folderName, sourceFileName, inputStream, contentType);
        } catch (Exception e) {
            UploadException uploadException = (UploadException) actionRequest.getAttribute(WebKeys.UPLOAD_EXCEPTION);

            if (uploadException != null) {
                Throwable cause = uploadException.getCause();

                if (cause instanceof FileUploadBase.IOFileUploadException) {
                    if (_log.isInfoEnabled()) {
                        _log.info("Temporary upload was cancelled");
                    }
                }

                if (uploadException.isExceededFileSizeLimit()) {
                    throw new FileSizeException(cause);
                }

                if (uploadException.isExceededUploadRequestSizeLimit()) {
                    throw new UploadRequestSizeException(cause);
                }
            } else {
                throw e;
            }
        } finally {
            StreamUtil.cleanUp(inputStream);
        }
    }
项目:ch-inofix-contact-manager    文件:ImportContactsMVCActionCommand.java   
protected void importData(ActionRequest actionRequest, String folderName) throws Exception {

        _log.info("importData()");

        ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

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

        FileEntry fileEntry = ExportImportHelperUtil.getTempFileEntry(groupId, themeDisplay.getUserId(), folderName);

        InputStream inputStream = null;

        try {
            inputStream = _dlFileEntryLocalService.getFileAsStream(fileEntry.getFileEntryId(), fileEntry.getVersion(),
                    false);

            importData(actionRequest, fileEntry.getTitle(), inputStream);

            deleteTempFileEntry(groupId, folderName);
        } finally {
            StreamUtil.cleanUp(inputStream);
        }
    }
项目:ch-inofix-data-manager    文件:ImportMeasurementsMVCActionCommand.java   
protected void addTempFileEntry(ActionRequest actionRequest, String folderName) throws Exception {

        _log.info("addTempFileEntry()");

        UploadPortletRequest uploadPortletRequest = _portal.getUploadPortletRequest(actionRequest);

        checkExceededSizeLimit(uploadPortletRequest);

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

        deleteTempFileEntry(groupId, folderName);

        InputStream inputStream = null;

        try {
            String sourceFileName = uploadPortletRequest.getFileName("file");

            inputStream = uploadPortletRequest.getFileAsStream("file");

            String contentType = uploadPortletRequest.getContentType("file");

            _layoutService.addTempFileEntry(groupId, folderName, sourceFileName, inputStream, contentType);
        } catch (Exception e) {
            UploadException uploadException = (UploadException) actionRequest.getAttribute(WebKeys.UPLOAD_EXCEPTION);

            if (uploadException != null) {
                Throwable cause = uploadException.getCause();

                if (cause instanceof FileUploadBase.IOFileUploadException) {
                    if (_log.isInfoEnabled()) {
                        _log.info("Temporary upload was cancelled");
                    }
                }

                if (uploadException.isExceededFileSizeLimit()) {
                    throw new FileSizeException(cause);
                }

                if (uploadException.isExceededUploadRequestSizeLimit()) {
                    throw new UploadRequestSizeException(cause);
                }
            } else {
                throw e;
            }
        } finally {
            StreamUtil.cleanUp(inputStream);
        }
    }
项目:ch-inofix-data-manager    文件:ImportMeasurementsMVCActionCommand.java   
protected void importData(ActionRequest actionRequest, String folderName) throws Exception {

        _log.info("importData()");

        ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

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

        FileEntry fileEntry = ExportImportHelperUtil.getTempFileEntry(groupId, themeDisplay.getUserId(), folderName);

        InputStream inputStream = null;

        try {
            inputStream = _dlFileEntryLocalService.getFileAsStream(fileEntry.getFileEntryId(), fileEntry.getVersion(),
                    false);

            importData(actionRequest, fileEntry.getTitle(), inputStream);

            deleteTempFileEntry(groupId, folderName);
        } finally {
            StreamUtil.cleanUp(inputStream);
        }
    }