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


Java PartSource类代码示例

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


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

示例1: getAbstract

import org.apache.commons.httpclient.methods.multipart.PartSource; //导入依赖的package包/类
/** 
 * 生成文件摘要
 * @param strFilePath 文件路径
 * @param file_digest_type 摘要算法
 * @return 文件摘要结果
 */
public static String getAbstract(String strFilePath, String file_digest_type) throws IOException {
    PartSource file = new FilePartSource(new File(strFilePath));
	if(file_digest_type.equals("MD5")){
		return DigestUtils.md5Hex(file.createInputStream());
	}
	else if(file_digest_type.equals("SHA")) {
		return DigestUtils.sha256Hex(file.createInputStream());
	}
	else {
		return "";
	}
}
 
开发者ID:dianbaer,项目名称:epay,代码行数:19,代码来源:AlipayCore.java

示例2: buildParts

import org.apache.commons.httpclient.methods.multipart.PartSource; //导入依赖的package包/类
private List<Part> buildParts(BaseRequest request) {
    List<Part> parts = new ArrayList<Part>();
    for (PartHolder h : TankHttpUtil.getPartsFromBody(request)) {
        if (h.getFileName() == null) {
            StringPart stringPart = new StringPart(h.getPartName(), new String(h.getBodyAsString()));
            if (h.isContentTypeSet()) {
                stringPart.setContentType(h.getContentType());
            }
            parts.add(stringPart);
        } else {
            PartSource partSource = new ByteArrayPartSource(h.getFileName(), h.getBody());
            FilePart p = new FilePart(h.getPartName(), partSource);
            if (h.isContentTypeSet()) {
                p.setContentType(h.getContentType());
            }
            parts.add(p);
        }
    }
    return parts;
}
 
开发者ID:intuit,项目名称:Tank,代码行数:21,代码来源:TankHttpClient3.java

示例3: getAbstract

import org.apache.commons.httpclient.methods.multipart.PartSource; //导入依赖的package包/类
/**
 * 生成文件摘要
 *
 * @param strFilePath      文件路径
 * @param file_digest_type 摘要算法
 * @return 文件摘要结果
 */
public static String getAbstract(String strFilePath, String file_digest_type) throws IOException {
	PartSource file = new FilePartSource(new File(strFilePath));
	if (file_digest_type.equals("MD5")) {
		return DigestUtils.md5Hex(file.createInputStream());
	} else if (file_digest_type.equals("SHA")) {
		return DigestUtils.sha256Hex(file.createInputStream());
	} else {
		return "";
	}
}
 
开发者ID:funtl,项目名称:framework,代码行数:18,代码来源:AlipayCore.java

示例4: sendFile

import org.apache.commons.httpclient.methods.multipart.PartSource; //导入依赖的package包/类
public static int sendFile(final String host, final String port, final String path, final String fileName,
    final InputStream inputStream, final long lengthInBytes) {
  HttpClient client = new HttpClient();
  try {

    client.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
    client.getParams().setSoTimeout(3600 * 1000); // One hour
    PostMethod post = new PostMethod("http://" + host + ":" + port + "/" + path);
    Part[] parts = { new FilePart(fileName, new PartSource() {
      @Override
      public long getLength() {
        return lengthInBytes;
      }

      @Override
      public String getFileName() {
        return "fileName";
      }

      @Override
      public InputStream createInputStream() throws IOException {
        return new BufferedInputStream(inputStream);
      }
    }) };
    post.setRequestEntity(new MultipartRequestEntity(parts, new HttpMethodParams()));
    client.executeMethod(post);
    if (post.getStatusCode() >= 400) {
      String errorString = "POST Status Code: " + post.getStatusCode() + "\n";
      if (post.getResponseHeader("Error") != null) {
        errorString += "ServletException: " + post.getResponseHeader("Error").getValue();
      }
      throw new HttpException(errorString);
    }
    return post.getStatusCode();
  } catch (Exception e) {
    LOGGER.error("Caught exception while sending file", e);
    Utils.rethrowException(e);
    throw new AssertionError("Should not reach this");
  }
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:41,代码来源:FileUploadUtils.java

示例5: getAbstract

import org.apache.commons.httpclient.methods.multipart.PartSource; //导入依赖的package包/类
/**
 * 生成文件摘要
 *
 * @param strFilePath      文件路径
 * @param file_digest_type 摘要算法
 * @return 文件摘要结果
 */
public static String getAbstract(String strFilePath, String file_digest_type) throws IOException {
    PartSource file = new FilePartSource(new File(strFilePath));
    switch (file_digest_type) {
        case "MD5":
            return DigestUtils.md5Hex(file.createInputStream());
        case "SHA":
            return DigestUtils.sha256Hex(file.createInputStream());
        default:
            return "";
    }
}
 
开发者ID:wenzhucjy,项目名称:GeneralUtils,代码行数:19,代码来源:AlipayCore_O.java

示例6: getPostMultiPartWithFiles

import org.apache.commons.httpclient.methods.multipart.PartSource; //导入依赖的package包/类
private PostMethod getPostMultiPartWithFiles(PostMethod method, KalturaParams kparams, KalturaFiles kfiles) {

   	String boundary = "---------------------------" + System.currentTimeMillis();
   	List <Part> parts = new ArrayList<Part>();
   	parts.add(new StringPart (HttpMethodParams.MULTIPART_BOUNDARY, boundary));

   	for(Entry<String, String> itr : kparams.entrySet()) {
   		parts.add(new StringPart (itr.getKey(), itr.getValue()));       
   	}
   	
   	for (String key : kfiles.keySet()) {
   	    final KalturaFile kFile = kfiles.get(key);
   	    parts.add(new StringPart (key, "filename="+kFile.getName()));
   	    if (kFile.getFile() != null) {
   	        // use the file
   	        File file = kFile.getFile();
   	        try {
   	            parts.add(new FilePart(key, file));
   	        } catch (FileNotFoundException e) {
   	            // TODO this sort of leaves the submission in a weird state... -AZ
   	            logger.error("Exception while iterating over kfiles", e);          
   	        }
   	    } else {
   	        // use the input stream
   	        PartSource fisPS = new PartSource() {
   	            public long getLength() {
   	                return kFile.getSize();
   	            }
   	            public String getFileName() {
   	                return kFile.getName();
   	            }
   	            public InputStream createInputStream() throws IOException {
   	                return kFile.getInputStream();
   	            }
   	        };
   	        parts.add(new FilePart(key, fisPS));
   	    }
   	}
    
   	Part allParts[] = new Part[parts.size()];
   	allParts = parts.toArray(allParts);
    
   	method.setRequestEntity(new MultipartRequestEntity(allParts, method.getParams()));

   	return method;
   }
 
开发者ID:ITYug,项目名称:kaltura-ce-sakai-extension,代码行数:47,代码来源:KalturaClientBase.java

示例7: ContentTypeFilePart

import org.apache.commons.httpclient.methods.multipart.PartSource; //导入依赖的package包/类
/**
 * ContentTypeFilePart constructor.
 * 
 * @param name the name of the part
 * @param partSource the source for this part
 * @param charset the charset encoding for this part.
 */
public ContentTypeFilePart(String name, PartSource partSource, String charset) {
    super(name, partSource, ContentType.get(partSource.getFileName()), charset);
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:11,代码来源:ContentTypeFilePart.java


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