Java 类org.apache.commons.httpclient.methods.multipart.PartSource 实例源码

项目:epay    文件:AlipayCore.java   
/** 
 * 生成文件摘要
 * @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 "";
    }
}
项目:framework    文件:AlipayCore.java   
/**
 * 生成文件摘要
 *
 * @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 "";
    }
}
项目:WeiXing_xmu-2016-MrCode    文件:AlipayCore.java   
/** 
 * 生成文件摘要
 * @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 "";
    }
}
项目:k-framework    文件:AlipayCore.java   
/** 
 * 生成文件摘要
 * @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 "";
    }
}
项目:Tank    文件:TankHttpClient3.java   
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;
}
项目:Shop-for-JavaWeb    文件:AlipayCore.java   
/** 
 * 生成文件摘要
 * @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 "";
    }
}
项目:xmu-2016-MrCode    文件:AlipayCore.java   
/** 
 * 生成文件摘要
 * @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 "";
    }
}
项目:shopping    文件:AlipayCore.java   
/** 
 * 生成文件摘要
 * @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 "";
    }
}
项目:Pinot    文件:FileUploadUtils.java   
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");
  }
}
项目:GeneralUtils    文件:AlipayCore_O.java   
/**
 * 生成文件摘要
 *
 * @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 "";
    }
}
项目:GeneralUtils    文件:AlipayCore.java   
/**
 * 生成文件摘要
 *
 * @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 "";
    }
}
项目:kaltura-ce-sakai-extension    文件:KalturaClientBase.java   
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;
   }
项目:lib-commons-httpclient    文件:ContentTypeFilePart.java   
/**
 * 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);
}
项目:lib-commons-httpclient    文件:ContentTypeFilePart.java   
/**
 * ContentTypeFilePart constructor.
 * 
 * @param name the name of the part
 * @param partSource the source for this part
 */
public ContentTypeFilePart(String name, PartSource partSource) {
    this(name, partSource, null);
}
项目:httpclient3-ntml    文件:ContentTypeFilePart.java   
/**
 * 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);
}
项目:httpclient3-ntml    文件:ContentTypeFilePart.java   
/**
 * ContentTypeFilePart constructor.
 * 
 * @param name the name of the part
 * @param partSource the source for this part
 */
public ContentTypeFilePart(String name, PartSource partSource) {
    this(name, partSource, null);
}