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