当前位置: 代码迷 >> Java相关 >> 新人求罩,求大神帮忙提取打包一下线程的代码,
  详细解决方案

新人求罩,求大神帮忙提取打包一下线程的代码,

热度:30   发布时间:2016-04-22 21:00:12.0
新人求罩,求大神帮忙提取封装一下线程的代码,急
public class UpYunUploadTask implements Callable<String>, Serializable {

    private static Logger logger = Logger.getLogger(UpYunUploadTask.class);

    private static final long serialVersionUID = 8843096818844315992L;


    private Map<String, String> taskData;

public UpYunUploadTask(Map<String, String> taskData) {
this.taskData = taskData;
}

public synchronized String call() throws Exception {
        // 1.上传icon图标
        String icon = taskData.get("icon");

        String screenshotDir = InitDataCompnent.getConfigValue("screenshotuploadpath");
        String apkiconDir = InitDataCompnent.getConfigValue("apkiconuploadpath");

        String screenshotUrl = InitDataCompnent.getConfigValue("screenshotuploadurl");
        String apkiconUrl = InitDataCompnent.getConfigValue("apkiconuploadurl");

        String upyunScreenshot = InitDataCompnent.getConfigValue("upyun_screenshot");
        String upyunApkicon = InitDataCompnent.getConfigValue("upyun_apkicon");
        UpYunUtils upyun = null;
        if(StringUtils.isNotBlank(icon)) {
            upyun = new UpYunUtils(Constant.APK_ICON_UPYUN_BUCKET_NAME,
                    Constant.APK_ICON_UPYUN_USER_NAME, Constant.APK_ICON_UPYUN_PASSWORD);
            upyun.setTimeout(300);
            File iconFile = null;
            if(icon.startsWith(screenshotUrl)) {
                icon = icon.replaceAll(screenshotUrl,"");
                iconFile = new File(screenshotDir + icon);
            } else if(icon.startsWith(apkiconUrl)) {
                icon = icon.replaceAll(apkiconUrl,"");
                iconFile = new File(apkiconDir + icon);
            }

            boolean isUpload = upyun.writeFile(upyunApkicon + icon, iconFile, true);
            logger.debug("本地文件路径:" + apkiconDir + icon +  ", 上传文件路径:" + upyunApkicon + icon +", 是否上传成功:" + isUpload);
        }

        String strImages = taskData.get("images");
        if(StringUtils.isNotBlank(strImages)) {
            upyun = new UpYunUtils(Constant.SCREEN_SHOT_UPYUN_BUCKET_NAME,
                    Constant.SCREEN_SHOT_UPYUN_USER_NAME, Constant.SCREEN_SHOT_UPYUN_PASSWORD);
            upyun.setTimeout(300);
            strImages = strImages.replaceAll(screenshotUrl,"");
            String[] images = StringUtils.split(strImages, ",");
           
            File imageFile = null;
            for(String image:images) {
                imageFile = new File(screenshotDir + image);
                boolean isUpload = upyun.writeFile(upyunScreenshot + image, imageFile, true);
                logger.debug("本地文件路径:" + apkiconDir + image + ",上传文件目录:" + upyunScreenshot + image +", 是否上传成功:" + isUpload);
            }
        }
  相关解决方案