<commit_before>package store.server;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.inject.Singleton;
import javax.json.JsonObject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;
import org.glassfish.jersey.media.multipart.FormDataParam;
import store.common.ContentInfo;
import store.common.Hash;
import static store.common.JsonUtil.readConfig;
import static store.common.JsonUtil.readContentInfo;
import static store.common.JsonUtil.write;

@Path("/")
@Singleton
public class StoreResource {

    private final StoreManager storeManager;

    public StoreResource(StoreManager storeManager) {
        this.storeManager = storeManager;
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Path("create")
    public Response create(JsonObject json) {
        storeManager.create(readConfig(json));
        return Response.ok().build();
    }

    @POST
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @Path("put")
    public Response put(@FormDataParam("info") JsonObject json, @FormDataParam("source") InputStream inputStream) {
        storeManager.put(readContentInfo(json), inputStream);
        return Response.ok().build();
    }

    @POST
    @Path("delete/{hash}")
    public Response delete(@PathParam("hash") String encodedHash) {
        storeManager.delete(new Hash(encodedHash));
        return Response.ok().build();
    }

    @GET
    @Produces(MediaType.APPLICATION_OCTET_STREAM)
    @Path("get/{hash}")
    public Response get(@PathParam("hash") String encodedHash) {
        final Hash hash = new Hash(encodedHash);
        return Response.ok(new StreamingOutput() {
            @Override
            public void write(OutputStream outputStream) throws IOException, WebApplicationException {
                try (ContentReader reader = storeManager.get(hash)) {
                    InputStream inputStream = reader.inputStream();
                    byte[] buffer = new byte[8192];
                    int len = inputStream.read(buffer);
                    while (len != -1) {
                        outputStream.write(buffer, 0, len);
                        len = inputStream.read(buffer);
                    }
                }
            }
        }).build();
    }

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("info/{hash}")
    public JsonObject info(@PathParam("hash") String encodedHash) {
        ContentInfo info = storeManager.info(new Hash(encodedHash));
        return write(info);
    }
}<commit_msg>Suppression item inutile d'une clause "throws".<commit_after>package store.server;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.inject.Singleton;
import javax.json.JsonObject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;
import org.glassfish.jersey.media.multipart.FormDataParam;
import store.common.ContentInfo;
import store.common.Hash;
import static store.common.JsonUtil.readConfig;
import static store.common.JsonUtil.readContentInfo;
import static store.common.JsonUtil.write;

@Path("/")
@Singleton
public class StoreResource {

    private final StoreManager storeManager;

    public StoreResource(StoreManager storeManager) {
        this.storeManager = storeManager;
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Path("create")
    public Response create(JsonObject json) {
        storeManager.create(readConfig(json));
        return Response.ok().build();
    }

    @POST
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @Path("put")
    public Response put(@FormDataParam("info") JsonObject json, @FormDataParam("source") InputStream inputStream) {
        storeManager.put(readContentInfo(json), inputStream);
        return Response.ok().build();
    }

    @POST
    @Path("delete/{hash}")
    public Response delete(@PathParam("hash") String encodedHash) {
        storeManager.delete(new Hash(encodedHash));
        return Response.ok().build();
    }

    @GET
    @Produces(MediaType.APPLICATION_OCTET_STREAM)
    @Path("get/{hash}")
    public Response get(@PathParam("hash") String encodedHash) {
        final Hash hash = new Hash(encodedHash);
        return Response.ok(new StreamingOutput() {
            @Override
            public void write(OutputStream outputStream) throws IOException {
                try (ContentReader reader = storeManager.get(hash)) {
                    InputStream inputStream = reader.inputStream();
                    byte[] buffer = new byte[8192];
                    int len = inputStream.read(buffer);
                    while (len != -1) {
                        outputStream.write(buffer, 0, len);
                        len = inputStream.read(buffer);
                    }
                }
            }
        }).build();
    }

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("info/{hash}")
    public JsonObject info(@PathParam("hash") String encodedHash) {
        ContentInfo info = storeManager.info(new Hash(encodedHash));
        return write(info);
    }
}
{'fraction_non_alphanumeric': 0.11464163206354938, 'fraction_numerical': 0.002166456038996209, 'mean_word_length': 2.926293408929837, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1369705', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1529, 'n_words': 318}