2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.adapter.netconf.internal;
27 import java.io.ByteArrayOutputStream;
29 class NetconfMessage {
31 private static final String EOM = "]]>]]>";
34 private MessageBuffer buffer = new MessageBuffer();
40 NetconfMessage(String text) {
42 throw new NullPointerException("Netconf message payload is null");
44 append(text.getBytes(), 0, text.length());
45 if(this.text == null) {
50 void append(byte[] bytes, int start, int end) {
51 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() {
79 return (text != null);
83 StringBuilder sb = new StringBuilder();
85 sb.append(text).append("\n");
88 return sb.toString().getBytes();
91 private class MessageBuffer extends ByteArrayOutputStream {