Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.github.joschi.jersey.security.smime;
 
 

Author(s):
Bill Burke
Version:
$Revision: 1 $
@Consumes("*/*")
public class EnvelopedReader implements MessageBodyReader<EnvelopedInput> {
    static {
        BouncyIntegration.init();
    }
    private static final String CRLF = "\r\n";
    @Context
    private Providers providers;
    public boolean isReadable(Class<?> typeType genericTypeAnnotation[] annotationsMediaType mediaType) {
        return EnvelopedInput.class.isAssignableFrom(type);
    }
    public EnvelopedInput readFrom(Class<EnvelopedInputtypeType genericTypeAnnotation[] annotationsMediaType mediaTypeMultivaluedMap<StringStringheadersInputStream entityStreamthrows IOExceptionWebApplicationException {
        Class<?> baseType = null;
        Type baseGenericType = null;
        if (genericType instanceof ParameterizedType) {
            ParameterizedType param = (ParameterizedTypegenericType;
            baseGenericType = param.getActualTypeArguments()[0];
            baseType = Types.getRawType(baseGenericType);
        }
        EnvelopedInputImpl input = new EnvelopedInputImpl();
        input.setType(baseType);
        input.setGenericType(baseGenericType);
        StringBuilder headerString = new StringBuilder();
        if (headers.containsKey("Content-Disposition")) {
            headerString.append("Content-Disposition: ").append(headers.getFirst("Content-Disposition")).append();
        }
        if (headers.containsKey("Content-Type")) {
            headerString.append("Content-Type: ").append(headers.getFirst("Content-Type")).append();
        }
        if (headers.containsKey("Content-Transfer-Encoding")) {
            headerString.append("Content-Transfer-Encoding: ").append(headers.getFirst("Content-Transfer-Encoding")).append();
        }
        headerString.append();
        ByteArrayInputStream is = new ByteArrayInputStream(headerString.toString().getBytes("utf-8"));
        MimeBodyPart body;
        try {
            body = new MimeBodyPart(new SequenceInputStream(isentityStream));
        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
        input.setProviders();
        input.setAnnotations(annotations);
        input.setBody(body);
        return input;
    }
New to GrepCode? Check out our FAQ X