@Override public File apply(ContainerRequest request) { final FormDataBodyPart part = getEntity(request).getField(name); final BodyPartEntity entity = part != null ? part.getEntityAs(BodyPartEntity.class) : null; if (entity != null) { try { // Create a temporary file. final File file = Utils.createTempFile(); // Move the part (represented either via stream or file) to the specific temporary file. entity.moveTo(file); return file; } catch (final IOException | MIMEParsingException cannotMove) { // Unable to create a temporary file or move the file. LOGGER.log(Level.WARNING, LocalizationMessages.CANNOT_INJECT_FILE(), cannotMove); } } return null; } }
bodyPart.setEntity(new BodyPartEntity(mimePart));
/** * Defers to {@link #cleanup}. */ public void close() throws IOException { cleanup(); }
/** * Returns the entity after appropriate conversion to the requested type. This is useful only when the containing * {@link MultiPart} instance has been received, which causes the {@code providers} property to have been set. * * @param clazz desired class into which the entity should be converted. * @return entity after appropriate conversion to the requested type. * * @throws ProcessingException if an IO error arises during reading an entity. * @throws IllegalArgumentException if no {@link MessageBodyReader} can be found to perform the requested conversion. * @throws IllegalStateException if this method is called when the {@code providers} property has not been set or when the * entity instance is not the unconverted content of the body part entity. */ public <T> T getEntityAs(final Class<T> clazz) { if (entity == null || !(entity instanceof BodyPartEntity)) { throw new IllegalStateException(LocalizationMessages.ENTITY_HAS_WRONG_TYPE()); } if (clazz == BodyPartEntity.class) { return clazz.cast(entity); } final Annotation[] annotations = new Annotation[0]; final MessageBodyReader<T> reader = messageBodyWorkers.getMessageBodyReader(clazz, clazz, annotations, mediaType); if (reader == null) { throw new IllegalArgumentException(LocalizationMessages.NO_AVAILABLE_MBR(clazz, mediaType)); } try { return reader.readFrom(clazz, clazz, annotations, mediaType, headers, ((BodyPartEntity) entity).getInputStream()); } catch (final IOException ioe) { throw new ProcessingException(LocalizationMessages.ERROR_READING_ENTITY(String.class), ioe); } }
if (bodyEntity instanceof BodyPartEntity) { bodyClass = InputStream.class; bodyEntity = ((BodyPartEntity) bodyEntity).getInputStream();
stream = part.getEntityAs(BodyPartEntity.class).getInputStream(); mediaType, request.getHeaders(), ((BodyPartEntity) p.getEntity()).getInputStream());
entity.moveTo(file);
/** * Perform any necessary cleanup at the end of processing this * {@code BodyPart}. */ public void cleanup() { if ((getEntity() != null) && (getEntity() instanceof BodyPartEntity)) { ((BodyPartEntity) getEntity()).cleanup(); } }
bodyPart.setEntity(new BodyPartEntity(mimePart));
/** * Returns the entity after appropriate conversion to the requested type. This is useful only when the containing * {@link MultiPart} instance has been received, which causes the {@code providers} property to have been set. * * @param clazz desired class into which the entity should be converted. * @return entity after appropriate conversion to the requested type. * * @throws ProcessingException if an IO error arises during reading an entity. * @throws IllegalArgumentException if no {@link MessageBodyReader} can be found to perform the requested conversion. * @throws IllegalStateException if this method is called when the {@code providers} property has not been set or when the * entity instance is not the unconverted content of the body part entity. */ public <T> T getEntityAs(final Class<T> clazz) { if (entity == null || !(entity instanceof BodyPartEntity)) { throw new IllegalStateException(LocalizationMessages.ENTITY_HAS_WRONG_TYPE()); } if (clazz == BodyPartEntity.class) { return clazz.cast(entity); } final Annotation[] annotations = new Annotation[0]; final MessageBodyReader<T> reader = messageBodyWorkers.getMessageBodyReader(clazz, clazz, annotations, mediaType); if (reader == null) { throw new IllegalArgumentException(LocalizationMessages.NO_AVAILABLE_MBR(clazz, mediaType)); } try { return reader.readFrom(clazz, clazz, annotations, mediaType, headers, ((BodyPartEntity) entity).getInputStream()); } catch (final IOException ioe) { throw new ProcessingException(LocalizationMessages.ERROR_READING_ENTITY(String.class), ioe); } }
@Override public File apply(ContainerRequest request) { final FormDataBodyPart part = getEntity(request).getField(name); final BodyPartEntity entity = part != null ? part.getEntityAs(BodyPartEntity.class) : null; if (entity != null) { try { // Create a temporary file. final File file = Utils.createTempFile(); // Move the part (represented either via stream or file) to the specific temporary file. entity.moveTo(file); return file; } catch (final IOException | MIMEParsingException cannotMove) { // Unable to create a temporary file or move the file. LOGGER.log(Level.WARNING, LocalizationMessages.CANNOT_INJECT_FILE(), cannotMove); } } return null; } }
/** * Defers to {@link #cleanup}. */ public void close() throws IOException { cleanup(); }
bodyPart.setEntity(new BodyPartEntity(mimePart));
/** * Returns the entity after appropriate conversion to the requested type. This is useful only when the containing * {@link MultiPart} instance has been received, which causes the {@code providers} property to have been set. * * @param clazz desired class into which the entity should be converted. * @return entity after appropriate conversion to the requested type. * * @throws ProcessingException if an IO error arises during reading an entity. * @throws IllegalArgumentException if no {@link MessageBodyReader} can be found to perform the requested conversion. * @throws IllegalStateException if this method is called when the {@code providers} property has not been set or when the * entity instance is not the unconverted content of the body part entity. */ public <T> T getEntityAs(final Class<T> clazz) { if (entity == null || !(entity instanceof BodyPartEntity)) { throw new IllegalStateException(LocalizationMessages.ENTITY_HAS_WRONG_TYPE()); } if (clazz == BodyPartEntity.class) { return clazz.cast(entity); } final Annotation[] annotations = new Annotation[0]; final MessageBodyReader<T> reader = messageBodyWorkers.getMessageBodyReader(clazz, clazz, annotations, mediaType); if (reader == null) { throw new IllegalArgumentException(LocalizationMessages.NO_AVAILABLE_MBR(clazz, mediaType)); } try { return reader.readFrom(clazz, clazz, annotations, mediaType, headers, ((BodyPartEntity) entity).getInputStream()); } catch (final IOException ioe) { throw new ProcessingException(LocalizationMessages.ERROR_READING_ENTITY(String.class), ioe); } }
@Override public File provide() { final FormDataBodyPart part = getEntity().getField(name); final BodyPartEntity entity = part != null ? part.getEntityAs(BodyPartEntity.class) : null; if (entity != null) { try { // Create a temporary file. final File file = Utils.createTempFile(); // Move the part (represented either via stream or file) to the specific temporary file. entity.moveTo(file); return file; } catch (final IOException | MIMEParsingException cannotMove) { // Unable to create a temporary file or move the file. LOGGER.log(Level.WARNING, LocalizationMessages.CANNOT_INJECT_FILE(), cannotMove); } } return null; } }
/** * Defers to {@link #cleanup}. */ public void close() throws IOException { cleanup(); }
bodyPart.setEntity(new BodyPartEntity(mimePart));
/** * Returns the entity after appropriate conversion to the requested type. This is useful only when the containing * {@link MultiPart} instance has been received, which causes the {@code providers} property to have been set. * * @param clazz desired class into which the entity should be converted. * @return entity after appropriate conversion to the requested type. * * @throws ProcessingException if an IO error arises during reading an entity. * @throws IllegalArgumentException if no {@link MessageBodyReader} can be found to perform the requested conversion. * @throws IllegalStateException if this method is called when the {@code providers} property has not been set or when the * entity instance is not the unconverted content of the body part entity. */ public <T> T getEntityAs(final Class<T> clazz) { if (entity == null || !(entity instanceof BodyPartEntity)) { throw new IllegalStateException(LocalizationMessages.ENTITY_HAS_WRONG_TYPE()); } if (clazz == BodyPartEntity.class) { return clazz.cast(entity); } final Annotation[] annotations = new Annotation[0]; final MessageBodyReader<T> reader = messageBodyWorkers.getMessageBodyReader(clazz, clazz, annotations, mediaType); if (reader == null) { throw new IllegalArgumentException(LocalizationMessages.NO_AVAILABLE_MBR(clazz, mediaType)); } try { return reader.readFrom(clazz, clazz, annotations, mediaType, headers, ((BodyPartEntity) entity).getInputStream()); } catch (final IOException ioe) { throw new ProcessingException(LocalizationMessages.ERROR_READING_ENTITY(String.class), ioe); } }
@Override public File provide() { final FormDataBodyPart part = getEntity().getField(name); final BodyPartEntity entity = part != null ? part.getEntityAs(BodyPartEntity.class) : null; if (entity != null) { try { // Create a temporary file. final File file = Utils.createTempFile(); // Move the part (represented either via stream or file) to the specific temporary file. entity.moveTo(file); return file; } catch (final IOException | MIMEParsingException cannotMove) { // Unable to create a temporary file or move the file. LOGGER.log(Level.WARNING, LocalizationMessages.CANNOT_INJECT_FILE(), cannotMove); } } return null; } }
/** * Defers to {@link #cleanup}. */ public void close() throws IOException { cleanup(); }