package forager.client;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import forager.events.ForagerEventMap;
import forager.events.ImportRequest;
import forager.events.ImportResponse;
import forager.ui.Launcher;

import galileo.event.BasicEventWrapper;
import galileo.event.EventContext;
import galileo.event.EventException;
import galileo.event.EventHandler;
import galileo.event.EventReactor;
import galileo.net.ClientMessageRouter;
import galileo.net.GalileoMessage;
import galileo.net.NetworkDestination;

public class Importer {

    private ForagerEventMap eventMap = new ForagerEventMap();
    private EventReactor eventReactor = new EventReactor(this, eventMap);

    private List<String> tasks = new ArrayList<>();

    private boolean successful;

    public boolean submitTasks(NetworkDestination server)
    throws Exception {
        ClientMessageRouter messageRouter = new ClientMessageRouter();
        messageRouter.addListener(eventReactor);
        ImportRequest request = new ImportRequest(tasks);

        messageRouter.sendMessage(server, eventReactor.wrapEvent(request));
        eventReactor.processNextEvent();
        boolean result = successful;

        successful = false;
        tasks.clear();
        messageRouter.shutdown();

        return result;
    }

    @EventHandler
    public void processResponse(ImportResponse response, EventContext context) {
        if (response.successful) {
            System.out.println("Successfully imported "
                    + tasks.size() + " tasks.");
        } else {
            System.out.println("Server could not complete import request!");
        }
    }
 
    public void addTaskFile(String file)
    throws FileNotFoundException, IOException {
        FileReader reader = new FileReader(file);
        int numTasks = readTaskData(reader);
        System.out.println("Importing " + numTasks + " tasks from " + file);
    }
 
    public int readTaskData(InputStreamReader reader)
    throws IOException {
        BufferedReader br = new BufferedReader(reader);
        int added = 0;
        String line;
        while ((line = br.readLine()) != null) {
            tasks.add(line);
            added++;
        }
        br.close();
        return added;
    }
}

@@ -346,76 +346,8 @@
 se;%0A
-import forager.ui.Launcher;%0A%0Aimport galileo.event.BasicEventWrapper;
 %0Aimp
@@ -382,45 +382,8 @@
 xt;%0A
-import galileo.event.EventException;%0A
 impo
@@ -492,43 +492,8 @@
 er;%0A
-import galileo.net.GalileoMessage;%0A
 impo
@@ -1418,251 +1418,48 @@
     
-if (response.successful) %7B%0A            System.out.println(%22Successfully imported %22%0A                    + tasks.size() + %22 tasks.%22);%0A        %7D else %7B%0A            System.out.println(%22Server could not complete import request!%22);%0A        %7D%0A    %7D%0A 
+successful = response.successful;%0A    %7D%0A
 %0A   
@@ -1466,20 +1466,19 @@
  public 
-void
+int
  addTask
@@ -1620,113 +1620,67 @@
 s = 
-readTaskData(reader);%0A        System.out.println(%22Importing %22 + numTasks + %22 tasks from %22 + file)
+addFromInputStream(reader);%0A        return numTasks
 ;%0A    %7D%0A
  %0A  
@@ -1675,17 +1675,16 @@
 ;%0A    %7D%0A
- 
 %0A    pub
@@ -1695,20 +1695,26 @@
 int 
-readTaskData
+addFromInputStream
 (Inp

Remove printed messages