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


Java MultipartStream类代码示例

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


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

示例1: readInternal

import org.apache.commons.fileupload.MultipartStream; //导入依赖的package包/类
@Override
protected MultipartFile[] readInternal (Class<? extends MultipartFile[]> clazz, HttpInputMessage inputMessage
) throws IOException {
  val boundaryBytes = getMultiPartBoundary(inputMessage.getHeaders().getContentType());
  MultipartStream multipartStream = new MultipartStream(inputMessage.getBody(), boundaryBytes, bufSize, null);

  val multiparts = new LinkedList<ByteArrayMultipartFile>();
  for (boolean nextPart = multipartStream.skipPreamble(); nextPart; nextPart = multipartStream.readBoundary()) {
    ByteArrayMultipartFile multiPart;
    try {
      multiPart = readMultiPart(multipartStream);
    } catch (Exception e) {
      throw new HttpMessageNotReadableException("Multipart body could not be read.", e);
    }
    multiparts.add(multiPart);
  }
  return multiparts.toArray(new ByteArrayMultipartFile[multiparts.size()]);
}
 
开发者ID:OpenFeign,项目名称:feign-form,代码行数:19,代码来源:SpringManyMultipartFilesReader.java

示例2: finaliseOnError

import org.apache.commons.fileupload.MultipartStream; //导入依赖的package包/类
public void finaliseOnError(Throwable pEx) {
  mStatus = FAILED;
  mErrorException = pEx;
  if (mUploadInfo != null) {
    if(mUploadInfo.getStatus().isInProgress() || mUploadInfo.getStatus() == UploadStatus.NOT_STARTED) {
      mUploadInfo.setStatus(UploadStatus.FAILED);
    }
    mUploadInfo.setSystemMsg(XFUtil.getJavaStackTraceInfo(pEx));
  }

  if(mItemInputStream != null && mItemInputStream instanceof MultipartStream.ItemInputStream) {
    //Forcibly close the underlying input stream for the file upload
    //This prevents threads getting stuck due to Tomcat/F5 issue caused by the client continuing to send data when FOX isn't reading it
    try {
      ((MultipartStream.ItemInputStream) mItemInputStream).close(true);
    }
    catch (Throwable th) {
      Track.recordSuppressedException("UploadFinaliseInputStreamClose", th);
    }
  }

  if(mItemNonBlockingInputStream != null) {
    mItemNonBlockingInputStream.destroy();
  }
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:26,代码来源:UploadWorkItem.java

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

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

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

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