java类javax.servlet.http.Part的实例源码

FrontiersReqHandler.java 文件源码 项目:Hi-Framework 阅读 23 收藏 0 点赞 0 评论 0
private Object getUploadedFiles(String strParamValue, String frontier, FrontierMethod frontierMethod,
                               MethodParam methodParam, Map<String,Object> uploadsMap,
                                HttpServletRequest request) throws FrontierCallException {

    String uploadName = strParamValue.substring(strParamValue.indexOf(":")+1,strParamValue.length());
    if(!uploadsMap.containsKey(uploadName))
        throw new FrontierCallException(frontier,methodParam.getName(),"The upload request data is corrupted");

    Double totalD = (Double) uploadsMap.get(uploadName);
    int total = totalD.intValue();
    if(total<1)
        throw new MissingFrontierParamException(frontier,frontierMethod.getName(),methodParam.getName());

    FileUpload[] files = new FileUpload[total];
    for(int i=0; i<total;i++){
        try {
            String partName = uploadName + "_file_" + i;
            Part part = request.getPart(partName);
            if (part == null)
                throw new FrontierCallException(frontier, methodParam.getName(), "The upload request data is corrupted");
            files[i] = new FileUpload(part);
        }catch (IOException | ServletException ex){
            throw new FrontierCallException(frontier, methodParam.getName(), "Failed to decode uploaded content",ex);
        }
    }

    if(methodParam.getType().isArray())return files;
    else{

        if(files.length>1)
            throw new FrontierCallException(frontier,methodParam.getName(),"One file expected. "+files.length+" uploaded files found");
        return files[0];

    }

}
JbootServletRequestWrapper.java 文件源码 项目:jboot 阅读 24 收藏 0 点赞 0 评论 0
@Override
public Collection<Part> getParts() throws IOException, ServletException {
    if (!RequestUtils.isMultipartRequest(this)) {
        return null;
    }
    return super.getParts();
}
HttpServletRequestImpl.java 文件源码 项目:lams 阅读 32 收藏 0 点赞 0 评论 0
@Override
public Part getPart(final String name) throws IOException, ServletException {
    if (parts == null) {
        loadParts();
    }
    for (Part part : parts) {
        if (part.getName().equals(name)) {
            return part;
        }
    }
    return null;
}
AbstractFileUpload.java 文件源码 项目:Equella 阅读 21 收藏 0 点赞 0 评论 0
public String getMimeType(SectionInfo info)
{
    Part file = getMultipartFile(info);
    if( file != null )
    {
        return file.getContentType();
    }
    return null;
}
MinijaxMultipartForm.java 文件源码 项目:minijax 阅读 29 收藏 0 点赞 0 评论 0
@Override
public InputStream getInputStream(final String name) {
    try {
        final Part part = values.get(name);
        return part == null ? null : part.getInputStream();
    } catch (final IOException ex) {
        throw ExceptionUtils.toWebAppException(ex);
    }
}
StandardMultipartHttpServletRequest.java 文件源码 项目:lams 阅读 32 收藏 0 点赞 0 评论 0
@Override
public String getMultipartContentType(String paramOrFileName) {
    try {
        Part part = getPart(paramOrFileName);
        return (part != null ? part.getContentType() : null);
    }
    catch (Exception ex) {
        throw new MultipartException("Could not access multipart servlet request", ex);
    }
}
PartHandler.java 文件源码 项目:oscm 阅读 23 收藏 0 点赞 0 评论 0
public static byte[] getBuffer(Part file) throws IOException {

        InputStream fileInStream = file.getInputStream();

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024);
        byte[] bytes = new byte[512];

        int readBytes;
        while ((readBytes = fileInStream.read(bytes)) > 0) {
            outputStream.write(bytes, 0, readBytes);
        }

        return outputStream.toByteArray();
    }
PartHandler.java 文件源码 项目:oscm 阅读 24 收藏 0 点赞 0 评论 0
public static boolean isEmpty(Part file) {

    if(file==null){
        return true;
    }

    return !(file.getSize()>0);
}
HTMLManagerServlet.java 文件源码 项目:lazycat 阅读 29 收藏 0 点赞 0 评论 0
protected String upload(HttpServletRequest request, StringManager smClient) {
    String message = "";

    try {
        while (true) {
            Part warPart = request.getPart("deployWar");
            if (warPart == null) {
                message = smClient.getString("htmlManagerServlet.deployUploadNoFile");
                break;
            }
            String filename = extractFilename(warPart.getHeader("Content-Disposition"));
            if (!filename.toLowerCase(Locale.ENGLISH).endsWith(".war")) {
                message = smClient.getString("htmlManagerServlet.deployUploadNotWar", filename);
                break;
            }
            // Get the filename if uploaded name includes a path
            if (filename.lastIndexOf('\\') >= 0) {
                filename = filename.substring(filename.lastIndexOf('\\') + 1);
            }
            if (filename.lastIndexOf('/') >= 0) {
                filename = filename.substring(filename.lastIndexOf('/') + 1);
            }

            // Identify the appBase of the owning Host of this Context
            // (if any)
            File file = new File(deployed, filename);
            if (file.exists()) {
                message = smClient.getString("htmlManagerServlet.deployUploadWarExists", filename);
                break;
            }

            ContextName cn = new ContextName(filename, true);
            String name = cn.getName();

            if ((host.findChild(name) != null) && !isDeployed(name)) {
                message = smClient.getString("htmlManagerServlet.deployUploadInServerXml", filename);
                break;
            }

            if (isServiced(name)) {
                message = smClient.getString("managerServlet.inService", name);
            } else {
                addServiced(name);
                try {
                    warPart.write(file.getAbsolutePath());
                    // Perform new deployment
                    check(name);
                } finally {
                    removeServiced(name);
                }
            }
            break;
        }
    } catch (Exception e) {
        message = smClient.getString("htmlManagerServlet.deployUploadFail", e.getMessage());
        log(message, e);
    }
    return message;
}
SSOUtilsTest.java 文件源码 项目:sso-client 阅读 36 收藏 0 点赞 0 评论 0
@Override
public Part getPart(String name) throws IOException, ServletException {
    return null;
}


问题


面经


文章

微信
公众号

扫码关注公众号