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 com.att.nsa.cambria.resources.streamReaders;
24 import java.io.BufferedReader;
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.io.InputStreamReader;
28 import java.util.logging.Logger;
30 import javax.servlet.http.HttpServletResponse;
32 import com.att.nsa.cambria.CambriaApiException;
33 import com.att.nsa.cambria.backends.Publisher.message;
34 import com.att.nsa.cambria.beans.LogDetails;
35 import com.att.nsa.cambria.resources.CambriaEventSet.reader;
37 import jline.internal.Log;
40 * This stream reader just pulls single lines. It uses the default partition if provided. If
41 * not, the key is the current time, which does not guarantee ordering.
46 public class CambriaTextStreamReader implements reader
48 private Logger log = Logger.getLogger(CambriaTextStreamReader.class.toString());
50 * This is the constructor for Cambria Text Reader format
53 * @throws CambriaApiException
55 public CambriaTextStreamReader ( InputStream is, String defPart ) throws CambriaApiException
57 fReader = new BufferedReader ( new InputStreamReader ( is ) );
63 * next() method iterates through msg length
65 * throws CambriaApiException
68 public message next () throws CambriaApiException
72 final String line = fReader.readLine ();
73 if ( line == null ) return null;
77 private LogDetails logDetails;
78 private boolean transactionEnabled;
81 * returns boolean value which
82 * indicates whether transaction is enabled
85 public boolean isTransactionEnabled() {
86 return transactionEnabled;
90 * sets boolean value which
91 * indicates whether transaction is enabled
93 public void setTransactionEnabled(boolean transactionEnabled) {
94 this.transactionEnabled = transactionEnabled;
100 * It ch4ecks whether fDefPart value is Null.
101 * If yes, it will return ystem.currentTimeMillis () else
102 * it will return fDefPart variable value
104 public String getKey ()
106 return fDefPart == null ? "" + System.currentTimeMillis () : fDefPart;
111 * returns the message in String type object
114 public String getMessage ()
121 * set log details in logDetails variable
123 public void setLogDetails(LogDetails logDetails) {
124 this.logDetails = logDetails;
129 * get the log details
131 public LogDetails getLogDetails() {
132 return this.logDetails;
136 catch ( IOException e )
139 throw new CambriaApiException ( HttpServletResponse.SC_BAD_REQUEST, e.getMessage () );
143 private final BufferedReader fReader;
144 private final String fDefPart;