001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.bi.reporting;
016    
017    import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayOutputStream;
018    
019    import java.io.OutputStream;
020    import java.io.Serializable;
021    
022    /**
023     * @author Michael C. Han
024     */
025    public class ByteArrayReportResultContainer
026            implements ReportResultContainer, Serializable {
027    
028            public static final int DEFAULT_INITIAL_CAPCITY = 15360;
029    
030            public ByteArrayReportResultContainer() {
031                    this(null, DEFAULT_INITIAL_CAPCITY);
032            }
033    
034            public ByteArrayReportResultContainer(String reportName) {
035                    this(reportName, DEFAULT_INITIAL_CAPCITY);
036            }
037    
038            public ByteArrayReportResultContainer(
039                    String reportName, int initialCapacity) {
040    
041                    _reportName = reportName;
042                    _initialCapacity = initialCapacity;
043            }
044    
045            public ReportResultContainer clone(String reportName) {
046                    return new ByteArrayReportResultContainer(reportName, _initialCapacity);
047            }
048    
049            public OutputStream getOutputStream() {
050                    if (_unsyncByteArrayOutputStream == null) {
051                            _unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream(
052                                    _initialCapacity);
053                    }
054    
055                    return _unsyncByteArrayOutputStream;
056            }
057    
058            public ReportGenerationException getReportGenerationException() {
059                    return _reportGenerationException;
060            }
061    
062            public String getReportName() {
063                    return _reportName;
064            }
065    
066            public byte[] getResults() {
067                    return _unsyncByteArrayOutputStream.toByteArray();
068            }
069    
070            public boolean hasError() {
071                    if (_reportGenerationException != null) {
072                            return true;
073                    }
074                    else {
075                            return false;
076                    }
077            }
078    
079            public void setReportGenerationException(
080                    ReportGenerationException reportGenerationException) {
081    
082                    _reportGenerationException = reportGenerationException;
083            }
084    
085            private int _initialCapacity;
086            private ReportGenerationException _reportGenerationException;
087            private String _reportName;
088            private UnsyncByteArrayOutputStream _unsyncByteArrayOutputStream;
089    
090    }