import com.mongodb.MongoClient;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Map;

/**
 * Created by aditya on 1/5/16.
 */
public class FileFetcher extends Thread {
    private Socket client;
    private String requestedResource;
    private Bufferpool pool;

    public FileFetcher(Socket client, Request req, Bufferpool pool){
        this.client = client;
        this.requestedResource = req.getRequestURL();
        this.pool = pool;
    }

    public void run() {
        try {
            byte[] file = pool.getResource(requestedResource);
            try {
                PrintWriter out =
                        new PrintWriter(client.getOutputStream(), true);

                Response res = new Response(200, file, requestedResource);
                res.writeData(client);
                client.close();
            }
            catch(IOException ioe){
                System.out.println("[ERROR] "+ioe.getMessage());
            }
        }
        catch(IOException IOE){
            System.out.println("[Error]" + IOE.getMessage());
            try {
                PrintWriter out =
                        new PrintWriter(client.getOutputStream(), true);

                Response res = new Response(404, "<h1> Sorry we couldn't find what you were looking for</h1><hr>\r\n");
                res.writeData(client);
                client.close();
            }
            catch(IOException ioe){}

            return;
        }
    }
}

@@ -1,12 +1,1496 @@
+Copyright (c) 2016, Aditya Ambadipudi%0AAll rights reserved.%0A%0ARedistribution and use in source and binary forms, with or without%0Amodification, are permitted provided that the following conditions are met:%0A%0A* Redistributions of source code must retain the above copyright notice, this%0A  list of conditions and the following disclaimer.%0A%0A* Redistributions in binary form must reproduce the above copyright notice,%0A  this list of conditions and the following disclaimer in the documentation%0A  and/or other materials provided with the distribution.%0A%0A* Neither the name of SilkRoad nor the names of its%0A  contributors may be used to endorse or promote products derived from%0A  this software without specific prior written permission.%0A%0ATHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS %22AS IS%22%0AAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE%0AIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE%0ADISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE%0AFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL%0ADAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR%0ASERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER%0ACAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,%0AOR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE%0AOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.%0A%0A
 import com.m

Update FileFetcher.java