@Override public ByteBuf getByteBuf() throws IOException { return fileUpload.getByteBuf(); }
/** * Gets the content of this part as a <tt>ByteBuffer</tt>. * * <p>Because the contents of the file are released after being retrieved, * this method can only be called <strong>once</strong></p> * * @return The content of this part as a <tt>ByteBuffer</tt> * @throws IOException If an error occurs in retrieving the content */ @Override public ByteBuffer getByteBuffer() throws IOException { ByteBuf byteBuf = fileUpload.getByteBuf(); try { return byteBuf.nioBuffer(); } finally { byteBuf.release(); } }
/** * Gets the content of this part as a <tt>InputStream</tt>. * * <p>The contents of the file will be released when the stream is closed. * This method should only be called <strong>once</strong></p> * * @return The content of this part as a <tt>InputStream</tt> * @throws IOException If an error occurs in retrieving the content */ @Override public InputStream getInputStream() throws IOException { return new ByteBufInputStream(fileUpload.getByteBuf(), true); }
/** * Gets the content of this part as a <tt>byte[]</tt>. * * <p>Because the contents of the file are released after being retrieved, * this method can only be called <strong>once</strong></p> * * @return The content of this part as a <tt>byte[]</tt> * @throws IOException If an error occurs in retrieving the content */ @Override public byte[] getBytes() throws IOException { ByteBuf byteBuf = fileUpload.getByteBuf(); try { return ByteBufUtil.getBytes(byteBuf); } finally { byteBuf.release(); } }
@Override public Optional<Object> convert(FileUpload object, Class<Object> targetType, ConversionContext context) { try { if (!object.isCompleted()) { return Optional.empty(); } String contentType = object.getContentType(); ByteBuf byteBuf = object.getByteBuf(); if (StringUtils.isNotEmpty(contentType)) { MediaType mediaType = new MediaType(contentType); Optional<MediaTypeCodec> registered = decoderRegistryProvider.get().findCodec(mediaType); if (registered.isPresent()) { MediaTypeCodec decoder = registered.get(); Object val = decoder.decode(targetType, new ByteBufInputStream(byteBuf)); return Optional.of(val); } else { return conversionService.convert(byteBuf, targetType, context); } } return conversionService.convert(byteBuf, targetType, context); } catch (Exception e) { context.reject(e); return Optional.empty(); } } }
@Override public void addContent(ByteBuf buffer, boolean last) throws IOException { if (fileUpload instanceof MemoryFileUpload) { checkSize(fileUpload.length() + buffer.readableBytes()); if (fileUpload.length() + buffer.readableBytes() > limitSize) { DiskFileUpload diskFileUpload = new DiskFileUpload(fileUpload .getName(), fileUpload.getFilename(), fileUpload .getContentType(), fileUpload .getContentTransferEncoding(), fileUpload.getCharset(), definedSize); diskFileUpload.setMaxSize(maxSize); ByteBuf data = fileUpload.getByteBuf(); if (data != null && data.isReadable()) { diskFileUpload.addContent(data.retain(), false); } // release old upload fileUpload.release(); fileUpload = diskFileUpload; } } fileUpload.addContent(buffer, last); }
@Override public ByteBuf getByteBuf() throws IOException { return fileUpload.getByteBuf(); }
@Override public ByteBuf getByteBuf() throws IOException { return fileUpload.getByteBuf(); }
@Override public ByteBuf getByteBuf() throws IOException { return fileUpload.getByteBuf(); }
@Override public ByteBuf getByteBuf() throws IOException { return fileUpload.getByteBuf(); }
public static InputParameter getFormData(InterfaceHttpData data) { if (data == null) { return null; } String name = data.getName(); switch (data.getHttpDataType()) { case Attribute: Attribute attribute = (Attribute) data; try { return new InputParameter(name, attribute.getValue()); } catch (IOException e) { throw new AssertionError(e); } case FileUpload: FileUpload fileUpload = (FileUpload) data; String contentType = fileUpload.getContentType(); try { return new InputParameter(name, getBytes(fileUpload.getByteBuf()), contentType); } catch (IOException e) { throw new AssertionError(e); } default: throw new IllegalArgumentException( "Except form field, but got " + data.getHttpDataType()); } } }
@Override public void addContent(ByteBuf buffer, boolean last) throws IOException { if (fileUpload instanceof MemoryFileUpload) { checkSize(fileUpload.length() + buffer.readableBytes()); if (fileUpload.length() + buffer.readableBytes() > limitSize) { DiskFileUpload diskFileUpload = new DiskFileUpload(fileUpload .getName(), fileUpload.getFilename(), fileUpload .getContentType(), fileUpload .getContentTransferEncoding(), fileUpload.getCharset(), definedSize); diskFileUpload.setMaxSize(maxSize); ByteBuf data = fileUpload.getByteBuf(); if (data != null && data.isReadable()) { diskFileUpload.addContent(data.retain(), false); } // release old upload fileUpload.release(); fileUpload = diskFileUpload; } } fileUpload.addContent(buffer, last); }
@Override public void addContent(ByteBuf buffer, boolean last) throws IOException { if (fileUpload instanceof MemoryFileUpload) { checkSize(fileUpload.length() + buffer.readableBytes()); if (fileUpload.length() + buffer.readableBytes() > limitSize) { DiskFileUpload diskFileUpload = new DiskFileUpload(fileUpload .getName(), fileUpload.getFilename(), fileUpload .getContentType(), fileUpload .getContentTransferEncoding(), fileUpload.getCharset(), definedSize); diskFileUpload.setMaxSize(maxSize); ByteBuf data = fileUpload.getByteBuf(); if (data != null && data.isReadable()) { diskFileUpload.addContent(data.retain(), false); } // release old upload fileUpload.release(); fileUpload = diskFileUpload; } } fileUpload.addContent(buffer, last); }
@Override public void addContent(ByteBuf buffer, boolean last) throws IOException { if (fileUpload instanceof MemoryFileUpload) { checkSize(fileUpload.length() + buffer.readableBytes()); if (fileUpload.length() + buffer.readableBytes() > limitSize) { DiskFileUpload diskFileUpload = new DiskFileUpload(fileUpload .getName(), fileUpload.getFilename(), fileUpload .getContentType(), fileUpload .getContentTransferEncoding(), fileUpload.getCharset(), definedSize); diskFileUpload.setMaxSize(maxSize); ByteBuf data = fileUpload.getByteBuf(); if (data != null && data.isReadable()) { diskFileUpload.addContent(data.retain(), false); } // release old upload fileUpload.release(); fileUpload = diskFileUpload; } } fileUpload.addContent(buffer, last); }
@Override public void addContent(ByteBuf buffer, boolean last) throws IOException { if (fileUpload instanceof MemoryFileUpload) { checkSize(fileUpload.length() + buffer.readableBytes()); if (fileUpload.length() + buffer.readableBytes() > limitSize) { DiskFileUpload diskFileUpload = new DiskFileUpload(fileUpload .getName(), fileUpload.getFilename(), fileUpload .getContentType(), fileUpload .getContentTransferEncoding(), fileUpload.getCharset(), definedSize); diskFileUpload.setMaxSize(maxSize); ByteBuf data = fileUpload.getByteBuf(); if (data != null && data.isReadable()) { diskFileUpload.addContent(data.retain(), false); } // release old upload fileUpload.release(); fileUpload = diskFileUpload; } } fileUpload.addContent(buffer, last); }
try { FileUpload nettyFileUpload = (FileUpload) data; final ByteBuf byteBuf = nettyFileUpload.getByteBuf(); byteBuf.retain(); context.onClose(ro -> byteBuf.release());