本文整理汇总了Java中org.apache.commons.fileupload.FileItemStream.isFormField方法的典型用法代码示例。如果您正苦于以下问题:Java FileItemStream.isFormField方法的具体用法?Java FileItemStream.isFormField怎么用?Java FileItemStream.isFormField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.fileupload.FileItemStream
的用法示例。
在下文中一共展示了FileItemStream.isFormField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInputStreamFromRequest
import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的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;
}
示例2: parseMultipartData
import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的package包/类
private void parseMultipartData(RestServiceRequest rsr, IMendixObject argO,
JSONObject data) throws IOException, FileUploadException {
boolean hasFile = false;
for(FileItemIterator iter = servletFileUpload.getItemIterator(rsr.request); iter.hasNext();) {
FileItemStream item = iter.next();
if (!item.isFormField()){ //This is the file(?!)
if (!isFileSource) {
RestServices.LOGPUBLISH.warn("Received request with binary data but input argument isn't a filedocument. Skipping. At: " + rsr.request.getRequestURL().toString());
continue;
}
if (hasFile)
RestServices.LOGPUBLISH.warn("Received request with multiple files. Only one is supported. At: " + rsr.request.getRequestURL().toString());
hasFile = true;
Core.storeFileDocumentContent(rsr.getContext(), argO, determineFileName(item), item.openStream());
}
else
data.put(item.getFieldName(), IOUtils.toString(item.openStream()));
}
}
示例3: parse
import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的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());
}
}
}
示例4: uploadFiles
import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的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;
}
示例5: parseMultipartParameters
import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的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;
}
示例6: handleMultipart
import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的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;
}
示例7: readFormData
import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的package包/类
/**
* Reads form values from the multipart request until a file is encountered. Field values are stored as strings for
* retrieval using {@link #getFormFieldValue}.
* @return True if there is an upload file available to read via {@link #getUploadFileItem()}.
*/
public boolean readFormData() {
mUploadFileItem = null;
try {
while (mItemIterator.hasNext()) {
FileItemStream lCurrentItem = mItemIterator.next();
/**
* NOTE: the InputStream here is read here in a blocking way. Long upload hangs have been observed on live
* environments at this point due to network issues. It should be possible to convert the stream to a
* non-blocking stream at this point if required.
*/
InputStream lItemInputStream = lCurrentItem.openStream();
if (lCurrentItem.isFormField()) {
//Read form values into the map
String lParamName = lCurrentItem.getFieldName();
String lFieldValue = Streams.asString(lItemInputStream);
mFieldParamMap.put(lParamName, lFieldValue);
}
else {
//We've hit the file field, so stop the read for now
mUploadFileItem = lCurrentItem;
break;
}
lItemInputStream.close();
}
}
catch (IOException | FileUploadException e) {
throw new ExInternal("Failed to read form data for the multipart request", e);
}
return mUploadFileItem != null;
}
示例8: initialiseUpload
import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的package包/类
private void initialiseUpload()
throws Throwable {
try {
FileItemStream lCurrentItem = mMultipartUploadReader.getUploadFileItem();
if(lCurrentItem == null) {
throw new ExInternal("No file available on the multipart upload reader - either reader is in an invalid state, or the upload contained no file field");
}
mItemInputStream = lCurrentItem.openStream();
if (lCurrentItem.isFormField()) {
//Skip form fields, they should have been read by the MultipartUploadReader
Track.alert("UploadWorkItem", "Unexpected form field encountered when streaming upload");
}
else {
mItemNonBlockingInputStream = new NonBlockingInputStream(mItemInputStream, BYTE_READ_QUANTITY, MAX_SUBSEQUENT_BUFFER_READS);
String lFilename = lCurrentItem.getName();
mUploadInfo.setOriginalFileLocation(lFilename);
int lBeginningIndex = lFilename.lastIndexOf("\\");
if ( lFilename != null && lBeginningIndex != -1 ) {
// substr from that last occurrence of a back slash
lFilename = lFilename.substring(lBeginningIndex + 1);
}
mUploadInfo.setFilename(lFilename);
String lContentType = lCurrentItem.getContentType();
mUploadInfo.setBrowserContentType(lContentType != null ? lContentType : "" );
mStatus = READING_FILE_DATA;
mLastReadTime = System.currentTimeMillis();
}
}
catch (Throwable ex1) {
throw ex1;
}
}
示例9: getFileItem
import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的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);
}
示例10: doPost
import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的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);
}
}
示例11: doPost
import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的package包/类
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException {
try {
ServletFileUpload upload = new ServletFileUpload();
res.setContentType("text/html");
res.setCharacterEncoding("UTF-8");
FileItemIterator iterator = upload.getItemIterator(req);
while (iterator.hasNext()) {
FileItemStream item = iterator.next();
InputStream stream = item.openStream();
if (item.isFormField()) {
log.warning("Got a form field: " + item.getFieldName());
} else {
log.warning("Got an uploaded file: " + item.getFieldName()+ ", name = " + item.getName());
// You now have the filename (item.getName() and the
// contents (which you can read from stream). Here we just
// print them back out to the servlet output stream, but you
// will probably want to do something more interesting (for
// example, wrap them in a Blob and commit them to the
// datastore).
/* int len;
byte[] buffer = new byte[8192];
while ((len = stream.read(buffer, 0, buffer.length)) != -1) {
res.getOutputStream().write(buffer, 0, len);
}*/
String content = IOUtils.toString(stream, "UTF-8");
tbx2rdfServlet.formatOutput(res,content);
}
}
} catch (Exception ex) {
//throw new ServletException(ex);
}
}
示例12: uploadMultipart
import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的package包/类
private void uploadMultipart(HttpServletRequest req, HttpServletResponse resp,
OutputStream repoItemOutputStrem) throws IOException {
log.debug("Multipart detected");
ServletFileUpload upload = new ServletFileUpload();
try {
// Parse the request
FileItemIterator iter = upload.getItemIterator(req);
while (iter.hasNext()) {
FileItemStream item = iter.next();
String name = item.getFieldName();
try (InputStream stream = item.openStream()) {
if (item.isFormField()) {
// TODO What to do with this?
log.debug("Form field {} with value {} detected.", name, Streams.asString(stream));
} else {
// TODO Must we support multiple files uploading?
log.debug("File field {} with file name detected.", name, item.getName());
log.debug("Start to receive bytes (estimated bytes)",
Integer.toString(req.getContentLength()));
int bytes = IOUtils.copy(stream, repoItemOutputStrem);
resp.setStatus(SC_OK);
log.debug("Bytes received: {}", Integer.toString(bytes));
}
}
}
} catch (FileUploadException e) {
throw new IOException(e);
}
}
示例13: asMultipartRequest
import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的package包/类
private static MultipartRequest asMultipartRequest(HttpServletRequest request) throws Exception {
String encoding = request.getCharacterEncoding();
MultipartRequest req = new MultipartRequest(request);
ServletFileUpload upload = new ServletFileUpload();
upload.setHeaderEncoding(encoding);
FileItemIterator it = upload.getItemIterator(request);
while (it.hasNext()) {
FileItemStream item = it.next();
String fieldName = item.getFieldName();
InputStream stream = item.openStream();
try {
if (item.isFormField()) {
req.setParameter(fieldName, Streams.asString(stream, encoding));
} else {
String originalFilename = item.getName();
File diskFile = getTempFile(originalFilename);
OutputStream fos = new FileOutputStream(diskFile);
try {
IoUtils.copy(stream, fos);
} finally {
IoUtils.closeQuietly(fos);
}
FilePart filePart = new FilePart(fieldName, originalFilename, diskFile);
req.addFile(filePart);
}
} finally {
IoUtils.closeQuietly(stream);
}
}
return req;
}
示例14: valueOf
import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的package包/类
private Object valueOf(FileItemStream itemStream) throws IOException {
if (itemStream.isFormField()) {
final String charset = charset(itemStream.getContentType());
return IoUtils.readIntoString(new InputStreamReader(itemStream.openStream(), charset));
}
return new FileValue();
}
示例15: internalImport
import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的package包/类
protected void internalImport(
HttpServletRequest request,
Properties options,
long projectID
) throws Exception {
String url = null;
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iter = upload.getItemIterator(request);
while (iter.hasNext()) {
FileItemStream item = iter.next();
String name = item.getFieldName().toLowerCase();
InputStream stream = item.openStream();
if (item.isFormField()) {
if (name.equals("url")) {
url = Streams.asString(stream);
} else {
options.put(name, Streams.asString(stream));
}
} else {
String fileName = item.getName().toLowerCase();
try {
ProjectManager.getSingleton().importProject(projectID, stream, !fileName.endsWith(".tar"));
} finally {
stream.close();
}
}
}
if (url != null && url.length() > 0) {
internalImportURL(request, options, projectID, url);
}
}