001
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
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 @Override
046 public ReportResultContainer clone(String reportName) {
047 return new ByteArrayReportResultContainer(reportName, _initialCapacity);
048 }
049
050 @Override
051 public OutputStream getOutputStream() {
052 if (_unsyncByteArrayOutputStream == null) {
053 _unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream(
054 _initialCapacity);
055 }
056
057 return _unsyncByteArrayOutputStream;
058 }
059
060 @Override
061 public ReportGenerationException getReportGenerationException() {
062 return _reportGenerationException;
063 }
064
065 @Override
066 public String getReportName() {
067 return _reportName;
068 }
069
070 @Override
071 public byte[] getResults() {
072 return _unsyncByteArrayOutputStream.toByteArray();
073 }
074
075 @Override
076 public boolean hasError() {
077 if (_reportGenerationException != null) {
078 return true;
079 }
080 else {
081 return false;
082 }
083 }
084
085 @Override
086 public void setReportGenerationException(
087 ReportGenerationException reportGenerationException) {
088
089 _reportGenerationException = reportGenerationException;
090 }
091
092 private int _initialCapacity;
093 private ReportGenerationException _reportGenerationException;
094 private String _reportName;
095 private UnsyncByteArrayOutputStream _unsyncByteArrayOutputStream;
096
097 }