org.jmythapi.protocol.utils
Class PacketUtils

java.lang.Object
  extended by org.jmythapi.protocol.utils.PacketUtils

public class PacketUtils
extends Object

This class provides MythTV-packet related utility function.

Usage example:


    // write a packet to the output stream
    IMythPacket resp = sendableObj.getPacket();
    PacketUtils.writeTo(req, this.socketOutputStream);
 
    // read the response packet from the input stream
    IMythPacket resp = PacketUtils.readFrom(protoVersion, this.socketInputStream);
 
To write a request-packet to the stream function writeTo is used. To read the response-packet from the stream function readFrom is used.

See Also:
IMythPacket

Field Summary
static String DELIM_REGEXP
          A regular expression used to split packet arguments when receiving them over network.
static int SIZE_STRING_LENGTH
          The length of the size string of a packet.
 
Method Summary
static String formatPayloadSizeString(int size)
          Generates the payload-size string.
static IMythPacket readFrom(ProtocolVersion protoVersion, InputStream input)
          Reads a MythTV-packet from an input-stream.
static IMythPacket readFrom(ProtocolVersion protoVersion, String inputString)
          Reads a MythTV-packet from a string.
static int readPayloadSize(InputStream input)
           
static ArrayList<String> split(String data)
          Converts an MythTV data-line into a list of arguments.
static void writeTo(IMythPacket packet, OutputStream output)
          Writes a MythTV-packet to an output-stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIZE_STRING_LENGTH

public static final int SIZE_STRING_LENGTH
The length of the size string of a packet.

See Also:
Constant Field Values

DELIM_REGEXP

public static final String DELIM_REGEXP
A regular expression used to split packet arguments when receiving them over network.

See Also:
Constant Field Values
Method Detail

split

public static ArrayList<String> split(String data)
Converts an MythTV data-line into a list of arguments.

E.g. "1002[]:[]224[]:[]853[]:[]853" will be converted to [1002,224,853,853].

Parameters:
data - the data-string that should be parsed.
Returns:
the data-items as list

readFrom

public static final IMythPacket readFrom(ProtocolVersion protoVersion,
                                         String inputString)
                                  throws IOException
Reads a MythTV-packet from a string.

Parameters:
protoVersion - the protocol version of the packet
inputString - the string representing the packet, e.g. "13     2[]:[]4[]:[]6".
Returns:
the read packet
Throws:
IOException - on communication errors

readFrom

public static final IMythPacket readFrom(ProtocolVersion protoVersion,
                                         InputStream input)
                                  throws IOException
Reads a MythTV-packet from an input-stream.

Parameters:
protoVersion - the protocol version of the packet
input - the input stream containing the packet data
Returns:
the read packet
Throws:
IOException - on communication errors

readPayloadSize

public static final int readPayloadSize(InputStream input)
                                 throws IOException
Throws:
IOException

writeTo

public static final void writeTo(IMythPacket packet,
                                 OutputStream output)
                          throws IOException
Writes a MythTV-packet to an output-stream.

Parameters:
packet - the packet that should be written to the stream.
output - the output-stream to write the date to.
Throws:
IOException - on communication errors

formatPayloadSizeString

public static final String formatPayloadSizeString(int size)
Generates the payload-size string.

Parameters:
size - the size of the payload
Returns:
the size string, e.g. "13     "


Copyright © 2008-2013. All Rights Reserved.