1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 *******************************************************************************/
22 package org.onap.dmaap.messagerouter.msgrtr.nsa.cambria.resources.streamReaders;
24 import java.io.IOException;
25 import java.io.InputStream;
27 import javax.servlet.http.HttpServletResponse;
29 import org.onap.dmaap.messagerouter.msgrtr.nsa.cambria.CambriaApiException;
30 import org.onap.dmaap.messagerouter.msgrtr.nsa.cambria.backends.Publisher.message;
31 import org.onap.dmaap.messagerouter.msgrtr.nsa.cambria.beans.LogDetails;
32 import org.onap.dmaap.messagerouter.msgrtr.nsa.cambria.resources.CambriaEventSet.reader;
34 import com.att.nsa.util.StreamTools;
38 * This stream reader reads raw bytes creating a single message.
42 public class CambriaRawStreamReader implements reader
45 * This is the constructor of CambriaRawStreamReader, it will basically the read from Input stream
48 * @throws CambriaApiException
50 public CambriaRawStreamReader ( InputStream is, String defPart ) throws CambriaApiException
60 * next() method reads the bytes and
61 * iterates through the messages
62 * @throws CambriaApiException
65 public message next () throws CambriaApiException
67 if ( fClosed ) return null;
71 final byte[] rawBytes = StreamTools.readBytes ( fStream );
75 private LogDetails logDetails;
76 private boolean transactionEnabled;
79 * returns boolean value which
80 * indicates whether transaction is enabled
82 public boolean isTransactionEnabled() {
83 return transactionEnabled;
87 * sets boolean value which
88 * indicates whether transaction is enabled
90 public void setTransactionEnabled(boolean transactionEnabled) {
91 this.transactionEnabled = transactionEnabled;
97 * It ch4ecks whether fDefPart value is Null.
98 * If yes, it will return ystem.currentTimeMillis () else
99 * it will return fDefPart variable value
101 public String getKey ()
103 return fDefPart == null ? "" + System.currentTimeMillis () : fDefPart;
108 * returns the message in String type object
110 public String getMessage ()
112 return new String ( rawBytes );
116 * set log details in logDetails variable
119 public void setLogDetails(LogDetails logDetails) {
120 this.logDetails = logDetails;
125 * get the log details
127 public LogDetails getLogDetails() {
128 return this.logDetails;
132 catch ( IOException e )
134 throw new CambriaApiException ( HttpServletResponse.SC_BAD_REQUEST, e.getMessage () );
138 private final InputStream fStream;
139 private final String fDefPart;
140 private boolean fClosed;
141 //private String transactionId;