當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。