com.kuka.roboticsAPI.controllerModel.sunrise.connectionLib
Class MessageUtilities

java.lang.Object
  extended by com.kuka.roboticsAPI.controllerModel.sunrise.connectionLib.MessageUtilities

public final class MessageUtilities
extends Object

Utility class for message sending and receiving.

This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

Field Summary
static String SEG_BEGIN
          Segment begin parameter string.
static String SEG_END
          Segment end parameter string.
 
Method Summary
static void addSegment(String segmentType, String segmentVersion, int checksum, Message message, Message messageToAddAsSegment)
          Adds a message as a segment into an existing message.
static void checkSize(long bytes, int maxLength)
          Checks if the given size is too big for sending.
static void closeSegment(Message message)
          Closes a message segment.
static Message generateErrorMessage(long id, Throwable cause)
          Generates an error message from a Java exception.
static Message getSegment(Message message, int segmentIndex, String segmentName)
          gets the specified segment within the message as a message object.
static int getSegmentCount(Message message)
          gets the amount of segments within the message.
static Message receiveMessageFromStream(InputStream inputStream, int messageLength)
          Receives a message from a stream.
static Message receiveMessageFromStream(InputStream inputStream, int messageLength, FastByteBuffer buffer)
          Receives a message from a stream.
static Message receiveMessageFromStreamChecked(InputStream inputStream, int messageLength)
          Receives a message from a stream.
static Message receiveMessageFromStreamChecked(InputStream inputStream, int messageLength, FastByteBuffer buffer)
          Receives a message from a stream.
static int receiveMessageLengthFromStream(InputStream inputStream)
          Receives the length of a message from a stream.
static int receiveMessageLengthFromStream(InputStream inputStream, FastByteBuffer lengthBuffer)
          Receives the length of a message from a stream.
static Throwable recoverException(Message errorMessage)
          Returns the causing exception from an error message, as generated by generateErrorMessage(long, Throwable).
static void sendMessageOverStream(OutputStream outputStream, Message message)
          Writes a message to a stream.
static void sendMessageOverStream(OutputStream outputStream, Message message, FastByteBuffer messageBuffer, FastByteBuffer lengthBuffer, int maxLength)
          Writes a message to a stream.
static void startSegment(ISegment segment, Message message)
          Starts a message segment.
static void startSegment(String segmentType, String segmentVersion, int checksum, Message message)
          Starts a message segment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEG_END

public static final String SEG_END
Segment end parameter string.

See Also:
Constant Field Values
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

SEG_BEGIN

public static final String SEG_BEGIN
Segment begin parameter string.

See Also:
Constant Field Values
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.
Method Detail

receiveMessageFromStream

public static Message receiveMessageFromStream(InputStream inputStream,
                                               int messageLength)
                                        throws IOException
Receives a message from a stream.

receiveMessageLengthFromStream should be called to determine the length of the message before.

Parameters:
inputStream - The input stream.
messageLength - The length of the message.
Returns:
The message. May be null, if deserialisation failed.
Throws:
IOException - If an I/O error occurred.
IllegalArgumentException - exception if message is too big
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

receiveMessageFromStreamChecked

public static Message receiveMessageFromStreamChecked(InputStream inputStream,
                                                      int messageLength)
                                               throws IOException,
                                                      MessageDeserializationException
Receives a message from a stream.

receiveMessageLengthFromStream should be called to determine the length of the message before.

Parameters:
inputStream - The input stream.
messageLength - The length of the message.
Returns:
The message.
Throws:
IOException - if an I/O error occurred
MessageDeserializationException - if an error occurred during message deserialization
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

receiveMessageFromStream

public static Message receiveMessageFromStream(InputStream inputStream,
                                               int messageLength,
                                               FastByteBuffer buffer)
                                        throws IOException
Receives a message from a stream.

receiveMessageLengthFromStream should be called to determine the length of the message before.

Parameters:
inputStream - The input stream.
messageLength - The length of the message.
buffer - The buffer which is used to receive the message.
Returns:
The message. May be null, if deserialisation failed.
Throws:
IOException - if an I/O error occurred
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

receiveMessageFromStreamChecked

public static Message receiveMessageFromStreamChecked(InputStream inputStream,
                                                      int messageLength,
                                                      FastByteBuffer buffer)
                                               throws IOException,
                                                      MessageDeserializationException
Receives a message from a stream.

receiveMessageLengthFromStream should be called to determine the length of the message before.

Parameters:
inputStream - The input stream.
messageLength - The length of the message.
buffer - The buffer which is used to receive the message.
Returns:
the message
Throws:
IOException - if an I/O error occurred
MessageDeserializationException - if an error occurred during message deserialization
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

receiveMessageLengthFromStream

public static int receiveMessageLengthFromStream(InputStream inputStream)
                                          throws IOException
Receives the length of a message from a stream.

Parameters:
inputStream - The stream.
Returns:
The length of the message.
Throws:
IOException - If an error occurs.
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

receiveMessageLengthFromStream

public static int receiveMessageLengthFromStream(InputStream inputStream,
                                                 FastByteBuffer lengthBuffer)
                                          throws IOException
Receives the length of a message from a stream.

Parameters:
inputStream - The stream.
lengthBuffer - The buffer used to receive the length.
Returns:
The length of the message.
Throws:
IOException - If an error occurs.
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

checkSize

public static void checkSize(long bytes,
                             int maxLength)
Checks if the given size is too big for sending.

Throws an exception if file is too big.

Parameters:
bytes - The byte count.
maxLength - The maximum length allowed for a message.
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

sendMessageOverStream

public static void sendMessageOverStream(OutputStream outputStream,
                                         Message message)
                                  throws IOException
Writes a message to a stream.

Parameters:
outputStream - The stream.
message - The message.
Throws:
IOException - If an error occurs.
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

sendMessageOverStream

public static void sendMessageOverStream(OutputStream outputStream,
                                         Message message,
                                         FastByteBuffer messageBuffer,
                                         FastByteBuffer lengthBuffer,
                                         int maxLength)
                                  throws IOException
Writes a message to a stream.

Parameters:
outputStream - The stream.
message - The message.
messageBuffer - The buffer for writing the message.
lengthBuffer - The buffer for writing the length of the message.
maxLength - The maximum length allowed for a message.
Throws:
IOException - If an error occurs.
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

closeSegment

public static void closeSegment(Message message)
Closes a message segment.

Parameters:
message - The message.
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

startSegment

public static void startSegment(ISegment segment,
                                Message message)
Starts a message segment.

Parameters:
segment - The segment holding the segment data.
message - The message.
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

startSegment

public static void startSegment(String segmentType,
                                String segmentVersion,
                                int checksum,
                                Message message)
Starts a message segment.

Parameters:
segmentType - The type of the segment.
segmentVersion - The version of the segment.
checksum - The checksum for the segment.
message - The message.
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

addSegment

public static void addSegment(String segmentType,
                              String segmentVersion,
                              int checksum,
                              Message message,
                              Message messageToAddAsSegment)
Adds a message as a segment into an existing message.

Parameters:
segmentType - The type of the segment.
segmentVersion - The version of the segment.
checksum - The checksum for the segment.
message - the message that will contain the added segment afterwards.
messageToAddAsSegment - the message that should be added as a segment.
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

getSegmentCount

public static int getSegmentCount(Message message)
gets the amount of segments within the message.

Parameters:
message - the message that contains the segments.
Returns:
the amount of segments within the message.
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

getSegment

public static Message getSegment(Message message,
                                 int segmentIndex,
                                 String segmentName)
gets the specified segment within the message as a message object.

Parameters:
message - the message containing the segment.
segmentIndex - the index of the segment in the message that should be returned.
segmentName - name of the segment
Returns:
the segment as a message or null if the message contains no segment with that name or that index.
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

generateErrorMessage

public static Message generateErrorMessage(long id,
                                           Throwable cause)
Generates an error message from a Java exception. The message will have a type of MessageType.Error and the given ID. The message parameters will be as follows:
  1. the exception message (see Throwable.getMessage(), or an empty string if the message is null
  2. (optional parameter) the serialized exception, as generated by ObjectOutputStream

Parameters:
id - The id for the error message. If the error occurred in reaction to a request message, this id should usually be the id of the original request message.
cause - the causing exception
Returns:
a new error message
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

recoverException

public static Throwable recoverException(Message errorMessage)
Returns the causing exception from an error message, as generated by generateErrorMessage(long, Throwable).

Parameters:
errorMessage - the error message
Returns:
The causing exception. May be null if not present or if deserialization failed.
Throws:
IllegalArgumentException - if the type of the given message is not MessageType.Error.
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.


Copyright © 2019. All rights reserved.