Search in sources :

Example 1 with UnsyncByteArrayInputStream

use of com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream in project liferay-ide by liferay.

the class KBArticleStagedModelDataHandler method importKBArticleAttachments.

protected void importKBArticleAttachments(PortletDataContext portletDataContext, KBArticle kbArticle, KBArticle importedKBArticle) throws Exception {
    List<Element> dlFileEntryElements = portletDataContext.getReferenceDataElements(kbArticle, DLFileEntry.class);
    ServiceContext serviceContext = new ServiceContext();
    serviceContext.setCompanyId(portletDataContext.getCompanyId());
    serviceContext.setScopeGroupId(portletDataContext.getScopeGroupId());
    InputStream inputStream = null;
    for (Element dlFileEntryElement : dlFileEntryElements) {
        try {
            byte[] bytes = portletDataContext.getZipEntryAsByteArray(dlFileEntryElement.attributeValue("path"));
            inputStream = new UnsyncByteArrayInputStream(bytes);
            String fileName = dlFileEntryElement.attributeValue("file-name");
            String mimeType = KnowledgeBaseUtil.getMimeType(bytes, fileName);
            PortletFileRepositoryUtil.addPortletFileEntry(portletDataContext.getScopeGroupId(), portletDataContext.getUserId(importedKBArticle.getUserUuid()), KBArticle.class.getName(), importedKBArticle.getClassPK(), PortletKeys.KNOWLEDGE_BASE_ADMIN, importedKBArticle.getAttachmentsFolderId(), inputStream, fileName, mimeType, true);
        } catch (DuplicateFileException dfe) {
            continue;
        } finally {
            StreamUtil.cleanUp(inputStream);
        }
    }
}
Also used : KBArticle(com.liferay.knowledgebase.model.KBArticle) DuplicateFileException(com.liferay.portlet.documentlibrary.DuplicateFileException) ServiceContext(com.liferay.portal.service.ServiceContext) UnsyncByteArrayInputStream(com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream) InputStream(java.io.InputStream) Element(com.liferay.portal.kernel.xml.Element) UnsyncByteArrayInputStream(com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream)

Example 2 with UnsyncByteArrayInputStream

use of com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream in project liferay-ide by liferay.

the class ClpSerializer method translateThrowable.

public static Throwable translateThrowable(Throwable throwable) {
    if (_useReflectionToTranslateThrowable) {
        try {
            UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream();
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(unsyncByteArrayOutputStream);
            objectOutputStream.writeObject(throwable);
            objectOutputStream.flush();
            objectOutputStream.close();
            UnsyncByteArrayInputStream unsyncByteArrayInputStream = new UnsyncByteArrayInputStream(unsyncByteArrayOutputStream.unsafeGetByteArray(), 0, unsyncByteArrayOutputStream.size());
            Thread currentThread = Thread.currentThread();
            ClassLoader contextClassLoader = currentThread.getContextClassLoader();
            ObjectInputStream objectInputStream = new ClassLoaderObjectInputStream(unsyncByteArrayInputStream, contextClassLoader);
            throwable = (Throwable) objectInputStream.readObject();
            objectInputStream.close();
            return throwable;
        } catch (SecurityException se) {
            if (_log.isInfoEnabled()) {
                _log.info("Do not use reflection to translate throwable");
            }
            _useReflectionToTranslateThrowable = false;
        } catch (Throwable throwable2) {
            _log.error(throwable2, throwable2);
            return throwable2;
        }
    }
    Class<?> clazz = throwable.getClass();
    String className = clazz.getName();
    if (className.equals(PortalException.class.getName())) {
        return new PortalException();
    }
    if (className.equals(SystemException.class.getName())) {
        return new SystemException();
    }
    if (className.equals("com.liferay.knowledgebase.DuplicateKBArticleUrlTitleException")) {
        return new com.liferay.knowledgebase.DuplicateKBArticleUrlTitleException();
    }
    if (className.equals("com.liferay.knowledgebase.DuplicateKBFolderNameException")) {
        return new com.liferay.knowledgebase.DuplicateKBFolderNameException();
    }
    if (className.equals("com.liferay.knowledgebase.InvalidKBArticleUrlTitleException")) {
        return new com.liferay.knowledgebase.InvalidKBArticleUrlTitleException();
    }
    if (className.equals("com.liferay.knowledgebase.InvalidKBFolderNameException")) {
        return new com.liferay.knowledgebase.InvalidKBFolderNameException();
    }
    if (className.equals("com.liferay.knowledgebase.KBArticleContentException")) {
        return new com.liferay.knowledgebase.KBArticleContentException();
    }
    if (className.equals("com.liferay.knowledgebase.KBArticleImportException")) {
        return new com.liferay.knowledgebase.KBArticleImportException();
    }
    if (className.equals("com.liferay.knowledgebase.KBArticleParentException")) {
        return new com.liferay.knowledgebase.KBArticleParentException();
    }
    if (className.equals("com.liferay.knowledgebase.KBArticlePriorityException")) {
        return new com.liferay.knowledgebase.KBArticlePriorityException();
    }
    if (className.equals("com.liferay.knowledgebase.KBArticleSourceURLException")) {
        return new com.liferay.knowledgebase.KBArticleSourceURLException();
    }
    if (className.equals("com.liferay.knowledgebase.KBArticleTitleException")) {
        return new com.liferay.knowledgebase.KBArticleTitleException();
    }
    if (className.equals("com.liferay.knowledgebase.KBCommentContentException")) {
        return new com.liferay.knowledgebase.KBCommentContentException();
    }
    if (className.equals("com.liferay.knowledgebase.KBTemplateContentException")) {
        return new com.liferay.knowledgebase.KBTemplateContentException();
    }
    if (className.equals("com.liferay.knowledgebase.KBTemplateTitleException")) {
        return new com.liferay.knowledgebase.KBTemplateTitleException();
    }
    if (className.equals("com.liferay.knowledgebase.NoSuchKBArticleSelectorException")) {
        return new com.liferay.knowledgebase.NoSuchKBArticleSelectorException();
    }
    if (className.equals("com.liferay.knowledgebase.NoSuchArticleException")) {
        return new com.liferay.knowledgebase.NoSuchArticleException();
    }
    if (className.equals("com.liferay.knowledgebase.NoSuchCommentException")) {
        return new com.liferay.knowledgebase.NoSuchCommentException();
    }
    if (className.equals("com.liferay.knowledgebase.NoSuchFolderException")) {
        return new com.liferay.knowledgebase.NoSuchFolderException();
    }
    if (className.equals("com.liferay.knowledgebase.NoSuchTemplateException")) {
        return new com.liferay.knowledgebase.NoSuchTemplateException();
    }
    return throwable;
}
Also used : UnsyncByteArrayOutputStream(com.liferay.portal.kernel.io.unsync.UnsyncByteArrayOutputStream) ClassLoaderObjectInputStream(com.liferay.portal.kernel.util.ClassLoaderObjectInputStream) ObjectOutputStream(java.io.ObjectOutputStream) SystemException(com.liferay.portal.kernel.exception.SystemException) PortalException(com.liferay.portal.kernel.exception.PortalException) UnsyncByteArrayInputStream(com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream) ClassLoaderObjectInputStream(com.liferay.portal.kernel.util.ClassLoaderObjectInputStream)

Example 3 with UnsyncByteArrayInputStream

use of com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream in project liferay-ide by liferay.

the class AlbumStagedModelDataHandler method _getContentStream.

private InputStream _getContentStream(FileEntry fileEntry) throws PortalException, SystemException {
    long repositoryId = DLFolderConstants.getDataRepositoryId(fileEntry.getRepositoryId(), fileEntry.getFolderId());
    String name = ((DLFileEntry) fileEntry.getModel()).getName();
    InputStream is = DLStoreUtil.getFileAsStream(fileEntry.getCompanyId(), repositoryId, name, fileEntry.getVersion());
    if (is == null) {
        is = new UnsyncByteArrayInputStream(new byte[0]);
    }
    return is;
}
Also used : UnsyncByteArrayInputStream(com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream) InputStream(java.io.InputStream) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry) UnsyncByteArrayInputStream(com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream)

Example 4 with UnsyncByteArrayInputStream

use of com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream in project liferay-ide by liferay.

the class ArtistStagedModelDataHandler method _getContentStream.

private InputStream _getContentStream(FileEntry fileEntry) throws PortalException, SystemException {
    long repositoryId = DLFolderConstants.getDataRepositoryId(fileEntry.getRepositoryId(), fileEntry.getFolderId());
    String name = ((DLFileEntry) fileEntry.getModel()).getName();
    InputStream is = DLStoreUtil.getFileAsStream(fileEntry.getCompanyId(), repositoryId, name, fileEntry.getVersion());
    if (is == null) {
        is = new UnsyncByteArrayInputStream(new byte[0]);
    }
    return is;
}
Also used : UnsyncByteArrayInputStream(com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream) InputStream(java.io.InputStream) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry) UnsyncByteArrayInputStream(com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream)

Example 5 with UnsyncByteArrayInputStream

use of com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream in project liferay-ide by liferay.

the class ClpSerializer method translateThrowable.

public static Throwable translateThrowable(Throwable throwable) {
    if (_useReflectionToTranslateThrowable) {
        try {
            UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream();
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(unsyncByteArrayOutputStream);
            objectOutputStream.writeObject(throwable);
            objectOutputStream.flush();
            objectOutputStream.close();
            UnsyncByteArrayInputStream unsyncByteArrayInputStream = new UnsyncByteArrayInputStream(unsyncByteArrayOutputStream.unsafeGetByteArray(), 0, unsyncByteArrayOutputStream.size());
            Thread currentThread = Thread.currentThread();
            ClassLoader contextClassLoader = currentThread.getContextClassLoader();
            ObjectInputStream objectInputStream = new ClassLoaderObjectInputStream(unsyncByteArrayInputStream, contextClassLoader);
            throwable = (Throwable) objectInputStream.readObject();
            objectInputStream.close();
            return throwable;
        } catch (SecurityException se) {
            if (_log.isInfoEnabled()) {
                _log.info("Do not use reflection to translate throwable");
            }
            _useReflectionToTranslateThrowable = false;
        } catch (Throwable throwable2) {
            _log.error(throwable2, throwable2);
            return throwable2;
        }
    }
    Class<?> clazz = throwable.getClass();
    String className = clazz.getName();
    if (className.equals(PortalException.class.getName())) {
        return new PortalException();
    }
    if (className.equals(SystemException.class.getName())) {
        return new SystemException();
    }
    if (className.equals("org.liferay.jukebox.AlbumNameException")) {
        return new org.liferay.jukebox.AlbumNameException();
    }
    if (className.equals("org.liferay.jukebox.ArtistNameException")) {
        return new org.liferay.jukebox.ArtistNameException();
    }
    if (className.equals("org.liferay.jukebox.DuplicatedAlbumException")) {
        return new org.liferay.jukebox.DuplicatedAlbumException();
    }
    if (className.equals("org.liferay.jukebox.DuplicatedArtistException")) {
        return new org.liferay.jukebox.DuplicatedArtistException();
    }
    if (className.equals("org.liferay.jukebox.DuplicatedSongException")) {
        return new org.liferay.jukebox.DuplicatedSongException();
    }
    if (className.equals("org.liferay.jukebox.NoSuchAlbumException")) {
        return new org.liferay.jukebox.NoSuchAlbumException();
    }
    if (className.equals("org.liferay.jukebox.NoSuchArtistException")) {
        return new org.liferay.jukebox.NoSuchArtistException();
    }
    if (className.equals("org.liferay.jukebox.NoSuchSongException")) {
        return new org.liferay.jukebox.NoSuchSongException();
    }
    if (className.equals("org.liferay.jukebox.SongNameException")) {
        return new org.liferay.jukebox.SongNameException();
    }
    if (className.equals("org.liferay.jukebox.NoSuchAlbumException")) {
        return new org.liferay.jukebox.NoSuchAlbumException();
    }
    if (className.equals("org.liferay.jukebox.NoSuchArtistException")) {
        return new org.liferay.jukebox.NoSuchArtistException();
    }
    if (className.equals("org.liferay.jukebox.NoSuchSongException")) {
        return new org.liferay.jukebox.NoSuchSongException();
    }
    return throwable;
}
Also used : UnsyncByteArrayOutputStream(com.liferay.portal.kernel.io.unsync.UnsyncByteArrayOutputStream) ClassLoaderObjectInputStream(com.liferay.portal.kernel.util.ClassLoaderObjectInputStream) ObjectOutputStream(java.io.ObjectOutputStream) SystemException(com.liferay.portal.kernel.exception.SystemException) UnsyncByteArrayInputStream(com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream) PortalException(com.liferay.portal.kernel.exception.PortalException) ObjectInputStream(java.io.ObjectInputStream) ClassLoaderObjectInputStream(com.liferay.portal.kernel.util.ClassLoaderObjectInputStream)

Aggregations

UnsyncByteArrayInputStream (com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream)6 UnsyncByteArrayOutputStream (com.liferay.portal.kernel.io.unsync.UnsyncByteArrayOutputStream)3 ClassLoaderObjectInputStream (com.liferay.portal.kernel.util.ClassLoaderObjectInputStream)3 InputStream (java.io.InputStream)3 ObjectInputStream (java.io.ObjectInputStream)3 ObjectOutputStream (java.io.ObjectOutputStream)3 PortalException (com.liferay.portal.kernel.exception.PortalException)2 SystemException (com.liferay.portal.kernel.exception.SystemException)2 DLFileEntry (com.liferay.portlet.documentlibrary.model.DLFileEntry)2 KBArticle (com.liferay.knowledgebase.model.KBArticle)1 Element (com.liferay.portal.kernel.xml.Element)1 ServiceContext (com.liferay.portal.service.ServiceContext)1 DuplicateFileException (com.liferay.portlet.documentlibrary.DuplicateFileException)1