CS3353 Program Project: Implement a Simple Protocol

CS3353 Program Project: Implement a Simple Protocol

CS3353 Program Project: Implement a Simple Protocol

Read the CS1043 Program Guidelines document (

Your program must include:

appropriate programming style including exception handling

appropriate documentation

appropriate design

The course instructor will schedule a collaboration date. This will be the only collaboration allowed between students for this project. A grade will be assigned for this activity.

Design a class that will handle a byte stream from an input to an output. Here are the design specifications:

  1. All error messages must be written to standard error.
  2. The input and output streams are be limited to 2043 bytes per reference.
  3. There must be at least one private instance field: a byte buffer no more than 2047 bytes in length.
  4. Constructor: IOPacket( String infile, String outfile ).
  5. int = readIOData( ) reads the input stream and places the data in the byte buffer. The method will add a header and a trailer to the buffer content. The method returns the actual number of bytes read. The header consists of a 16 bit field: the highest order bit is a parity bit, and the remaining bits hold the actual number of bytes read from the input stream. The trailer will be assigned a 16 bit value representing the input data stream’s 16-bit checksum.
  6. int = readIOPacket( ) reads an input stream and verifies the parity bit in the header, and verifies the checksum. The header, trailer, and data are copied into the byte buffer. Return the actual number of bytes read.
  7. writeIOData( ) writes the data portion of the byte buffer to the output stream.
  8. writeIOPacket( ) writes the header, trailer, and data information contained in the byte buffer to the output stream.
  9. byte [] = getBuffer ( ) returns the reference to the byte buffer.
  10. int = getDataSize( ), returns the size in bytes of the data portion stored in the byte buffer.
  11. setDataSize( int ), sets the first two bytes of the byte buffer to hold the actual number of bytes read from the input stream and stored in the byte buffer. Set the parity bit so the total number of bits in the data length field is even. The parity bit is the left most bit in the first byte of the buffer.
  12. boolean = parityCheck( ), returns true if the sum of the bits in the first two bytes is even.
  13. int = calcChecksum( ), returns the 16-bit checksum from the data portion of the byte buffer.
  14. setChecksum( int ), sets the last two bytes of the byte buffer to hold the 16=-bit checksum.
  15. int = getChecksum( ), returns the checksum stored in the last two bytes of the byte buffer.
  16. Include a closeIOPacket() method to close/flush the open files.

Bit operations are required for this assignment: both bit shifting and bit masking.

Note that while the maximum number of bytes that can be read is defined by the size of your byte buffer, the last record in your byte stream is likely to be smaller than the maximum.

Data flow is as follows:

Input stream -> readIOData -> writeIOPacket -> readIOPacket -> writeIOData -> Output stream

The Input stream and Output stream must be identical. The following Linux/Unix command lines are connected by a named pipe:

mkfifo myNamedPipe

java testIOa | java testIOb

myNamedPipe is the name of the output for testIOa and the input for testIOb.