NioMultipartParser extends OutputStream implements Disposable { @Override public void close() throws IOException { if (closed.compareAndSet(false, true)) { if (partBodyStreamStorage != null) { partBodyStreamStorage.close(); } } } NioMultipartParser(final MultipartContext multipartContext, final NioMultipartParserListener nioMultipartParserListener);  NioMultipartParser(final MultipartContext multipartContext, final NioMultipartParserListener nioMultipartParserListener, final PartBodyStreamStorageFactory partBodyStreamStorageFactory);  NioMultipartParser(final MultipartContext multipartContext, final NioMultipartParserListener nioMultipartParserListener, final int bufferSize);  NioMultipartParser(final MultipartContext multipartContext,
                              final NioMultipartParserListener nioMultipartParserListener,
                              final PartBodyStreamStorageFactory partBodyStreamStorageFactory,
                              final int bufferSize,
                              final int maxHeadersSectionSize,
                              final int maxLevelOfNestedMultipart); @Override void close(); @Override boolean dispose(); @Override void flush(); @Override void write(final int data); @Override void write(byte[] data); @Override void write(byte[] data, int indexStart, int indexEnd); List<String> geFsmTransitions(); static final int DEFAULT_BUFFER_SIZE; static final int DEFAULT_HEADERS_SECTION_SIZE; static final int DEFAULT_MAX_LEVEL_OF_NESTED_MULTIPART; }
@Test public void testClose() throws IOException { MultipartContext context = mock(MultipartContext.class); when(context.getContentType()).thenReturn("multipart/form-data;boundary=AAA"); NioMultipartParserListener listener = mock(NioMultipartParserListener.class); PartBodyStreamStorageFactory partBodyStreamStorageFactory = mock(PartBodyStreamStorageFactory.class); StreamStorage streamStorage = mock(StreamStorage.class); when(partBodyStreamStorageFactory.newStreamStorageForPartBody(anyMap(), anyInt())).thenReturn(streamStorage); NioMultipartParser parser = new NioMultipartParser(context, listener, partBodyStreamStorageFactory); byte[] part = "--AAA\r\nContent-Type: text/plain\r\n\r\nThis is a body".getBytes(); for (byte aPartByte : part) { parser.write(aPartByte); } parser.close(); verify(streamStorage).close(); }