1 /******************************************************************************* 2 * Copyright (c) 2007, 2014 Massimiliano Ziccardi 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 *******************************************************************************/ 16 package it.jnrpe.net; 17 18 import java.io.IOException; 19 import java.io.InputStream; 20 import java.util.Arrays; 21 22 /** 23 * This object represent a generic response packet. 24 * 25 * @author Massimiliano Ziccardi 26 */ 27 public final class JNRPEResponse extends JNRPEProtocolPacket { 28 /** 29 * Default constructor. 30 */ 31 public JNRPEResponse() { 32 super(); 33 setPacketType(PacketType.RESPONSE); 34 } 35 36 /** 37 * Builds a JNRPE response reading the content from an InputStream. 38 * 39 * @param in 40 * The InputStream to read from 41 * 42 * @throws IOException 43 * on any io exception 44 */ 45 public JNRPEResponse(final InputStream in) throws IOException { 46 super(); 47 fromInputStream(in); 48 } 49 50 /** 51 * Sets the message to be included in the response. 52 * 53 * @param message 54 * the response message 55 */ 56 public void setMessage(final String message) { 57 setBuffer(message); 58 } 59 60 /** 61 * Returns the response message. 62 * 63 * @return the response message 64 */ 65 public String getMessage() { 66 return getPacketString(); 67 } 68 69 @Override 70 public String toString() { 71 72 return "JNRPEResponse [getPacketType()=" + getPacketType() 73 + ", getPacketVersion()=" + getPacketVersion() 74 + ", getResultCode()=" + getResultCode() + ", getBuffer()=" 75 + Arrays.toString(getBuffer()) + "]"; 76 } 77 78 }