2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.adapter.netconf.internal;
26 import java.io.ByteArrayOutputStream;
28 class NetconfMessage {
30 private static final String EOM = "]]>]]>";
33 private MessageBuffer buffer = new MessageBuffer();
39 NetconfMessage(String text) {
41 throw new NullPointerException("Netconf message payload is null");
43 append(text.getBytes(), 0, text.length());
44 if(this.text == null) {
49 void append(byte[] bytes, int start, int finish) {
50 boolean eomFound = false;
52 for(int i = start; i < end; i++) {
53 if(bytes[i] == EOM.charAt(eomNotch)) {
60 if(eomNotch == EOM.length()) {
61 // end of message found
67 buffer.write(bytes, start, end);
69 text = new String(buffer.getBytes(), 0, buffer.size() - EOM.length());
78 boolean isCompleted() {
83 StringBuilder sb = new StringBuilder();
85 sb.append(text).append("\n");
88 return sb.toString().getBytes();
91 private class MessageBuffer extends ByteArrayOutputStream {