本文整理匯總了Java中org.apache.commons.fileupload.FileUpload.getItemIterator方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUpload.getItemIterator方法的具體用法?Java FileUpload.getItemIterator怎麽用?Java FileUpload.getItemIterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.fileupload.FileUpload
的用法示例。
在下文中一共展示了FileUpload.getItemIterator方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: blockingIOAdapterFunctionalTest
import org.apache.commons.fileupload.FileUpload; //導入方法依賴的package包/類
@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()));
}
final FileUpload fileUpload = new FileUpload();
final FileItemIterator fileItemIterator = fileUpload.getItemIterator(testCase.getRequestContext());
try(final CloseableIterator<ParserToken> parts = Multipart.multipart(testCase.getMultipartContext()).forBlockingIO(testCase.getBodyInputStream())) {
while (parts.hasNext()) {
ParserToken parserToken = parts.next();
ParserToken.Type partItemType = parserToken.getType();
if (ParserToken.Type.NESTED_END.equals(partItemType) || ParserToken.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(parserToken, fileItemStream);
}
}
}
示例2: parseRequest
import org.apache.commons.fileupload.FileUpload; //導入方法依賴的package包/類
protected void parseRequest(MultipartFormData multipartFormData, FileUpload fileUpload, RestMultipartRequestContext requestContext) {
try {
FileItemIterator itemIterator = fileUpload.getItemIterator(requestContext);
while (itemIterator.hasNext()) {
FileItemStream stream = itemIterator.next();
multipartFormData.addPart(new FormPart(stream));
}
} catch (Exception e) {
throw new RestException(Status.BAD_REQUEST, e, "multipart/form-data cannot be processed");
}
}
示例3: nioParserFunctionalTest
import org.apache.commons.fileupload.FileUpload; //導入方法依賴的package包/類
@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()));
}
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());
}
}
}