it.jnrpe.net
Class JNRPERequest

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

public class JNRPERequest
extends Object

This object represent a generic request packet.

Author:
Massimiliano Ziccardi

Constructor Summary
JNRPERequest(InputStream in)
          This constructor initializes the object with the data read from the given input stream.
JNRPERequest(String commandName, String... arguments)
          Inizialize the request with the supplied command and command arguments.
 
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.
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 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

JNRPERequest

public JNRPERequest(InputStream in)
             throws IOException,
                    BadCRCException
This constructor initializes the object with the data read from the given input stream.

Parameters:
in - The stream containing the data to be parsed
Throws:
IOException - On any IO exception
BadCRCException - If the CRC can't be validated

JNRPERequest

public JNRPERequest(String commandName,
                    String... arguments)
Inizialize the request with the supplied command and command arguments.

Parameters:
commandName - The command
arguments - The arguments
Method Detail

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.