package org.netmelody.tatin.server;

import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;

import org.simpleframework.http.Path;
import org.simpleframework.http.Request;
import org.simpleframework.http.Response;
import org.simpleframework.http.core.Container;

import com.google.common.base.Optional;
import com.google.common.io.ByteStreams;

public final class TatinContainer implements Container {

    private final Map<String, byte[]> state = new HashMap<String, byte[]>();

    @Override
    public void handle(Request req, Response resp) {
        if ("GET".equals(req.getMethod())) {
            handleGet(req, resp);
        }
    }

    private void handleGet(Request req, Response resp) {
        try {
            final OutputStream outputStream = resp.getOutputStream();
            ByteStreams.copy(ByteStreams.newInputStreamSupplier(valueAt(req.getPath())), outputStream);
            outputStream.close();
        }
        catch (Exception e) {
        }
    }

    private byte[] valueAt(final Path path) {
        return Optional.fromNullable(state.get(path.getPath())).or(new byte[0]);
    }

}
@@ -26,24 +26,52 @@
 in.server;%0A%0A
+import java.io.InputStream;%0A
 import java.
@@ -672,32 +672,434 @@
 esp);%0A        %7D%0A
+        if (%22PUT%22.equals(req.getMethod())) %7B%0A            handlePut(req, resp);%0A        %7D%0A    %7D%0A%0A    private void handlePut(Request req, Response resp) %7B%0A        try %7B%0A            final InputStream inputStream = req.getInputStream();%0A            state.put(req.getPath().getPath(), ByteStreams.toByteArray(inputStream));%0A            inputStream.close();%0A        %7D%0A        catch (Exception e) %7B%0A        %7D%0A
     %7D%0A%0A    priva

handle put