Class<?> rawType = Types.getRawType(baseType); MultipartInputImpl input = new MultipartInputImpl(mediaType, workers); input.parse(entityStream); for (InputPart part : input.getParts()) list.add(part.getBody(rawType, baseType)); input.close();
public void parse(InputStream is) throws IOException { mimeMessage = new BinaryMessage(addHeaderToHeadlessStream(is)); extractParts(); }
protected InputStream addHeaderToHeadlessStream(InputStream is) throws UnsupportedEncodingException { return new SequenceInputStream(createHeaderInputStream(), is); }
public MultipartInput readFrom(Class<MultipartInput> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { String boundary = mediaType.getParameters().get("boundary"); if (boundary == null) throw new IOException(Messages.MESSAGES.unableToGetBoundary()); MultipartInputImpl input = new MultipartInputImpl(mediaType, workers); /* StringWriter writer = new StringWriter(); int b; do { b = entityStream.read(); if (b == -1) break; writer.write(b); } while (b != -1); System.out.println(writer.toString()); */ input.parse(entityStream); return input; } }
MediaType contentType = new MediaType("multipart", "form-data", parameters); MultipartInputImpl multipart = new MultipartInputImpl(contentType, null); multipart.parse(bais); LOG.info(multipart.getPreamble()); LOG.info("**********"); for (InputPart part : multipart.getParts())
@Override protected InputPart extractPart(BodyPart bodyPart) throws IOException { InputPart inputPart = super.extractPart(bodyPart); relatedMap .put(inputPart.getHeaders().getFirst("Content-ID"), inputPart); return inputPart; }
public MultipartInputImpl(final MediaType contentType, final Providers workers, final MediaType defaultPartContentType, final String defaultPartCharset) { this.contentType = contentType; this.workers = workers; if (defaultPartContentType != null) this.defaultPartContentType = defaultPartContentType; this.defaultPartCharset = defaultPartCharset; if (defaultPartCharset != null) { this.defaultPartContentType = getMediaTypeWithDefaultCharset(this.defaultPartContentType); } }
protected void finalize() throws Throwable { close(); }
private MediaType getMediaTypeWithDefaultCharset(MediaType mediaType) { String charset = defaultPartCharset; return getMediaTypeWithCharset(mediaType, charset); }
public PartImpl(final BodyPart bodyPart) { this.bodyPart = bodyPart; for (Field field : bodyPart.getHeader()) { headers.add(field.getName(), field.getBody()); if (field instanceof ContentTypeField) { contentType = MediaType.valueOf(field.getBody()); contentTypeFromMessage = true; } } if (contentType == null) contentType = defaultPartContentType; if (getCharset(contentType) == null) { if (defaultPartCharset != null) { contentType = getMediaTypeWithDefaultCharset(contentType); } else if (contentType.getType().equalsIgnoreCase("text")) { contentType = getMediaTypeWithCharset(contentType, "us-ascii"); } } }
return (T) new MultipartInputImpl(Multipart.class.cast(bodyPart.getBody()), workers);
MediaType contentType = new MediaType("multipart", "form-data", parameters); MultipartInputImpl multipart = new MultipartInputImpl(contentType, null); multipart.parse(bais); LOG.info(multipart.getPreamble()); LOG.info("**********"); for (InputPart part : multipart.getParts())
public MultipartInputImpl(final Multipart multipart, final Providers workers) throws IOException { for (BodyPart bodyPart : multipart.getBodyParts()) parts.add(extractPart(bodyPart)); this.workers = workers; }
public MultipartInput readFrom(Class<MultipartInput> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { String boundary = mediaType.getParameters().get("boundary"); if (boundary == null) throw new IOException(Messages.MESSAGES.unableToGetBoundary()); MultipartInputImpl input = new MultipartInputImpl(mediaType, workers); /* StringWriter writer = new StringWriter(); int b; do { b = entityStream.read(); if (b == -1) break; writer.write(b); } while (b != -1); System.out.println(writer.toString()); */ input.parse(entityStream); return input; } }
public MultipartInputImpl(final MediaType contentType, final Providers workers) { this.contentType = contentType; this.workers = workers; HttpRequest httpRequest = ResteasyContext.getContextData(HttpRequest.class); if (httpRequest != null) { String defaultContentType = (String) httpRequest .getAttribute(InputPart.DEFAULT_CONTENT_TYPE_PROPERTY); if (defaultContentType != null) this.defaultPartContentType = MediaType .valueOf(defaultContentType); this.defaultPartCharset = (String) httpRequest.getAttribute(InputPart.DEFAULT_CHARSET_PROPERTY); if (defaultPartCharset != null) { this.defaultPartContentType = getMediaTypeWithDefaultCharset(this.defaultPartContentType); } } }
protected void finalize() throws Throwable { close(); }
private MediaType getMediaTypeWithDefaultCharset(MediaType mediaType) { String charset = defaultPartCharset; return getMediaTypeWithCharset(mediaType, charset); }
public PartImpl(BodyPart bodyPart) { this.bodyPart = bodyPart; for (Field field : bodyPart.getHeader()) { headers.add(field.getName(), field.getBody()); if (field instanceof ContentTypeField) { contentType = MediaType.valueOf(field.getBody()); contentTypeFromMessage = true; } } if (contentType == null) contentType = defaultPartContentType; if (getCharset(contentType) == null) { if (defaultPartCharset != null) { contentType = getMediaTypeWithDefaultCharset(contentType); } else if (contentType.getType().equalsIgnoreCase("text")) { contentType = getMediaTypeWithCharset(contentType, "us-ascii"); } } }
return (T) new MultipartInputImpl(Multipart.class.cast(bodyPart.getBody()), workers);
Class<?> rawType = Types.getRawType(baseType); MultipartInputImpl input = new MultipartInputImpl(mediaType, workers); input.parse(entityStream); for (InputPart part : input.getParts()) list.add(part.getBody(rawType, baseType)); input.close();