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


Java MultipartStream.readBodyData方法代码示例

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


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

示例1: writeConfigFile

import org.apache.commons.fileupload.MultipartStream; //导入方法依赖的package包/类
private String writeConfigFile (InputStream inputStream, String b) throws IOException {
    byte[] boundary = b.getBytes();
    @SuppressWarnings("deprecation")
    MultipartStream multipartStream = new MultipartStream(inputStream, boundary);
    File tempDir = new File(STORAGE_DIR_PATH);
    if (!tempDir.exists()) {
        tempDir.mkdir();
    }
    File file = File.createTempFile(CONFIG_FILE_PREFIX, ".xml", tempDir);
    FileOutputStream out = new FileOutputStream(file.getAbsolutePath());
    boolean nextPart = multipartStream.skipPreamble();
    if (nextPart) {
        multipartStream.readHeaders();
        multipartStream.readBodyData(out);
    }
    out.close();
    String id = file.getName();
    return id.substring(id.indexOf(CONFIG_FILE_PREFIX) + CONFIG_FILE_PREFIX.length(), id.lastIndexOf(".xml"));
}
 
开发者ID:dice-group,项目名称:LIMES,代码行数:20,代码来源:SimpleServer.java

示例2: readMultiPart

import org.apache.commons.fileupload.MultipartStream; //导入方法依赖的package包/类
private ByteArrayMultipartFile readMultiPart (MultipartStream multipartStream) throws IOException {
  val multiPartHeaders = splitIntoKeyValuePairs(
      multipartStream.readHeaders(),
      NEWLINES_PATTERN,
      COLON_PATTERN,
      false
  );

  val contentDisposition = splitIntoKeyValuePairs(
      multiPartHeaders.get(CONTENT_DISPOSITION),
      SEMICOLON_PATTERN,
      EQUALITY_SIGN_PATTERN,
      true
  );

  if (!contentDisposition.containsKey("form-data")) {
    throw new HttpMessageNotReadableException("Content-Disposition is not of type form-data.");
  }

  val bodyStream = new ByteArrayOutputStream();
  multipartStream.readBodyData(bodyStream);
  return new ByteArrayMultipartFile(
      contentDisposition.get("name"),
      contentDisposition.get("filename"),
      multiPartHeaders.get(CONTENT_TYPE),
      bodyStream.toByteArray()
  );
}
 
开发者ID:OpenFeign,项目名称:feign-form,代码行数:29,代码来源:SpringManyMultipartFilesReader.java

示例3: getPartData

import org.apache.commons.fileupload.MultipartStream; //导入方法依赖的package包/类
private static Struct getPartData(MultipartStream stream) throws IOException, PageException {
	Struct headers = extractHeaders(stream.readHeaders());
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	stream.readBodyData(baos);
	Struct fileStruct = new StructImpl();
	fileStruct.set(KeyConstants._content, baos.toByteArray());
	fileStruct.set(KeyConstants._headers, headers);
	IOUtil.closeEL(baos);
	return fileStruct;
}
 
开发者ID:lucee,项目名称:Lucee4,代码行数:11,代码来源:MultiPartResponseUtils.java

示例4: processMultiPartFile

import org.apache.commons.fileupload.MultipartStream; //导入方法依赖的package包/类
public static byte[] processMultiPartFile(HttpServletRequest httpServletRequest, String contentMessage) throws
        IOException {
    //Content-Type: multipart/form-data; boundary="----=_Part_2_1843361794.1448198281814"

    String encoding = httpServletRequest.getCharacterEncoding();

    if (encoding == null) {
        encoding = DEFAULT_ENCODING;
        httpServletRequest.setCharacterEncoding(encoding);
    }

    byte[] requestBodyArray = IOUtils.toByteArray(httpServletRequest.getInputStream());
    if (requestBodyArray == null || requestBodyArray.length == 0) {
        throw new ActivitiIllegalArgumentException("No :" + contentMessage + "was found in request body.");
    }

    String requestContentType = httpServletRequest.getContentType();

    StringBuilder contentTypeString = new StringBuilder();
    contentTypeString.append("Content-Type: " + requestContentType);
    contentTypeString.append("\r");
    contentTypeString.append(System.getProperty("line.separator"));

    byte[] contentTypeArray = contentTypeString.toString().getBytes(encoding);

    byte[] aggregatedRequestBodyByteArray = new byte[contentTypeArray.length + requestBodyArray.length];

    System.arraycopy(contentTypeArray, 0, aggregatedRequestBodyByteArray, 0, contentTypeArray.length);
    System.arraycopy(requestBodyArray, 0, aggregatedRequestBodyByteArray, contentTypeArray
            .length, requestBodyArray.length);

    boolean debugEnabled = log.isDebugEnabled();


    int index = requestContentType.indexOf("boundary");

    if (index <= 0) {
        throw new ActivitiIllegalArgumentException("boundary tag not found in the request header.");
    }
    String boundaryString = requestContentType.substring(index + "boundary=".length());
    boundaryString = boundaryString.replaceAll("\"", "").trim();

    if (debugEnabled) {
        log.debug("----------Content-Type:-----------\n" + httpServletRequest.getContentType());
        log.debug("\n\n\n\n");
        log.debug("\n\n\n\n----------Aggregated Request Body:-----------\n" + new String(aggregatedRequestBodyByteArray));
        log.debug("boundaryString:" + boundaryString);
    }

    byte[] boundary = boundaryString.getBytes(encoding);
    ByteArrayInputStream content = new ByteArrayInputStream(aggregatedRequestBodyByteArray);
    MultipartStream multipartStream = new MultipartStream(content, boundary, aggregatedRequestBodyByteArray.length,
            null);

    boolean nextPart = multipartStream.skipPreamble();
    if (debugEnabled) {
        log.debug(nextPart);
    }
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    byte[] byteArray = null;
    // Get first file in the map, ignore possible other files
    while (nextPart) {
        //
        if (debugEnabled) {

            String header = multipartStream.readHeaders();
            printHeaders(header);
        }


        multipartStream.readBodyData(byteArrayOutputStream);
        byteArray = byteArrayOutputStream.toByteArray();

        nextPart = multipartStream.readBoundary();
    }

    return byteArray;
}
 
开发者ID:wso2,项目名称:carbon-business-process,代码行数:79,代码来源:Utils.java


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