當前位置: 首頁>>代碼示例>>Java>>正文


Java FileItemIterator.hasNext方法代碼示例

本文整理匯總了Java中org.apache.commons.fileupload.FileItemIterator.hasNext方法的典型用法代碼示例。如果您正苦於以下問題:Java FileItemIterator.hasNext方法的具體用法?Java FileItemIterator.hasNext怎麽用?Java FileItemIterator.hasNext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.fileupload.FileItemIterator的用法示例。


在下文中一共展示了FileItemIterator.hasNext方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getRequestData

import org.apache.commons.fileupload.FileItemIterator; //導入方法依賴的package包/類
private Map<String, String> getRequestData(HttpServletRequest request) {
  Map<String, String> requestData = new HashMap<>();

  ServletFileUpload upload = new ServletFileUpload();
  try {
    FileItemIterator itemIterator = upload.getItemIterator(request);
    while (itemIterator.hasNext()) {
      FileItemStream item = itemIterator.next();
      InputStream itemStream = item.openStream();
      String value = Streams.asString(itemStream, CharEncoding.UTF_8);
      requestData.put(item.getFieldName(), value);
    }
  } catch (FileUploadException | IOException e) {
    LOGGER.error("Failed to process request", e);
  }

  return requestData;
}
 
開發者ID:Cognifide,項目名稱:aet,代碼行數:19,代碼來源:SuiteServlet.java

示例2: blockingIoMultipart

import org.apache.commons.fileupload.FileItemIterator; //導入方法依賴的package包/類
/**
 * <p> Example of parsing the multipart request using commons file upload. In this case the parsing happens in blocking io.
 *
 * @param request The {@code HttpServletRequest}
 * @return The {@code VerificationItems}
 * @throws Exception if an exception happens during the parsing
 */
@RequestMapping(value = "/blockingio/fileupload/multipart", method = RequestMethod.POST)
public @ResponseBody VerificationItems blockingIoMultipart(final HttpServletRequest request) throws Exception {

    assertRequestIsMultipart(request);

    final ServletFileUpload servletFileUpload = new ServletFileUpload();
    final FileItemIterator fileItemIterator = servletFileUpload.getItemIterator(request);

    final VerificationItems verificationItems = new VerificationItems();
    Metadata metadata = null;
    while (fileItemIterator.hasNext()){
        FileItemStream fileItemStream = fileItemIterator.next();
        if (METADATA_FIELD_NAME.equals(fileItemStream.getFieldName())){
            if (metadata != null){
                throw new IllegalStateException("Found more than one metadata field");
            }
            metadata = unmarshalMetadata(fileItemStream.openStream());
        }else {
            VerificationItem verificationItem = buildVerificationItem(fileItemStream.openStream(), fileItemStream.getFieldName(), fileItemStream.isFormField());
            verificationItems.getVerificationItems().add(verificationItem);
        }
    }
    processVerificationItems(verificationItems, metadata, false, request.getHeader(VERIFICATION_CONTROL_HEADER_NAME));
    return verificationItems;
}
 
開發者ID:synchronoss,項目名稱:nio-multipart,代碼行數:33,代碼來源:MultipartController.java

示例3: dumpFileIterator

import org.apache.commons.fileupload.FileItemIterator; //導入方法依賴的package包/類
void dumpFileIterator(final FileItemIterator fileItemIterator){

        int partIndex = 0;

        try {
            log.info("-- COMMONS FILE UPLOAD --");
            while (fileItemIterator.hasNext()) {
                log.info("-- Part " + partIndex++);
                FileItemStream fileItemStream = fileItemIterator.next();

                FileItemHeaders fileItemHeaders = fileItemStream.getHeaders();
                Iterator<String> headerNames = fileItemHeaders.getHeaderNames();
                while(headerNames.hasNext()){
                    String headerName = headerNames.next();
                    log.info("Header: " + headerName+ ": " + Joiner.on(',').join(fileItemHeaders.getHeaders(headerName)));
                }
                log.info("Body:\n" + IOUtils.toString(fileItemStream.openStream()));
            }
            log.info("-- ------------------- --");
        }catch (Exception e){
            log.error("Error dumping the FileItemIterator", e);
        }

    }
 
開發者ID:synchronoss,項目名稱:nio-multipart,代碼行數:25,代碼來源:FunctionalTest.java

示例4: getInputStreamFromRequest

import org.apache.commons.fileupload.FileItemIterator; //導入方法依賴的package包/類
private InputStream getInputStreamFromRequest(HttpServletRequest request) {
	InputStream inputStream=null;
	DiskFileItemFactory dff = new DiskFileItemFactory();
	try {
		ServletFileUpload sfu = new ServletFileUpload(dff);
		FileItemIterator fii = sfu.getItemIterator(request);
		while (fii.hasNext()) {
			FileItemStream item = fii.next();
			// 普通參數存儲
			if (!item.isFormField()) {
				// 隻保留一個
				if (inputStream == null) {
					inputStream = item.openStream();
					return inputStream;
				}
			} 
		}
	} catch (Exception e) {
	}
	return inputStream;
}
 
開發者ID:huanzhou,項目名稱:jeecms6,代碼行數:22,代碼來源:SnapScreenServlet.java

示例5: provideHeaders

import org.apache.commons.fileupload.FileItemIterator; //導入方法依賴的package包/類
/**
 * Provides parsed email headers from the "headers" param in a multipart/form-data request.
 * <p>
 * Although SendGrid parses some headers for us, it doesn't parse "reply-to", so we need to do
 * this. Once we are doing it, it's easier to be consistent and use this as the sole source of
 * truth for information that originates in the headers.
 */
@Provides
@Singleton
InternetHeaders provideHeaders(FileItemIterator iterator) {
  try {
    while (iterator != null && iterator.hasNext()) {
      FileItemStream item = iterator.next();
      // SendGrid sends us the headers in the "headers" param.
      if (item.getFieldName().equals("headers")) {
        try (InputStream stream = item.openStream()) {
          // SendGrid always sends headers in UTF-8 encoding.
          return new InternetHeaders(new ByteArrayInputStream(
              CharStreams.toString(new InputStreamReader(stream, UTF_8.name())).getBytes(UTF_8)));
        }
      }
    }
  } catch (MessagingException | FileUploadException | IOException e) {
    // If we fail parsing the headers fall through returning the empty header object below.
  }
  return new InternetHeaders();  // Parsing failed or there was no "headers" param.
}
 
開發者ID:google,項目名稱:domaintest,代碼行數:28,代碼來源:EmailApiModule.java

示例6: parse

import org.apache.commons.fileupload.FileItemIterator; //導入方法依賴的package包/類
public void parse(MultipartRequestCallback callback) throws IOException, FileUploadException, StatusServletException {
	if (!ServletFileUpload.isMultipartContent(request)) {
		LOGGER.error("Request content is not multipart.");
		throw new StatusServletException(Response.SC_PRECONDITION_FAILED);
	}
	
	final FileItemIterator iterator = new ServletFileUpload(new DiskFileItemFactory()).getItemIterator(request);
	while (iterator.hasNext()) {
		// Gets the first HTTP request element.
		final FileItemStream item = iterator.next();

		if (item.isFormField()) {
			final String value = Streams.asString(item.openStream(), "UTF-8");
			properties.put(item.getFieldName(), value);
			
		} else if(callback != null) {
			callback.onInputStream(item.openStream(), item.getFieldName(), item.getContentType());
		}
	}
}
 
開發者ID:sigmah-dev,項目名稱:sigmah,代碼行數:21,代碼來源:MultipartRequest.java

示例7: uploadFiles

import org.apache.commons.fileupload.FileItemIterator; //導入方法依賴的package包/類
private List<FileEntry> uploadFiles(HttpServletRequest request, String spaceGuid)
    throws FileUploadException, IOException, FileStorageException, SLException {
    ServletFileUpload upload = getFileUploadServlet();
    long maxUploadSize = getConfiguration().getMaxUploadSize();
    upload.setSizeMax(maxUploadSize);

    List<FileEntry> uploadedFiles = new ArrayList<FileEntry>();
    FileItemIterator fileItemIterator = null;
    try {
        fileItemIterator = upload.getItemIterator(request);
    } catch (SizeLimitExceededException ex) {
        throw new SLException(MessageFormat.format(Messages.MAX_UPLOAD_SIZE_EXCEEDED, maxUploadSize));
    }
    while (fileItemIterator.hasNext()) {
        FileItemStream item = fileItemIterator.next();
        if (item.isFormField()) {
            continue; // ignore simple (non-file) form fields
        }

        InputStream in = null;
        try {
            in = item.openStream();
            FileEntry entry = getFileService().addFile(spaceGuid, item.getName(),
                getConfiguration().getFileUploadProcessor(), in);
            uploadedFiles.add(entry);
        } finally {
            IOUtils.closeQuietly(in);
        }
    }
    return uploadedFiles;
}
 
開發者ID:SAP,項目名稱:cf-mta-deploy-service,代碼行數:32,代碼來源:FilesApiServiceImpl.java

示例8: getRequestStream

import org.apache.commons.fileupload.FileItemIterator; //導入方法依賴的package包/類
private InputStream getRequestStream(HttpServletRequest req, String expectedFieldName)
      throws Exception {
    ServletFileUpload upload = new ServletFileUpload();
    FileItemIterator iterator = upload.getItemIterator(req);
    while (iterator.hasNext()) {
      FileItemStream item = iterator.next();
//      LOG.info(item.getContentType());
      if (item.getFieldName().equals(expectedFieldName)) {
        return item.openStream();
      }
    }
    throw new IllegalArgumentException("Field " + expectedFieldName + " not found in upload");
  }
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:14,代碼來源:GalleryServlet.java

示例9: getRequestStream

import org.apache.commons.fileupload.FileItemIterator; //導入方法依賴的package包/類
private InputStream getRequestStream(HttpServletRequest req, String expectedFieldName)
    throws Exception {
  ServletFileUpload upload = new ServletFileUpload();
  FileItemIterator iterator = upload.getItemIterator(req);
  while (iterator.hasNext()) {
    FileItemStream item = iterator.next();
    if (item.getFieldName().equals(expectedFieldName)) {
      return item.openStream();
    }
  }

  throw new IllegalArgumentException("Field " + expectedFieldName + " not found in upload");
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:14,代碼來源:UploadServlet.java

示例10: parseMultipartParameters

import org.apache.commons.fileupload.FileItemIterator; //導入方法依賴的package包/類
/**
 *
 * @param req
 * @return
 * @throws IOException
 */
private static Map<String, String[]> parseMultipartParameters(HttpServletRequest req) throws IOException {
    if (isMultipartContent(req)) {
        Map<String, String[]> multipartParameters = new HashMap();
        Map<String, List<String>> map = new HashMap();
        try {
            ServletFileUpload upload = new ServletFileUpload();
            FileItemIterator iter = upload.getItemIterator(req);
            req.setAttribute(REQ_ATT_MULTIPART_ITERATOR, iter);
            while (iter.hasNext()) {
                FileItemStream item = iter.next();
                if (!item.isFormField()) {
                    req.setAttribute(REQ_ATT_MULTIPART_CURRENT_ITEM, item);
                    break;
                }
                List<String> list = map.get(item.getFieldName());
                if (list == null) {
                    list = new ArrayList();
                    map.put(item.getFieldName(), list);
                }
                String encoding = req.getCharacterEncoding();
                if (encoding == null) {
                    encoding = "UTF-8";
                }
                list.add(Miscellaneous.toString(item.openStream(), encoding));
            }
        } catch (FileUploadException ex) {
            throw new RuntimeException(ex);
        }
        for (Map.Entry<String, List<String>> entrySet : map.entrySet()) {
            String key = entrySet.getKey();
            List<String> value = entrySet.getValue();
            multipartParameters.put(key, value.toArray(new String[value.size()]));
        }
        return multipartParameters;
    }
    return null;
}
 
開發者ID:brutusin,項目名稱:Brutusin-RPC,代碼行數:44,代碼來源:RpcServlet.java

示例11: handleMultipart

import org.apache.commons.fileupload.FileItemIterator; //導入方法依賴的package包/類
private String handleMultipart(RecordedRequest request) {
    RecordedUpload upload = new RecordedUpload(request);
    Exception exception;
    try {
        Map<String,String> params = new HashMap<>();
        FileItemIterator iter = upload.getItemIterator();
        while (iter.hasNext()) {
            FileItemStream item = iter.next();
            String name = item.getFieldName();
            InputStream stream = item.openStream();
            if (item.isFormField()) {
                String value = Streams.asString(stream);
                System.out.println("Form field " + name + " with value "
                        + value + " detected.");
                params.put(name,value);
            } else {
                System.out.println("File field " + name + " with file name "
                        + item.getName() + " detected.");
                params.put(name, "file->"+item.getName());
            }
        }
        return "Multipart:"+JSON.toJSONString(params);
    } catch (Exception e) {
        exception = e;
    }
    return "Multipart:error->"+exception;
}
 
開發者ID:alexclin0188,項目名稱:httplite,代碼行數:28,代碼來源:MiscHandle.java

示例12: getFileItem

import org.apache.commons.fileupload.FileItemIterator; //導入方法依賴的package包/類
private void getFileItem(HttpServletRequest request) throws FileUploadException, IOException {
	boolean isMultipart = ServletFileUpload.isMultipartContent(request);
	
	if (!isMultipart) {
		throw new IllegalArgumentException("Not multipart...");
	}
	
	
		ServletFileUpload upload = new ServletFileUpload();
		
		List<String> mdrEntries = new ArrayList<String>();
		
		// Parse the request
		FileItemIterator iter = upload.getItemIterator(request);
		while (iter.hasNext()) {
			FileItemStream item = iter.next();
			
			String name = item.getFieldName();
			InputStream stream = item.openStream();
			if (item.isFormField()) {
				System.out.println("Form field " + name + " with value "
						+ Streams.asString(stream) + " detected.");
			} else {
				System.out.println("File field " + name + " with file name "
						+ item.getName() + " detected.");
				// Process the input stream
			}
			String mdrEntry = handleInput(name, stream);
			mdrEntries.add(mdrEntry);
		}
		commitContent(mdrEntries);
}
 
開發者ID:luox12,項目名稱:onecmdb,代碼行數:33,代碼來源:ChangeUploadCommand.java

示例13: doPost

import org.apache.commons.fileupload.FileItemIterator; //導入方法依賴的package包/類
protected void doPost(HttpServletRequest req, HttpServletResponse res)
		throws ServletException, IOException {
	long gameId = 0l;
	String auth = null;
	try {
		ServletFileUpload upload = new ServletFileUpload();
		FileItemIterator iter = upload.getItemIterator(req);

		String json = "";
		while (iter.hasNext()) {
			FileItemStream item = iter.next();
			String name = item.getFieldName();
			InputStream stream = item.openStream();
			if (item.isFormField()) {
				String value = Streams.asString(stream);
				if ("gameId".equals(name)) gameId = Long.parseLong(value);
				if ("auth".equals(name)) auth = value;
				
			} else {
				json = Streams.asString(stream);

			}
		}

		res.setContentType("text/plain");
		JSONObject jObject = new JSONObject(json);
		Object deserialized = JsonBeanDeserializer.deserialize(json);
		
		if (deserialized instanceof GamePackage && ((GamePackage) deserialized).getGame() != null)
			unpackGame((GamePackage) deserialized, req, auth);
		if (deserialized instanceof RunPackage && ((RunPackage) deserialized ).getRun() != null)
			unpackRun((RunPackage) deserialized, req, gameId, auth);

	} catch (Exception ex) {
		throw new ServletException(ex);
	}
}
 
開發者ID:WELTEN,項目名稱:dojo-ibl,代碼行數:38,代碼來源:UploadGameServlet.java

示例14: provideParameterMap

import org.apache.commons.fileupload.FileItemIterator; //導入方法依賴的package包/類
@Provides
@Singleton
Multimap<String, String> provideParameterMap(
    @RequestData("queryString") String queryString,
    @RequestData("postBody") Lazy<String> lazyPostBody,
    @RequestData("charset") String requestCharset,
    FileItemIterator multipartIterator) {
  // Calling request.getParameter() or request.getParameterMap() etc. consumes the POST body. If
  // we got the "postpayload" param we don't want to parse the body, so use only the query params.
  // Note that specifying both "payload" and "postpayload" will result in the "payload" param
  // being honored and the POST body being completely ignored.
  ImmutableMultimap.Builder<String, String> params = new ImmutableMultimap.Builder<>();
  Multimap<String, String> getParams = parseQuery(queryString);
  params.putAll(getParams);
  if (getParams.containsKey("postpayload")) {
    // Treat the POST body as if it was the "payload" param.
    return params.put("payload", nullToEmpty(lazyPostBody.get())).build();
  }
  // No "postpayload" so it's safe to consume the POST body and look for params there.
  if (multipartIterator == null) {  // Handle GETs and form-urlencoded POST requests.
    params.putAll(parseQuery(nullToEmpty(lazyPostBody.get())));
  } else {  // Handle multipart/form-data requests.
    try {
      while (multipartIterator != null && multipartIterator.hasNext()) {
        FileItemStream item = multipartIterator.next();
        try (InputStream stream = item.openStream()) {
          params.put(
              item.isFormField() ? item.getFieldName() : item.getName(),
              CharStreams.toString(new InputStreamReader(stream, requestCharset)));
        }
      }
    } catch (FileUploadException | IOException e) {
      // Ignore the failure and fall through to return whatever params we managed to parse.
    }
  }
  return params.build();
}
 
開發者ID:google,項目名稱:domaintest,代碼行數:38,代碼來源:HttpApiModule.java

示例15: Upload

import org.apache.commons.fileupload.FileItemIterator; //導入方法依賴的package包/類
private Upload(final HttpServletRequest request) {
    this.upload = new ServletFileUpload();
    this.request = request;

    super.setStreamProvider(new InputStreamProvider() {

        @Override
        public InputStream getStream(String path) throws IOException {
            try {
                FileItemIterator iter = upload.getItemIterator(request);
                while (iter.hasNext()) {
                    FileItemStream stm = iter.next();
                    if (stm.getFieldName().equals(path)) {
                        return stm.openStream();
                    }
                }
            } catch (Exception e) {
                throw new IOException(e);
            }
            throw new IOException(path + " does not exists");
        }

        @Override
        public String getRealPath(String p) {
            throw new UnsupportedOperationException();
        }
    });

}
 
開發者ID:xkommando,項目名稱:Gplume,代碼行數:30,代碼來源:Upload.java


注:本文中的org.apache.commons.fileupload.FileItemIterator.hasNext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。