当前位置: 首页>>代码示例>>Java>>正文


Java FileItemStream.openStream方法代码示例

本文整理汇总了Java中org.apache.commons.fileupload.FileItemStream.openStream方法的典型用法代码示例。如果您正苦于以下问题:Java FileItemStream.openStream方法的具体用法?Java FileItemStream.openStream怎么用?Java FileItemStream.openStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.fileupload.FileItemStream的用法示例。


在下文中一共展示了FileItemStream.openStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRequestData

import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的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: 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;
}
 
开发者ID:huanzhou,项目名称:jeecms6,代码行数:22,代码来源:SnapScreenServlet.java

示例3: createZipFile

import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的package包/类
private ZipFile createZipFile(FileItemStream item) {
	ZipFile zipFile = null;
	try {
		File f = new File("zipFile");
		InputStream inputStream = item.openStream();
		OutputStream outputStream = new FileOutputStream(f);
		int len;
		byte[] buffer = new byte[1000000];
		while ((len = inputStream.read(buffer, 0, buffer.length)) != -1) {
			outputStream.write(buffer, 0, len);
		}
		outputStream.close();
		inputStream.close();

		zipFile = new ZipFile(f);

	} catch (Exception e) {
		LOG.error(e.getMessage());
	}

	return zipFile;
}
 
开发者ID:geowe,项目名称:geowe-core,代码行数:23,代码来源:FileUploadZipServlet.java

示例4: execute

import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的package包/类
@Override
protected void execute(ElfinderStorage elfinderStorage, HttpServletRequest request, JSONObject json) throws Exception {

    List<FileItemStream> files = (List<FileItemStream>) request.getAttribute(FileItemStream.class.getName());
    List<VolumeHandler> added = new ArrayList<>();

    String target = request.getParameter(ElFinderConstants.ELFINDER_PARAMETER_TARGET);
    VolumeHandler parentDir = findTarget(elfinderStorage, target);

    for (FileItemStream file : files) {
        String fileName = file.getName();
        VolumeHandler newFile = new VolumeHandler(parentDir, fileName);
        newFile.createFile();
        InputStream is = file.openStream();
        OutputStream os = newFile.openOutputStream();

        IOUtils.copy(is, os);
        os.close();
        is.close();

        added.add(newFile);
    }

    json.put(ElFinderConstants.ELFINDER_JSON_RESPONSE_ADDED, buildJsonFilesArray(request, added));
}
 
开发者ID:trustsystems,项目名称:elfinder-java-connector,代码行数:26,代码来源:UploadCommand.java

示例5: _store

import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的package包/类
private ISObject _store(FileItemStream fileItemStream) throws IOException {
    String filename = fileItemStream.getName();
    String key = newKey(filename);
    File tmpFile = getFile(key);
    InputStream input = fileItemStream.openStream();
    ThresholdingByteArrayOutputStream output = new ThresholdingByteArrayOutputStream(inMemoryCacheThreshold, tmpFile);
    IO.copy(input, output);

    ISObject retVal;
    if (output.exceedThreshold) {
        retVal = getFull(key);
    } else {
        int size = output.written;
        byte[] buf = output.buf();
        retVal = SObject.of(key, buf, size);
    }

    if (S.notBlank(filename)) {
        retVal.setFilename(filename);
    }
    String contentType = fileItemStream.getContentType();
    if (null != contentType) {
        retVal.setContentType(contentType);
    }
    return retVal;
}
 
开发者ID:actframework,项目名称:actframework,代码行数:27,代码来源:UploadFileStorageService.java

示例6: provideHeaders

import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的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

示例7: addItemProxy

import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的package包/类
public void addItemProxy(final FileItemStream item) throws IOException
{
	InputStream stream = item.openStream();
	ByteArrayOutputStream os = new ByteArrayOutputStream();
	IOUtils.copy(stream, os);
	final byte[] bs = os.toByteArray();
	stream.close();

	addItem((FileItemStream) Proxy.newProxyInstance(this.getClass()
			.getClassLoader(), new Class[] { FileItemStream.class },
			new InvocationHandler()
			{
				@Override
				public Object invoke(Object proxy, Method method,
						Object[] args) throws Throwable
				{
					if ("openStream".equals(method.getName()))
					{
						return new ByteArrayInputStream(bs);
					}

					return method.invoke(item, args);
				}
			}));
}
 
开发者ID:bluejoe2008,项目名称:elfinder-2.x-servlet,代码行数:26,代码来源:MultipleUploadItems.java

示例8: 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;
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:32,代码来源:FilesApiServiceImpl.java

示例9: getRequestStream

import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的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

示例10: getRequestStream

import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的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

示例11: streamFileToDisk

import org.apache.commons.fileupload.FileItemStream; //导入方法依赖的package包/类
/**
 * Streams the file upload stream to the specified file.
 *
 * @param itemStream file item stream
 * @param file the file
 * @return true if stream was successfully
 * @throws IOException in case of IO errors
 */
private boolean streamFileToDisk(FileItemStream itemStream, File file) throws IOException {
    boolean result = false;
    try (InputStream input = itemStream.openStream();
            OutputStream output = new BufferedOutputStream(new FileOutputStream(file), bufferSize)) {
        byte[] buffer = new byte[bufferSize];
        LOG.debug("Streaming file using buffer size {}.", bufferSize);
        for (int length = 0; ((length = input.read(buffer)) > 0); ) {
            output.write(buffer, 0, length);
        }
        result = true;
    }
    return result;
}
 
开发者ID:txazo,项目名称:struts2,代码行数:22,代码来源:JakartaStreamMultiPartRequest.java

示例12: 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;
}
 
开发者ID:alexclin0188,项目名称:httplite,代码行数:28,代码来源:MiscHandle.java

示例13: 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;
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:42,代码来源:MultipartUploadReader.java

示例14: 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;
  }
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:39,代码来源:UploadWorkItem.java

示例15: 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);
}
 
开发者ID:luox12,项目名称:onecmdb,代码行数:33,代码来源:ChangeUploadCommand.java


注:本文中的org.apache.commons.fileupload.FileItemStream.openStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。