<commit_before>package uk.me.mjt.s3test;

import com.amazonaws.auth.AnonymousAWSCredentials;
import com.amazonaws.internal.StaticCredentialsProvider;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.S3ClientOptions;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
import org.junit.After;
import org.junit.Before;

public class BasicTestSuperclass {
    
    S3Server instance;
    AmazonS3Client client;
    
    public BasicTestSuperclass() {
    }
    
    @Before
    public void setUp() throws Exception {
        instance = new S3Server();
        instance.start();
        Thread.sleep(100);
        client = new AmazonS3Client(new StaticCredentialsProvider(new AnonymousAWSCredentials()));
        client.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(true));
        //client.setEndpoint("http://localhost:8123");
        client.setEndpoint(instance.getAddress());
    }
    
    @After
    public void tearDown() throws Exception {
        client.shutdown();
        instance.stop();
        Thread.sleep(1000);
    }

    public void createDefaultBucket() throws Exception {
        createDefaultBucket(client);
    }

    public static void createDefaultBucket(AmazonS3Client client) throws Exception {
        client.createBucket("bucketname");

        byte[] content = "asdf".getBytes("UTF-8");
        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setContentLength(content.length);

        PutObjectRequest s3request = new PutObjectRequest("bucketname", "asdf.txt", new ByteArrayInputStream(content), metadata);
        client.putObject(s3request);
    }
    
    static String inputStreamToString(InputStream is) {
        // From http://stackoverflow.com/a/5445161/1367431
        try {
            java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
            return s.hasNext() ? s.next() : "";<commit_msg>Speed up those tests<commit_after>package uk.me.mjt.s3test;

import com.amazonaws.auth.AnonymousAWSCredentials;
import com.amazonaws.internal.StaticCredentialsProvider;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.S3ClientOptions;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
import org.junit.After;
import org.junit.Before;

public class BasicTestSuperclass {
    
    S3Server instance;
    AmazonS3Client client;
    
    public BasicTestSuperclass() {
    }
    
    @Before
    public void setUp() throws Exception {
        instance = new S3Server();
        instance.start();

        client = new AmazonS3Client(new StaticCredentialsProvider(new AnonymousAWSCredentials()));
        client.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(true));
        //client.setEndpoint("http://localhost:8123");
        client.setEndpoint(instance.getAddress());
    }
    
    @After
    public void tearDown() throws Exception {
        client.shutdown();
        instance.stop();
    }

    public void createDefaultBucket() throws Exception {
        createDefaultBucket(client);
    }

    public static void createDefaultBucket(AmazonS3Client client) throws Exception {
        client.createBucket("bucketname");

        byte[] content = "asdf".getBytes("UTF-8");
        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setContentLength(content.length);

        PutObjectRequest s3request = new PutObjectRequest("bucketname", "asdf.txt", new ByteArrayInputStream(content), metadata);
        client.putObject(s3request);
    }
    
    static String inputStreamToString(InputStream is) {
        // From http://stackoverflow.com/a/5445161/1367431
        try {
            java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
            return s.hasNext() ? s.next() : "";
{'fraction_non_alphanumeric': 0.10750061079892499, 'fraction_numerical': 0.018812606889811873, 'mean_word_length': 3.397422126745435, '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': '3746372', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1135, 'n_words': 215}