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


Java FileItemStream类代码示例

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


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

示例1: read

import org.apache.commons.fileupload.FileItemStream; //导入依赖的package包/类
/**
 * Returns the next byte in the stream.
 *
 * @return The next byte in the stream, as a non-negative
 * integer, or -1 for EOF.
 * @throws IOException An I/O error occurred.
 */
@Override
public int read() throws IOException {
    if (closed) {
        throw new FileItemStream.ItemSkippedException();
    }
    if (available() == 0 && makeAvailable() == 0) {
        return -1;
    }
    ++total;
    int b = buffer[head++];
    if (b >= 0) {
        return b;
    }
    return b + BYTE_POSITIVE_OFFSET;
}
 
开发者ID:dueros,项目名称:dcs-sdk-java,代码行数:23,代码来源:MultipartStreamCopy.java

示例2: skip

import org.apache.commons.fileupload.FileItemStream; //导入依赖的package包/类
/**
 * Skips the given number of bytes.
 *
 * @param bytes Number of bytes to skip.
 * @return The number of bytes, which have actually been
 * skipped.
 * @throws IOException An I/O error occurred.
 */
@Override
public long skip(long bytes) throws IOException {
    if (closed) {
        throw new FileItemStream.ItemSkippedException();
    }
    int av = available();
    if (av == 0) {
        av = makeAvailable();
        if (av == 0) {
            return 0;
        }
    }
    long res = Math.min(av, bytes);
    head += res;
    return res;
}
 
开发者ID:dueros,项目名称:dcs-sdk-java,代码行数:25,代码来源:MultipartStreamCopy.java

示例3: processFileItemStreamAsFormField

import org.apache.commons.fileupload.FileItemStream; //导入依赖的package包/类
/**
 * Processes the FileItemStream as a Form Field.
 *
 * @param itemStream file item stream
 */
private void processFileItemStreamAsFormField(FileItemStream itemStream) {
    String fieldName = itemStream.getFieldName();
    try {
        List<String> values;
        String fieldValue = Streams.asString(itemStream.openStream());
        if (!parameters.containsKey(fieldName)) {
            values = new ArrayList<>();
            parameters.put(fieldName, values);
        } else {
            values = parameters.get(fieldName);
        }
        values.add(fieldValue);
    } catch (IOException e) {
        LOG.warn("Failed to handle form field '{}'.", fieldName, e);
    }
}
 
开发者ID:txazo,项目名称:struts2,代码行数:22,代码来源:JakartaStreamMultiPartRequest.java

示例4: processFileItemStreamAsFileField

import org.apache.commons.fileupload.FileItemStream; //导入依赖的package包/类
/**
 * Processes the FileItemStream as a file field.
 *
 * @param itemStream file item stream
 * @param location location
 */
private void processFileItemStreamAsFileField(FileItemStream itemStream, String location) {
    // Skip file uploads that don't have a file name - meaning that no file was selected.
    if (itemStream.getName() == null || itemStream.getName().trim().length() < 1) {
        LOG.debug("No file has been uploaded for the field: {}", itemStream.getFieldName());
        return;
    }

    File file = null;
    try {
        // Create the temporary upload file.
        file = createTemporaryFile(itemStream.getName(), location);

        if (streamFileToDisk(itemStream, file)) {
            createFileInfoFromItemStream(itemStream, file);
        }
    } catch (IOException e) {
        if (file != null) {
            try {
                file.delete();
            } catch (SecurityException se) {
                LOG.warn("Failed to delete '{}' due to security exception above.", file.getName(), se);
            }
        }
    }
}
 
开发者ID:txazo,项目名称:struts2,代码行数:32,代码来源:JakartaStreamMultiPartRequest.java

示例5: createFileInfoFromItemStream

import org.apache.commons.fileupload.FileItemStream; //导入依赖的package包/类
/**
 * Creates an internal <code>FileInfo</code> structure used to pass information
 * to the <code>FileUploadInterceptor</code> during the interceptor stack
 * invocation process.
 *
 * @param itemStream file item stream
 * @param file the file
 */
private void createFileInfoFromItemStream(FileItemStream itemStream, File file) {
    // gather attributes from file upload stream.
    String fileName = itemStream.getName();
    String fieldName = itemStream.getFieldName();
    // create internal structure
    FileInfo fileInfo = new FileInfo(file, itemStream.getContentType(), fileName);
    // append or create new entry.
    if (!fileInfos.containsKey(fieldName)) {
        List<FileInfo> infos = new ArrayList<>();
        infos.add(fileInfo);
        fileInfos.put(fieldName, infos);
    } else {
        fileInfos.get(fieldName).add(fileInfo);
    }
}
 
开发者ID:txazo,项目名称:struts2,代码行数:24,代码来源:JakartaStreamMultiPartRequest.java

示例6: 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

示例7: blockingIoMultipart

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

示例8: dumpFileIterator

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

示例9: uploadFile

import org.apache.commons.fileupload.FileItemStream; //导入依赖的package包/类
/**
 * Uploads a file to Google Cloud Storage to the bucket specified in the BUCKET_NAME
 * environment variable, appending a timestamp to end of the uploaded filename.
 */
public String uploadFile(FileItemStream fileStream, final String bucketName)
    throws IOException, ServletException {
  checkFileExtension(fileStream.getName());

  DateTimeFormatter dtf = DateTimeFormat.forPattern("-YYYY-MM-dd-HHmmssSSS");
  DateTime dt = DateTime.now(DateTimeZone.UTC);
  String dtString = dt.toString(dtf);
  final String fileName = fileStream.getName() + dtString;

  // the inputstream is closed by default, so we don't need to close it here
  @SuppressWarnings("deprecation")
  BlobInfo blobInfo =
      storage.create(
          BlobInfo
              .newBuilder(bucketName, fileName)
              // Modify access list to allow all users with link to read file
              .setAcl(new ArrayList<>(Arrays.asList(Acl.of(User.ofAllUsers(), Role.READER))))
              .build(),
          fileStream.openStream());
  logger.log(Level.INFO, "Uploaded file {0} as {1}", new Object[]{
      fileStream.getName(), fileName});
  // return the public download link
  return blobInfo.getMediaLink();
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:29,代码来源:CloudStorageHelper.java

示例10: uploadFile

import org.apache.commons.fileupload.FileItemStream; //导入依赖的package包/类
/**
 * Uploads a file to Google Cloud Storage to the bucket specified in the BUCKET_NAME
 * environment variable, appending a timestamp to end of the uploaded filename.
 */
@SuppressWarnings("deprecation")
public String uploadFile(FileItemStream fileStream, final String bucketName)
    throws IOException, ServletException {
  checkFileExtension(fileStream.getName());

  DateTimeFormatter dtf = DateTimeFormat.forPattern("-YYYY-MM-dd-HHmmssSSS");
  DateTime dt = DateTime.now(DateTimeZone.UTC);
  String dtString = dt.toString(dtf);
  final String fileName = fileStream.getName() + dtString;

  // the inputstream is closed by default, so we don't need to close it here
  BlobInfo blobInfo =
      storage.create(
          BlobInfo
              .newBuilder(bucketName, fileName)
              // Modify access list to allow all users with link to read file
              .setAcl(new ArrayList<>(Arrays.asList(Acl.of(User.ofAllUsers(), Role.READER))))
              .build(),
          fileStream.openStream());
  // return the public download link
  return blobInfo.getMediaLink();
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:27,代码来源:CloudStorageHelper.java

示例11: uploadFile

import org.apache.commons.fileupload.FileItemStream; //导入依赖的package包/类
/**
 * Uploads a file to Google Cloud Storage to the bucket specified in the BUCKET_NAME
 * environment variable, appending a timestamp to end of the uploaded filename.
 */
public String uploadFile(FileItemStream fileStream, final String bucketName)
    throws IOException, ServletException {
  checkFileExtension(fileStream.getName());

  DateTimeFormatter dtf = DateTimeFormat.forPattern("-YYYY-MM-dd-HHmmssSSS");
  DateTime dt = DateTime.now(DateTimeZone.UTC);
  String dtString = dt.toString(dtf);
  final String fileName = fileStream.getName() + dtString;

  // the inputstream is closed by default, so we don't need to close it here
  @SuppressWarnings("deprecation")
  BlobInfo blobInfo =
      storage.create(
          BlobInfo
              .newBuilder(bucketName, fileName)
              // Modify access list to allow all users with link to read file
              .setAcl(new ArrayList<>(Arrays.asList(Acl.of(User.ofAllUsers(), Role.READER))))
              .build(),
          fileStream.openStream());
  // return the public download link
  return blobInfo.getMediaLink();
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:27,代码来源:CloudStorageHelper.java

示例12: 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

示例13: 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

示例14: 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

示例15: 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()));
	}
}
 
开发者ID:mendix,项目名称:RestServices,代码行数:21,代码来源:MicroflowService.java


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