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 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; }
Map.Entry<Object, Object> entry = iter.next(); Object value = entry.getValue(); Attachment handler = createDataHandler(value, value.getClass(), new Annotation[]{}, entry.getKey().toString(), Attachment handler = createDataHandler(obj, genericType, anns, rootMediaType, mt.toString(), 1);
Map.Entry<Object, Object> entry = iter.next(); Object value = entry.getValue(); Attachment handler = createDataHandler(value, value.getClass(), new Annotation[]{}, entry.getKey().toString(), Attachment handler = createDataHandler(obj, genericType, anns, rootMediaType, mt.toString(), 1);
private <T> Attachment createDataHandler(T obj, Class<T> cls, Type genericType, Annotation[] anns, String mimeType, String mainMediaType, int id) throws IOException { DataHandler dh = null; if (InputStream.class.isAssignableFrom(obj.getClass())) { dh = createInputStreamDH((InputStream)obj, mimeType); } else if (DataHandler.class.isAssignableFrom(obj.getClass())) { dh = (DataHandler)obj; } else if (DataSource.class.isAssignableFrom(obj.getClass())) { dh = new DataHandler((DataSource)obj); } else if (File.class.isAssignableFrom(obj.getClass())) { File f = (File)obj; ContentDisposition cd = mainMediaType.startsWith(MediaType.MULTIPART_FORM_DATA) ? new ContentDisposition("form-data;name=file;filename=" + f.getName()) : null; return new Attachment(AttachmentUtil.BODY_ATTACHMENT_ID, Files.newInputStream(f.toPath()), cd); } else if (Attachment.class.isAssignableFrom(obj.getClass())) { Attachment att = (Attachment)obj; if (att.getObject() == null) { return att; } dh = getHandlerForObject(att.getObject(), att.getObject().getClass(), new Annotation[]{}, att.getContentType().toString(), id); return new Attachment(att.getContentId(), dh, att.getHeaders()); } else if (byte[].class.isAssignableFrom(obj.getClass())) { ByteDataSource source = new ByteDataSource((byte[])obj);
private <T> Attachment createDataHandler(T obj, Class<T> cls, Type genericType, Annotation[] anns, String mimeType, String mainMediaType, int id) throws IOException { DataHandler dh = null; if (InputStream.class.isAssignableFrom(obj.getClass())) { dh = createInputStreamDH((InputStream)obj, mimeType); } else if (DataHandler.class.isAssignableFrom(obj.getClass())) { dh = (DataHandler)obj; } else if (DataSource.class.isAssignableFrom(obj.getClass())) { dh = new DataHandler((DataSource)obj); } else if (File.class.isAssignableFrom(obj.getClass())) { File f = (File)obj; ContentDisposition cd = mainMediaType.startsWith(MediaType.MULTIPART_FORM_DATA) ? new ContentDisposition("form-data;name=file;filename=" + f.getName()) : null; return new Attachment(AttachmentUtil.BODY_ATTACHMENT_ID, new FileInputStream(f), cd); } else if (Attachment.class.isAssignableFrom(obj.getClass())) { Attachment att = (Attachment)obj; if (att.getObject() == null) { return att; } dh = getHandlerForObject(att.getObject(), att.getObject().getClass(), new Annotation[]{}, att.getContentType().toString(), id); return new Attachment(att.getContentId(), dh, att.getHeaders()); } else if (byte[].class.isAssignableFrom(obj.getClass())) { ByteDataSource source = new ByteDataSource((byte[])obj);