it.jnrpe.net
Class JNRPEResponse

java.lang.Object
  extended by it.jnrpe.net.JNRPEResponse

public final class JNRPEResponse
extends Object

This object represent a generic response packet.

Author:
Massimiliano Ziccardi

Constructor Summary
JNRPEResponse()
          Default constructor.
JNRPEResponse(InputStream in)
          Builds a JNRPE response reading the content from an InputStream.
 
Method Summary
protected  void _setMessage(String message)
          Sets the packet message.
protected  void fromInputStream(InputStream in)
          Initialize the object reading the data from the input stream.
 int getCRC()
          Returns the packet CRC value.
 PacketType getPacketType()
          Returns the packet type.
 PacketVersion getPacketVersion()
          Returns the packet version.
 int getResultCode()
          Returns the result code.
 String getStringMessage()
          Returns the string message.
protected  void initRandomBuffer()
          Initializes the arrays with random data.
 void setCRC(int crc)
          Sets the CRC value.
protected  void setDataBuffer(String commandName)
          Write the command name inside the JNRPE packet.
 void setMessage(String message)
          Sets the message to be included in the response.
protected  void setPacketType(PacketType packetType)
          Sets the packet type.
 void setPacketVersion(PacketVersion version)
          Sets the packet version.
 void setResultCode(int status)
          Sets the result code.
 byte[] toByteArray()
          Converts the packet object to its byte array representation.
 void updateCRC()
          Updates the CRC value.
 void validate()
          Validates the packet CRC.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JNRPEResponse

public JNRPEResponse()
Default constructor.


JNRPEResponse

public JNRPEResponse(InputStream in)
              throws IOException
Builds a JNRPE response reading the content from an InputStream.

Parameters:
in - The InputStream to read from
Throws:
IOException - on any io exception
Method Detail

updateCRC

public void updateCRC()
Updates the CRC value.


setMessage

public void setMessage(String message)
Sets the message to be included in the response.

Parameters:
message - the response message

getCRC

public int getCRC()
Returns the packet CRC value.

Returns:
the CRC value

getPacketType

public PacketType getPacketType()
Returns the packet type.

Returns:
The packet type

getPacketVersion

public PacketVersion getPacketVersion()
Returns the packet version.

Returns:
The packet version

setCRC

public void setCRC(int crc)
Sets the CRC value.

Parameters:
crc - The new CRC value

setPacketType

protected void setPacketType(PacketType packetType)
Sets the packet type.

Parameters:
packetType - The new packet type

setPacketVersion

public void setPacketVersion(PacketVersion version)
Sets the packet version.

Parameters:
version - The packet version

getResultCode

public int getResultCode()
Returns the result code.

Returns:
The result code

setResultCode

public void setResultCode(int status)
Sets the result code.

Parameters:
status - The new result code

fromInputStream

protected void fromInputStream(InputStream in)
                        throws IOException
Initialize the object reading the data from the input stream.

Parameters:
in - The stream to be read
Throws:
IOException - On any I/O error

validate

public void validate()
              throws BadCRCException
Validates the packet CRC.

Throws:
BadCRCException - If the CRC can't be validated

toByteArray

public byte[] toByteArray()
Converts the packet object to its byte array representation.

Returns:
The byte array representation of this packet.

getStringMessage

public String getStringMessage()
Returns the string message.

Returns:
The string message

_setMessage

protected void _setMessage(String message)
Sets the packet message. If the message is longer than. JNRPEProtocolPacket.MAX_PACKETBUFFER_LENGTH than it gets truncated to JNRPEProtocolPacket.MAX_PACKETBUFFER_LENGTH bytes.

Parameters:
message - The message

initRandomBuffer

protected void initRandomBuffer()
Initializes the arrays with random data. Not sure it is really needed...


setDataBuffer

protected void setDataBuffer(String commandName)
Write the command name inside the JNRPE packet.

Parameters:
commandName - The command name


Copyright © 2014. All Rights Reserved.