1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.kernel.bi.reporting;
16  
17  import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayOutputStream;
18  
19  import java.io.OutputStream;
20  import java.io.Serializable;
21  
22  /**
23   * <a href="ByteArrayReportResultContainer.java.html"><b><i>View Source</i></b>
24   * </a>
25   *
26   * @author Michael C. Han
27   */
28  public class ByteArrayReportResultContainer
29      implements ReportResultContainer, Serializable {
30  
31      public static final int DEFAULT_INITIAL_CAPCITY = 15360;
32  
33      public ByteArrayReportResultContainer() {
34          this(null, DEFAULT_INITIAL_CAPCITY);
35      }
36  
37      public ByteArrayReportResultContainer(String reportName) {
38          this(reportName, DEFAULT_INITIAL_CAPCITY);
39      }
40  
41      public ByteArrayReportResultContainer(
42          String reportName, int initialCapacity) {
43  
44          _reportName = reportName;
45          _initialCapacity = initialCapacity;
46      }
47  
48      public ReportResultContainer clone(String reportName) {
49          return new ByteArrayReportResultContainer(reportName, _initialCapacity);
50      }
51  
52      public OutputStream getOutputStream() {
53          if (_unsyncByteArrayOutputStream == null) {
54              _unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream(
55                  _initialCapacity);
56          }
57  
58          return _unsyncByteArrayOutputStream;
59      }
60  
61      public ReportGenerationException getReportGenerationException() {
62          return _reportGenerationException;
63      }
64  
65      public String getReportName() {
66          return _reportName;
67      }
68  
69      public byte[] getResults() {
70          return _unsyncByteArrayOutputStream.toByteArray();
71      }
72  
73      public boolean hasError() {
74          if (_reportGenerationException != null) {
75              return true;
76          }
77          else {
78              return false;
79          }
80      }
81  
82      public void setReportGenerationException(
83          ReportGenerationException reportGenerationException) {
84  
85          _reportGenerationException = reportGenerationException;
86      }
87  
88      private int _initialCapacity;
89      private ReportGenerationException _reportGenerationException;
90      private String _reportName;
91      private UnsyncByteArrayOutputStream _unsyncByteArrayOutputStream;
92  
93  }