List of usage examples for org.apache.commons.fileupload FileUpload FileUpload
public FileUpload()
FileItem
instances. From source file:org.synchronoss.cloud.nio.multipart.FunctionalTest.java
@Test public void nioParserFunctionalTest() throws Exception { log.info("NIO PARSER FUNCTIONAL TEST [ " + testCase.getDescription() + " ]"); if (log.isDebugEnabled()) { log.debug("Request body\n" + IOUtils.toString(testCase.getBodyInputStream())); }//from w w w .j av a 2 s .c o m final AtomicBoolean finished = new AtomicBoolean(false); final FileUpload fileUpload = new FileUpload(); final FileItemIterator fileItemIterator = fileUpload.getItemIterator(testCase.getRequestContext()); final NioMultipartParserListener nioMultipartParserListener = nioMultipartParserListenerVerifier( fileItemIterator, finished); // Comment out the NioMultipartParserListener above and uncomment the next two lines to // skip validation and just print the parts as extracted by the 2 frameworks. //dumpFileIterator(fileItemIterator); //final NioMultipartParserListener nioMultipartParserListener = nioMultipartParserListenerDumper(); final MultipartContext multipartContext = testCase.getMultipartContext(); final ChunksFileReader chunksFileReader = new ChunksFileReader(testCase.getBodyInputStream(), 5, 10); final NioMultipartParser parser = new NioMultipartParser(multipartContext, nioMultipartParserListener); byte[] chunk; while (true) { chunk = chunksFileReader.readChunk(); if (chunk.length <= 0) { break; } parser.write(chunk, 0, chunk.length); } int attempts = 0; while (!finished.get()) { Thread.sleep(100); if (++attempts > 3) { fail("Parser didn't come back in a reasonable time"); } } if (log.isInfoEnabled()) { List<String> fsmTransitions = parser.geFsmTransitions(); if (fsmTransitions != null) { log.info("TRANSITIONS: \n" + Joiner.on('\n').join(fsmTransitions)); } else { log.info("To see the FSM transitions enable debug on " + NioMultipartParser.class.getName()); } } }
From source file:org.synchronoss.cloud.nio.multipart.FunctionalTest.java
@Test public void blockingIOAdapterFunctionalTest() throws Exception { log.info("BLOCKING IO ADAPTER FUNCTIONAL TEST [ " + testCase.getDescription() + " ]"); if (log.isDebugEnabled()) { log.debug("Request body\n" + IOUtils.toString(testCase.getBodyInputStream())); }/*from w w w. ja v a 2 s .c om*/ final FileUpload fileUpload = new FileUpload(); final FileItemIterator fileItemIterator = fileUpload.getItemIterator(testCase.getRequestContext()); try (final CloseableIterator<PartItem> parts = Multipart.multipart(testCase.getMultipartContext()) .forBlockingIO(testCase.getBodyInputStream())) { while (parts.hasNext()) { BlockingIOAdapter.PartItem partItem = parts.next(); BlockingIOAdapter.PartItem.Type partItemType = partItem.getType(); if (BlockingIOAdapter.PartItem.Type.NESTED_END.equals(partItemType) || BlockingIOAdapter.PartItem.Type.NESTED_START.equals(partItemType)) { // Commons file upload is not returning an item representing the start/end of a nested multipart. continue; } assertTrue(fileItemIterator.hasNext()); FileItemStream fileItemStream = fileItemIterator.next(); assertEquals(partItem, fileItemStream); } } }