MultipartFormDataEntityProvider implements EntityProvider<Iterator<FileItem>> { @Override public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { if (type == Iterator.class) { if (genericType instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType)genericType; Type[] actualTypeArguments = parameterizedType.getActualTypeArguments(); return actualTypeArguments.length == 1 && actualTypeArguments[0] == FileItem.class; } } return false; } MultipartFormDataEntityProvider(@Context HttpServletRequest httpRequest); @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override @SuppressWarnings("unchecked") Iterator<FileItem> readFrom(Class<Iterator<FileItem>> type,
                                       Type genericType,
                                       Annotation[] annotations,
                                       MediaType mediaType,
                                       MultivaluedMap<String, String> httpHeaders,
                                       InputStream entityStream); @Override long getSize(Iterator<FileItem> t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override void writeTo(Iterator<FileItem> t,
                        Class<?> type,
                        Type genericType,
                        Annotation[] annotations,
                        MediaType mediaType,
                        MultivaluedMap<String, Object> httpHeaders,
                        OutputStream entityStream);  }
@Test public void isReadableForIteratorOfFileItems() throws Exception { Class<Iterator> type = Iterator.class; ParameterizedType genericType = newParameterizedType(Iterator.class, FileItem.class); assertTrue(formDataEntityProvider.isReadable(type, genericType, new Annotation[0], null)); }
@Test public void isNotReadableForIteratorOfOtherTypeThanFileItem() throws Exception { Class<Iterator> type = Iterator.class; ParameterizedType genericType = newParameterizedType(Iterator.class, String.class); assertFalse(formDataEntityProvider.isReadable(type, genericType, new Annotation[0], null)); }
@Test public void isNotReadableWhenGenericTypeIsNotAvailable() throws Exception { Class<Iterator> type = Iterator.class; assertFalse(formDataEntityProvider.isReadable(type, null, new Annotation[0], null)); }