@Test public void readsEntityStreamAsIteratorOfFileItems() throws Exception { Class type = Iterator.class; ParameterizedType genericType = newParameterizedType(Iterator.class, FileItem.class); Annotation[] annotations = new Annotation[0]; MultivaluedMap<String, String> headers = new MultivaluedHashMap<>(); InputStream in = mock(InputStream.class); mockHttpServletRequest(); Iterator<FileItem> fileItems = formDataEntityProvider.readFrom(type, genericType, annotations, null, headers, in); List<FileItem> fileItemList = Lists.newArrayList(fileItems); assertEquals(1, fileItemList.size()); assertEquals("text", fileItemList.get(0).getFieldName()); assertEquals("test.txt", fileItemList.get(0).getName()); assertEquals("text/plain", fileItemList.get(0).getContentType()); assertEquals("hello", fileItemList.get(0).getString()); }
@Override @SuppressWarnings("unchecked") public Iterator<FileItem> readFrom(Class<Iterator<FileItem>> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { try { ApplicationContext context = ApplicationContext.getCurrent(); int bufferSize = context.getEverrestConfiguration().getMaxBufferSize(); DefaultFileItemFactory factory = new DefaultFileItemFactory(bufferSize, FileCollector.getInstance().getStore()); FileUpload upload = new FileUpload(factory); return upload.parseRequest(httpRequest).iterator(); } catch (FileUploadException e) { throw new IOException(String.format("Can't process multipart data item, %s", e)); } }
MultipartFormDataEntityProvider implements EntityProvider<Iterator<FileItem>> { @Override @SuppressWarnings("unchecked") public Iterator<FileItem> readFrom(Class<Iterator<FileItem>> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { try { ApplicationContext context = ApplicationContext.getCurrent(); int bufferSize = context.getEverrestConfiguration().getMaxBufferSize(); DefaultFileItemFactory factory = new DefaultFileItemFactory(bufferSize, FileCollector.getInstance().getStore()); FileUpload upload = new FileUpload(factory); return upload.parseRequest(httpRequest).iterator(); } catch (FileUploadException e) { throw new IOException(String.format("Can't process multipart data item, %s", e)); } } }
MultipartFormDataEntityProvider implements EntityProvider<Iterator<FileItem>> { @Override @SuppressWarnings("unchecked") public Iterator<FileItem> readFrom(Class<Iterator<FileItem>> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { try { ApplicationContext context = ApplicationContext.getCurrent(); int bufferSize = context.getEverrestConfiguration().getMaxBufferSize(); DefaultFileItemFactory factory = new DefaultFileItemFactory(bufferSize, FileCollector.getInstance().getStore()); FileUpload upload = new FileUpload(factory); return upload.parseRequest(httpRequest).iterator(); } catch (FileUploadException e) { throw new IOException(String.format("Can't process multipart data item, %s", e)); } } MultipartFormDataEntityProvider(@Context HttpServletRequest httpRequest); }
MultipartFormDataEntityProvider implements EntityProvider<Iterator<FileItem>> { @Override @SuppressWarnings("unchecked") public Iterator<FileItem> readFrom(Class<Iterator<FileItem>> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { try { ApplicationContext context = ApplicationContext.getCurrent(); int bufferSize = context.getEverrestConfiguration().getMaxBufferSize(); DefaultFileItemFactory factory = new DefaultFileItemFactory(bufferSize, FileCollector.getInstance().getStore()); FileUpload upload = new FileUpload(factory); return upload.parseRequest(httpRequest).iterator(); } catch (FileUploadException e) { throw new IOException(String.format("Can't process multipart data item, %s", e)); } } 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); }
MultipartFormDataEntityProvider implements EntityProvider<Iterator<FileItem>> { @Override @SuppressWarnings("unchecked") public Iterator<FileItem> readFrom(Class<Iterator<FileItem>> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { try { ApplicationContext context = ApplicationContext.getCurrent(); int bufferSize = context.getEverrestConfiguration().getMaxBufferSize(); DefaultFileItemFactory factory = new DefaultFileItemFactory(bufferSize, FileCollector.getInstance().getStore()); FileUpload upload = new FileUpload(factory); return upload.parseRequest(httpRequest).iterator(); } catch (FileUploadException e) { throw new IOException(String.format("Can't process multipart data item, %s", e)); } } 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);  }