package com.jenjinstudios.io.concurrency;

import com.jenjinstudios.io.Message;
import com.jenjinstudios.io.MessageReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * Reads incoming messages and stores them in a MessageQueue.
 *
 * @author Caleb Brinkman
 */
public class ReadTask implements Runnable
{
    private static final Logger LOGGER = LoggerFactory.getLogger(ReadTask.class);
    private final MessageQueue messageQueue;
    private final MessageReader messageReader;

    /**
     * Construct a new ReadTask that will read from the given message input stream and store the incoming messages in
     * the given MessageQueue.
     *
     * @param messageQueue The MessageQueue.
     * @param messageReader The MessageReader.
     */
    public ReadTask(MessageQueue messageQueue, MessageReader messageReader) {
        this.messageQueue = messageQueue;
        this.messageReader = messageReader;
    }

    @Override
    public void run() {
        try {
            final Message message = messageReader.read();
            messageQueue.messageReceived(message);
        } catch (IOException e) {
            messageQueue.errorEncountered(e);
            try {
                messageReader.close();
            } catch (IOException e1) {
                LOGGER.warn("Error when closing message reader", e1);
            }
        }
    }
}

@@ -170,24 +170,53 @@
 erFactory;%0A%0A
+import java.io.EOFException;%0A
 import java.
@@ -1142,24 +1142,317 @@
 d(message);%0A
+        %7D catch (EOFException ignored) %7B%0A            LOGGER.info(%22Client disconnected%22);%0A            try %7B%0A                messageReader.close();%0A            %7D catch (IOException closeException) %7B%0A                LOGGER.warn(%22Error when closing message reader%22, closeException);%0A            %7D%0A
         %7D ca
@@ -1609,18 +1609,30 @@
 ception 
-e1
+closeException
 ) %7B%0A    
@@ -1696,10 +1696,22 @@
 r%22, 
-e1
+closeException
 );%0A 

Add special handling for EOFException