<commit_before>/**
 * 
 */
package org.resteasy.plugins.providers;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;

import javax.activation.DataSource;
import javax.mail.util.ByteArrayDataSource;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.MessageBodyReader;
import javax.ws.rs.ext.MessageBodyWriter;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a> Jun 23,
 *         2008
 * 
 */
public abstract class AbstractEntityProvider<T> implements
	MessageBodyReader<T>, MessageBodyWriter<T> {

    /**
     * 
     * @param in
     * @return
     * @throws IOException
     */
    protected String readString(InputStream in) throws IOException {
	char[] buffer = new char[100];
	StringBuilder builder = new StringBuilder();
	BufferedReader reader = new BufferedReader(new InputStreamReader(in));
	int wasRead = 0;
	do {
	    wasRead = reader.read(buffer, 0, 100);
	    if (wasRead > 0) {
		builder.append(buffer, 0, wasRead);
	    }
	} while (wasRead > -1);

	return builder.toString();
    }
    
    /**
     * 
     * @param in
     * @param mediaType
     * @return
     * @throws IOException
     */
    public DataSource readDataSource(InputStream in, MediaType mediaType) throws IOException {
	ByteArrayDataSource ds = 
	    new ByteArrayDataSource(
		    new BufferedInputStream(in), mediaType.toString());
	
	return ds;
    }
    
    /**
     * 
     */
    public long getSize(T t) {
	return -1;
    }
    
    /**
     * 
     * @param in
     * @param out
     * @throws IOException
     */
    public void writeTo(final InputStream in, 
	    	        final OutputStream out) throws IOException {
        int read;
        final byte[] buf = new byte[2048];
        while ((read = in.read(buf)) != -1) {
            out.write(buf, 0, read);
        }   
    }
}
<commit_msg>added new methods to support IIOImageProvider<commit_after>/**
 * 
 */
package org.resteasy.plugins.providers;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.sql.Array;
import java.util.ArrayList;
import java.util.List;

import javax.activation.DataSource;
import javax.mail.util.ByteArrayDataSource;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Variant;
import javax.ws.rs.core.Variant.VariantListBuilder;
import javax.ws.rs.ext.MessageBodyReader;
import javax.ws.rs.ext.MessageBodyWriter;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a> Jun 23,
 *         2008
 * 
 */
public abstract class AbstractEntityProvider<T> implements
	MessageBodyReader<T>, MessageBodyWriter<T> {

    /**
     * 
     * @param in
     * @return
     * @throws IOException
     */
    protected String readString(InputStream in) throws IOException {
	char[] buffer = new char[100];
	StringBuilder builder = new StringBuilder();
	BufferedReader reader = new BufferedReader(new InputStreamReader(in));
	int wasRead = 0;
	do {
	    wasRead = reader.read(buffer, 0, 100);
	    if (wasRead > 0) {
		builder.append(buffer, 0, wasRead);
	    }
	} while (wasRead > -1);

	return builder.toString();
    }
    
    /**
     * 
     * @param mediaTypes
     * @return
     */
    public List<MediaType> getAvailableMediaTypes(String[] mediaTypes) {
	List<MediaType> types = new ArrayList<MediaType>();
	for(String mediaType : mediaTypes) {
	    types.add(MediaType.valueOf(mediaType));
	}
	return types;
    }
    
    /**
     * 
     * @param mediaTypes
     * @return
     */
    public List<Variant> getAvailableVariants(String[] mediaTypes) {
	return getAvailableVariants(getAvailableMediaTypes(mediaTypes));
    }
    /**
     * 
     * @param mediaTypes
     * @return
     */
    public List<Variant> getAvailableVariants(List<MediaType> mediaTypes) {
	VariantListBuilder builder = Variant.VariantListBuilder.newInstance();
	MediaType[] types = mediaTypes.toArray(new MediaType[mediaTypes.size()]);
	builder.mediaTypes(types);
	return builder.build();
    }
    /**
     * 
     * @param in
     * @param mediaType
     * @return
     * @throws IOException
     */
    public DataSource readDataSource(InputStream in, MediaType mediaType) throws IOException {
	ByteArrayDataSource ds = 
	    new ByteArrayDataSource(
		    new BufferedInputStream(in), mediaType.toString());
	
	return ds;
    }
    
    /**
     * 
     */
    public long getSize(T t) {
	return -1;
    }
    
    /**
     * 
     * @param in
     * @param out
     * @throws IOException
     */
    public void writeTo(final InputStream in, 
	    	        final OutputStream out) throws IOException {
        int read;
        final byte[] buf = new byte[2048];
        while ((read = in.read(buf)) != -1) {
            out.write(buf, 0, read);
        }   
    }
}

{'fraction_non_alphanumeric': 0.1203496645659687, 'fraction_numerical': 0.00975808091075422, 'mean_word_length': 2.787528868360277, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 27, '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': '3756013', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1481, 'n_words': 340}