private List<Attachment> getAttachments(List<?> objects, String rootMediaType) throws IOException { List<Attachment> handlers = new ArrayList<>(objects.size()); for (int i = 0; i < objects.size(); i++) { Object value = objects.get(i); Attachment handler = createDataHandler(value, value.getClass(), new Annotation[]{}, rootMediaType, rootMediaType, i); handlers.add(handler); } return handlers; }
private Object getAttachmentCollection(Type t, List<Attachment> infos, Annotation[] anns) throws IOException { Class<?> actual = getActualType(t, 0); if (Attachment.class.isAssignableFrom(actual)) { return infos; } Collection<Object> objects = new ArrayList<>(); for (Attachment a : infos) { objects.add(fromAttachment(a, actual, actual, anns)); } return objects; }
private <T> DataHandler getHandlerForObject(T obj, Type genericType, Annotation[] anns, String mimeType, int id) { @SuppressWarnings("unchecked") Class<T> cls = (Class<T>)obj.getClass(); return getHandlerForObject(obj, cls, genericType, anns, mimeType, id); }
public Object readFrom(Class<Object> c, Type t, Annotation[] anns, MediaType mt, MultivaluedMap<String, String> headers, InputStream is) throws IOException, WebApplicationException { checkContentLength(); List<Attachment> infos = AttachmentUtils.getAttachments( mc, attachmentDir, attachmentThreshold, attachmentMaxSize); if (collectionExpected && AnnotationUtils.getAnnotation(anns, Multipart.class) == null) { return getAttachmentCollection(t, infos, anns); Class<?> actual = getActualType(t, 1); for (Attachment a : infos) { map.put(a.getContentType().toString(), fromAttachment(a, actual, actual, anns)); if (multipart != null) { if (collectionExpected && !mediaTypeSupported(multipart.getContentType()) && !PropertyUtils.isTrue(mc.getContextualProperty(SINGLE_PART_IS_COLLECTION))) { List<Attachment> allMultiparts = AttachmentUtils.getMatchingAttachments(id, infos); return getAttachmentCollection(t, allMultiparts, anns); return fromAttachment(multipart, c, t, anns);
DataHandler dh = null; if (InputStream.class.isAssignableFrom(obj.getClass())) { dh = createInputStreamDH((InputStream)obj, mimeType); } else if (DataHandler.class.isAssignableFrom(obj.getClass())) { dh = (DataHandler)obj; return att; dh = getHandlerForObject(att.getObject(), att.getObject().getClass(), new Annotation[]{}, att.getContentType().toString(), id); dh = new DataHandler(source); } else { dh = getHandlerForObject(obj, cls, genericType, anns, mimeType, id); String contentId = getContentId(anns, id); MultivaluedMap<String, String> headers = new MetadataMap<>(); headers.putSingle("Content-Type", mimeType);
Map.Entry<Object, Object> entry = iter.next(); Object value = entry.getValue(); Attachment handler = createDataHandler(value, value.getClass(), new Annotation[]{}, entry.getKey().toString(), String rootMediaType = getRootMediaType(anns, mt); if (List.class.isAssignableFrom(obj.getClass())) { return getAttachments((List<?>)obj, rootMediaType); return getAttachments(atts, rootMediaType); Attachment handler = createDataHandler(obj, genericType, anns, rootMediaType, mt.toString(), 1);
public void writeTo(Object obj, Class<?> type, Type genericType, Annotation[] anns, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException { List<Attachment> handlers = convertToDataHandlers(obj, type, genericType, anns, mt); mc.put(MultipartBody.OUTBOUND_MESSAGE_ATTACHMENTS, handlers); handlers.get(0).getDataHandler().writeTo(os); }
public Object readFrom(Class<Object> c, Type t, Annotation[] anns, MediaType mt, MultivaluedMap<String, String> headers, InputStream is) throws IOException, WebApplicationException { checkContentLength(); List<Attachment> infos = AttachmentUtils.getAttachments( mc, attachmentDir, attachmentThreshold, attachmentMaxSize); if (collectionExpected && AnnotationUtils.getAnnotation(anns, Multipart.class) == null) { return getAttachmentCollection(t, infos, anns); Class<?> actual = getActualType(t, 1); for (Attachment a : infos) { map.put(a.getContentType().toString(), fromAttachment(a, actual, actual, anns)); if (multipart != null) { if (collectionExpected && !mediaTypeSupported(multipart.getContentType()) && !MessageUtils.isTrue(mc.getContextualProperty(SINGLE_PART_IS_COLLECTION))) { List<Attachment> allMultiparts = AttachmentUtils.getMatchingAttachments(id, infos); return getAttachmentCollection(t, allMultiparts, anns); } else { return fromAttachment(multipart, c, t, anns);
DataHandler dh = null; if (InputStream.class.isAssignableFrom(obj.getClass())) { dh = createInputStreamDH((InputStream)obj, mimeType); } else if (DataHandler.class.isAssignableFrom(obj.getClass())) { dh = (DataHandler)obj; return att; dh = getHandlerForObject(att.getObject(), att.getObject().getClass(), new Annotation[]{}, att.getContentType().toString(), id); dh = new DataHandler(source); } else { dh = getHandlerForObject(obj, cls, genericType, anns, mimeType, id); String contentId = getContentId(anns, id);
Map.Entry<Object, Object> entry = iter.next(); Object value = entry.getValue(); Attachment handler = createDataHandler(value, value.getClass(), new Annotation[]{}, entry.getKey().toString(), String rootMediaType = getRootMediaType(anns, mt); if (List.class.isAssignableFrom(obj.getClass())) { return getAttachments((List<?>)obj, rootMediaType); } else { if (MultipartBody.class.isAssignableFrom(type)) { List<Attachment> atts = ((MultipartBody)obj).getAllAttachments(); return getAttachments(atts, rootMediaType); Attachment handler = createDataHandler(obj, genericType, anns, rootMediaType, mt.toString(), 1);
public void writeTo(Object obj, Class<?> type, Type genericType, Annotation[] anns, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException { List<Attachment> handlers = convertToDataHandlers(obj, type, genericType, anns, mt); if (mc.get(AttachmentUtils.OUT_FILTERS) != null) { List<MultipartOutputFilter> filters = CastUtils.cast((List<?>)mc.get(AttachmentUtils.OUT_FILTERS)); for (MultipartOutputFilter filter : filters) { filter.filter(handlers); } } mc.put(MultipartBody.OUTBOUND_MESSAGE_ATTACHMENTS, handlers); handlers.get(0).getDataHandler().writeTo(os); }
private Object getAttachmentCollection(Type t, List<Attachment> infos, Annotation[] anns) throws IOException { Class<?> actual = getActualType(t, 0); if (Attachment.class.isAssignableFrom(actual)) { return infos; } Collection<Object> objects = new ArrayList<Object>(); for (Attachment a : infos) { objects.add(fromAttachment(a, actual, actual, anns)); } return objects; }
private List<Attachment> getAttachments(List<?> objects, String rootMediaType) throws IOException { List<Attachment> handlers = new ArrayList<Attachment>(objects.size()); for (int i = 0; i < objects.size(); i++) { Object value = objects.get(i); Attachment handler = createDataHandler(value, value.getClass(), new Annotation[]{}, rootMediaType, rootMediaType, i); handlers.add(handler); } return handlers; }
private <T> DataHandler getHandlerForObject(T obj, Type genericType, Annotation[] anns, String mimeType, int id) { @SuppressWarnings("unchecked") Class<T> cls = (Class<T>)obj.getClass(); return getHandlerForObject(obj, cls, genericType, anns, mimeType, id); }