LiveController.java 23.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
package com.cnlive.shenhe.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.bean.ErrorEnum;
import com.cnlive.shenhe.bean.ResponseBean;
import com.cnlive.shenhe.bean.SessionUser;
import com.cnlive.shenhe.dto.LiveDTO;
import com.cnlive.shenhe.entity.ShyLive;
import com.cnlive.shenhe.entity.ShySites;
import com.cnlive.shenhe.entity.ShyUsers;
import com.cnlive.shenhe.service.LiveService;
import com.cnlive.shenhe.service.SitesService;
import com.cnlive.shenhe.service.UsersService;
import com.cnlive.shenhe.service.VideosService;
import com.cnlive.shenhe.utils.AuditPass;
import com.cnlive.shenhe.utils.CommonConst;
import com.cnlive.shenhe.utils.CommonUtils;
import com.cnlive.shenhe.utils.HttpClientUtils;
import com.github.pagehelper.PageInfo;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 */
@Controller
@RequestMapping("/live")
public class LiveController extends BaseController {
    private static Logger logger = LoggerFactory.getLogger(LiveController.class);
    @Autowired
    AuditPass pass;
    @Autowired
    VideosService videosService;
    @Autowired
    UsersService usersService;
    @Autowired
    SitesService sitesService;
    @Autowired
    LiveService liveService;

    @Value("${qn_domain}")
    String qn_domain;

    @Value("${ks_domain}")
    String ks_domain;

    @Value("${cms_getVideoAndLiveId}")
    String cms_getVideoAndLiveId;

    /**
     * 审核信息返回接口
     *
     * @param activity_id 视频id
     * @param state       状态码
     * @param attr_tags   标签
     * @param msg         备注信息
     * @return
     */
    @PostMapping("/shenheVideo")
    @ResponseBody
    public ResponseBean shenheInfo(Integer id, String activity_id, Integer state, String attr_tags, String msg, String callback, HttpSession session) {
        SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
        String userId = sessionUser.getUserId();
        JSONObject result;
        try {
            result = pass.auditPass(activity_id, state, attr_tags, msg, callback);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("视频审核失败");
            return new ResponseBean(ErrorEnum.ERROR);
        }
        if (result == null) {
            System.out.println("视频审核失败且接口错误没有返回信息");
            return new ResponseBean(ErrorEnum.ERROR);
        }
        Integer code = result.getInteger("code");
        if (code != 0) {
            System.out.println("审核失败,code==" + code);
            return new ResponseBean(code, result.getString("msg"));
        }
        state = state == 4 ? 2 : 1;
        int i = videosService.updateVideo(id, userId, null, attr_tags, state, msg);
        if (i == 0) {
            return new ResponseBean(ErrorEnum.ERROR);
        }
        return new ResponseBean(ErrorEnum.SUCCESS);
    }

    /**
     * 内容分页列表接口
     *
     * @param model
     * @param liveDTO
     * @param session
     * @return
     */
    @GetMapping("/page")
    public Object getListLives(Model model, LiveDTO liveDTO, HttpSession session) {
        logger.info("列表请求参数:{}", JSON.toJSONString(liveDTO));
        SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
        Integer spid = sessionUser.getSpid();
        String userId = sessionUser.getUserId();
        liveDTO.setSpid(spid);
        liveDTO.setUserId(userId);
        if (CommonUtils.isNotEmpty(liveDTO.getSp_desc()) && liveDTO.getSpid() == 0) {
            ShySites shySite = sitesService.findspidBySpdesc(liveDTO.getSp_desc());
            if (CommonUtils.isNotNull(shySite)) {
                liveDTO.setSpid(shySite.getSpid());
            } else {
                setmodelSite(model);
                return "error.html";
            }
        } else if (CommonUtils.isEmpty(liveDTO.getSp_desc()) && liveDTO.getSpid() == 0) {
            liveDTO.setSpid(null);
        }
        StringBuilder orderByClause = new StringBuilder();
        //String orderByClause = "";
        //审核状态:全部待领
        if (liveDTO.getShenhe_state() != null && liveDTO.getShenhe_state() == 0) {
            orderByClause.append("field(activity_status,1,3,2,0,4), pre_start_time");
            //审核状态:待审核
        } else if (liveDTO.getShenhe_state() != null && liveDTO.getShenhe_state() == 1) {
            orderByClause.append("field(activity_status,1,3,2,0,4), pre_start_time");
            //审核状态:已审核
        } else if (liveDTO.getShenhe_state() != null && liveDTO.getShenhe_state() == 2) {
            orderByClause.append("pre_start_time desc");
            //审核状态:全部
        } else {
            orderByClause.append("is_hot desc, pre_start_time");
            //直播状态:结束、撤销、下线
            if (liveDTO.getActivity_status() != null && (liveDTO.getActivity_status() == 0 || liveDTO.getActivity_status() == 2 || liveDTO.getActivity_status() == 4)) {
                orderByClause.append("is_hot desc, pre_start_time desc");
            }
        }
        if (CommonUtils.isNotNull(liveDTO.getContentId())) {
            Map<String, String> map = new HashMap<>(1);
            map.put("id", liveDTO.getContentId().toString());
            String post = HttpClientUtils.get(cms_getVideoAndLiveId, map);
            JSONObject jsonObject = JSONObject.parseObject(post);
            JSONObject data = jsonObject.getJSONObject("data");
            if (data != null) {
                String pid = data.getString("pid");
                liveDTO.setActivity_id(pid);
            } else {
                liveDTO.setActivity_id(String.valueOf(liveDTO.getContentId()));
            }
        }
        PageInfo<ShyLive> livePage = liveService.getListLive(liveDTO);
        List<ShyLive> list = livePage.getList();
        if (!list.isEmpty()) {
            for (ShyLive live : list) {
                //显示spid简称
                ShySites shySites = sitesService.findspidDescByspid(live.getSp_id());
                if (CommonUtils.isNotNull(shySites)) {
                    live.setSpid_desc(shySites.getName());
                }
            }
        }
        model.addAttribute("livePage", livePage);
        model.addAttribute("pageSize", liveDTO.getPageSize());
        model.addAttribute("ActivityStatus", liveDTO.getActivity_status());
        model.addAttribute("Activity_name", liveDTO.getActivity_name());
        model.addAttribute("Activity_id", liveDTO.getActivity_id());
        model.addAttribute("Sp_desc", liveDTO.getSp_desc());
        model.addAttribute("Start_date", liveDTO.getStart_date());
        model.addAttribute("End_date", liveDTO.getEnd_date());
        model.addAttribute("ContentId", liveDTO.getContentId());
        return "page/live.html";
    }

    /**
     * 内容详情页接口(查看)
     *
     * @param id
     * @return
     */
    @GetMapping("/details")
    public Object getDetailsLive(Model model, Integer id) {
        ShyLive live = liveService.getDetailsLive(id);
        //显示spid简称
        ShySites shySites = sitesService.findspidDescByspid(live.getSp_id());
        if (CommonUtils.isNotNull(shySites)) {
            live.setSpid_desc(shySites.getName());
        }
        model.addAttribute("live", live);
        return "page/liveDetail.html";
    }

    /**
     * 认领
     *
     * @param ids     根据id认领
     * @param num     认领条数
     * @param session
     * @return
     */
    @PostMapping("/receive")
    @ResponseBody
    public ResponseBean receive(String ids, Integer num, HttpSession session) {
        SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
        String userId = sessionUser.getUserId();
        Integer spid = sessionUser.getSpid();
        //领取时要检查领取的数据是否可以领
        if (CommonUtils.isNotEmpty(ids)) {
            String[] cids = ids.split(",");
            for (String cid : cids) {
                ShyLive shyLive = liveService.selectByPrimaryKey(Integer.parseInt(cid));
                if (CommonUtils.isNotNull(shyLive)) {
                    if (!shyLive.getShenhe_state().equals(CommonConst.RECEIVE_BEFORE)) {
                        return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "您领取的内容中有已被领取或者已经被审核,请检查并重试");
                    }
                } else {
                    return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "您领取的内容不存在,请检查并重试");

                }
            }
        }
        Integer n = liveService.receive(ids, num, userId, spid);
        return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "认领到" + n + "条内容");
    }


    /**
     * 退领
     *
     * @param ids
     * @param session
     * @return
     */
    @PostMapping("/retReceive")
    @ResponseBody
    public ResponseBean retReceive(String ids, HttpSession session) {
        SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
        String userId = sessionUser.getUserId();
        //在退领操作前先判断是否包含已退领或者已经审核的数据,有则退回检查并重新退领
        String[] cids = ids.split(",");
        for (String cid : cids) {
            ShyLive shyLive = liveService.selectByPrimaryKey(Integer.parseInt(cid));
            if (!shyLive.getShenhe_state().equals(CommonConst.RECEIVE_AFTER) || !shyLive.getAuditor().equals(userId)) {
                return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "退领失败,您选中的内容包含已退领的或已经审核的");
            }
        }
        return liveService.retReceive(ids, userId);
    }

    /**
     * 打回(审核通过、拒绝、强制下线)
     * status 3、4、6
     *
     * @param ids
     * @param msg
     * @param session
     * @return
     */
    @PostMapping("/repulse")
    @ResponseBody
    public ResponseBean repulse(String ids, String msg, Integer status, HttpSession session) {
        SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
        String userId = sessionUser.getUserId();
        ResponseBean responseBean = new ResponseBean();
        String[] shyLiveIds = ids.split(",");
        StringBuilder showMsg = new StringBuilder();
        for (String shyLiveId : shyLiveIds) {
            ShyLive shyLive = liveService.selectByPrimaryKey(Integer.parseInt(shyLiveId));
            JSONObject result;
            try {
                result = pass.livePass(shyLive.getActivity_id(), status, msg, msg, shyLive.getCallback());
            } catch (Exception e) {
                logger.error("直播视频审核失败,id==" + shyLiveId, e);
                showMsg.append(",").append(shyLive.getActivity_id()).append(" 拒绝请求失败");
                break;
            }
            if (result == null) {
                logger.error("直播视频审核失败且接口错误没有返回信息,id==" + shyLiveId);
                showMsg.append(",").append(shyLive.getActivity_id()).append(" 拒绝请求失败");
                break;
            }
            Integer code = result.getInteger("errorCode");
            if (code != 0) {
                logger.error("直播视频审核失败,id:{},code:{}", shyLiveId, code);
                showMsg.append(",").append(shyLive.getActivity_id()).append(" ").append(result.getString(" errorMessage"));
                break;
            }
            int i = liveService.updateLive(Integer.parseInt(shyLiveId), userId, "", status == 3 ? 3 : 4, msg);
            if (i == 0) {
                showMsg.append(",").append(shyLive.getActivity_id()).append(" 更新失败");
                break;
            }
        }
        if (CommonUtils.isNotEmpty(showMsg.toString())) {
            responseBean.setErrorCode(ErrorEnum.ERROR.getErrorCode());
            responseBean.setErrorMessage(showMsg.toString());
        }
        return responseBean;
    }

    /**
     * 同步直播云信息
     *
     * @param ids
     * @param
     * @return
     */
    @PostMapping("/syncLive")
    @ResponseBody
    public ResponseBean syncLive(String ids) {
        logger.info("同步直播云信息接口进入");
        ResponseBean responseBean = new ResponseBean();
        String[] shyLiveIds = ids.split(",");
        StringBuilder showMsg = new StringBuilder();
        for (String shyLiveId : shyLiveIds) {
            ShyLive shyLive = liveService.selectByPrimaryKey(Integer.parseInt(shyLiveId));
            JSONObject result;
            try {
                result = pass.syncLive(shyLive.getActivity_id());
            } catch (Exception e) {
                logger.error("直播云信息同步失败,id==" + shyLiveId, e);
                showMsg.append(",").append(shyLive.getActivity_id()).append(" 拒绝请求失败");
                break;
            }
            if (result == null) {
                logger.error("直播云信息同步失败且接口错误没有返回信息,id==" + shyLiveId);
                showMsg.append(",").append(shyLive.getActivity_id()).append(" 拒绝请求失败");
                break;
            }
            Integer code = result.getInteger("errorCode");
            if (code != 0) {
                logger.error("直播云信息同步失败,id:{},code:{}", shyLiveId, code);
                showMsg.append(result.getString("errorMessage"));
                break;
            }
        }
        if (CommonUtils.isNotEmpty(showMsg.toString())) {
            responseBean.setErrorCode(ErrorEnum.ERROR.getErrorCode());
            responseBean.setErrorMessage(showMsg.toString());
        } else {
            showMsg.append("直播云信息同步成功");
            responseBean.setErrorCode(ErrorEnum.SUCCESS.getErrorCode());
            responseBean.setErrorMessage(showMsg.toString());
        }
        return responseBean;
    }

    /**
     * 根据条件导出excel
     */
    @GetMapping("excel")
    public void getExcel(LiveDTO liveDTO, HttpSession session, HttpServletResponse response) {

        SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
        Integer spid = sessionUser.getSpid();
        String userId = sessionUser.getUserId();
        liveDTO.setSpid(spid);
        liveDTO.setUserId(userId);
        if (CommonUtils.isNotEmpty(liveDTO.getSp_desc()) && liveDTO.getSpid() == 0) {
            ShySites shySite = sitesService.findspidBySpdesc(liveDTO.getSp_desc());
            if (CommonUtils.isNotNull(shySite)) {
                liveDTO.setSpid(shySite.getSpid());
            }
        } else if (CommonUtils.isEmpty(liveDTO.getSp_desc()) && liveDTO.getSpid() == 0) {
            liveDTO.setSpid(null);
        }
        List<ShyLive> liveList = liveService.findByCondition(liveDTO);

        String fileName = "直播数据";

        XSSFWorkbook wb = new XSSFWorkbook();
        ServletOutputStream out = null;
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {
            XSSFSheet sheetlist = wb.createSheet(fileName);
            XSSFRow row = sheetlist.createRow(0);//行
            XSSFCell cell = row.createCell(0);//列
            cell.setCellValue("id");
            cell = row.createCell(1);//列
            cell.setCellValue("预计直播日期");
            cell = row.createCell(2);//列
            cell.setCellValue("预计开始时间");
            cell = row.createCell(3);//列
            cell.setCellValue("预计结束时间");
            cell = row.createCell(4);//列
            cell.setCellValue("直播主题");
            cell = row.createCell(5);//列
            cell.setCellValue("直播申请方");
            cell = row.createCell(6);//列
            cell.setCellValue("直播类型");
            cell = row.createCell(7);//列
            cell.setCellValue("监播人");
            cell = row.createCell(8);//列
            cell.setCellValue("实际直播日期");
            cell = row.createCell(9);//列
            cell.setCellValue("实际开始时间");
            cell = row.createCell(10);//列
            cell.setCellValue("实际结束时间");
            cell = row.createCell(11);//列
            cell.setCellValue("时长");
            cell = row.createCell(12);//列
            cell.setCellValue("备注");
            cell = row.createCell(13);//列
            cell.setCellValue("版权来源");

            for (int i = 0; i < liveList.size(); i++) {
                row = sheetlist.createRow((short) (i + 1));//行
                cell = row.createCell(0);//列
                cell.setCellValue(liveList.get(i).getId());
                cell = row.createCell(1);//列
                if (liveList.get(i).getPre_start_time() != null) {
                    cell.setCellValue(CommonUtils.formatDate(liveList.get(i).getPre_start_time(), "yyyy/MM/dd"));
                }
                cell = row.createCell(2);//列
                if (liveList.get(i).getPre_start_time() != null) {
                    cell.setCellValue(CommonUtils.formatDate(liveList.get(i).getPre_start_time(), "HH:mm"));
                }
                /*预计结束时间需要处理成用户可读*/
                String preEndTime = "";
                //结束时间为空
                if (CommonUtils.isNull(liveList.get(i).getPre_end_time())) {
                    preEndTime = "待定";
                } else {
                    long start = liveList.get(i).getPre_start_time().getTime() + 8 * 60 * 60 * 1000;
                    long end = liveList.get(i).getPre_end_time().getTime() + 8 * 60 * 60 * 1000;
                    long count = end / (24 * 3600 * 1000) - start / (24 * 3600 * 1000);
                    logger.info(String.valueOf(count));
                    if (count == 0) {
                        preEndTime = CommonUtils.formatDate(liveList.get(i).getPre_end_time(), "HH:mm");
                    } else if (count > 0) {
                        preEndTime = "跨" + count + "天 " + CommonUtils.formatDate(liveList.get(i).getPre_end_time(), "HH:mm");
                    }
                }
                cell = row.createCell(3);//列
                cell.setCellValue(preEndTime);
                cell = row.createCell(4);//列
                cell.setCellValue(liveList.get(i).getActivity_name());
                cell = row.createCell(5);//列
                cell.setCellValue(sitesService.findspidDescByspid(liveList.get(i).getSp_id()).getName());
                cell = row.createCell(6);//列
                cell.setCellValue(liveList.get(i).getLive_type());
                cell = row.createCell(7);//列
                /* 审核员需要做处理*/
                String updater = "";//审核员名字
                if (!liveList.get(i).getShenhe_state().equals(CommonConst.RECEIVE_BEFORE)) {
                    updater = CommonUtils.isEmpty(liveList.get(i).getUpdater()) || "null".equals(liveList.get(i).getUpdater()) ? "自动通过" : liveList.get(i).getUpdater();
                    String auditorId = liveList.get(i).getAuditor();
                    if (CommonUtils.isNotEmpty(auditorId)) {
                        ShyUsers user = new ShyUsers();
                        user.setUser_id(auditorId);
                        user = usersService.select(user);
                        if (CommonUtils.isNotNull(user)) {
                            String email = CommonUtils.isEmpty(user.getEmail()) || "null".equals(user.getEmail()) ? "" : user.getEmail();
                            updater = CommonUtils.isEmpty(user.getUsername()) ? email : user.getUsername();
                        }
                    }
                }
                cell.setCellValue(updater);
                cell = row.createCell(8);//列
                if (liveList.get(i).getActivity_start_time() != null) {
                    cell.setCellValue(CommonUtils.formatDate(liveList.get(i).getActivity_start_time(), "yyyy/MM/dd"));
                }
                cell = row.createCell(9);//列
                if (liveList.get(i).getActivity_start_time() != null) {
                    cell.setCellValue(CommonUtils.formatDate(liveList.get(i).getActivity_start_time(), "HH:mm"));
                }
                /*实际结束时间需要处理成用户可读*/
                String activityEndTime = "";
                if (liveList.get(i).getActivity_start_time() != null && liveList.get(i).getActivity_end_time() != null) {
                    long activityStart = liveList.get(i).getActivity_start_time().getTime() + 8 * 60 * 60 * 1000;
                    long activityEnd = liveList.get(i).getActivity_end_time().getTime() + 8 * 60 * 60 * 1000;
                    long activityCount = activityEnd / (24 * 3600 * 1000) - activityStart / (24 * 3600 * 1000);
                    logger.info(String.valueOf(activityCount));
                    if (activityCount == 0) {
                        activityEndTime = CommonUtils.formatDate(liveList.get(i).getActivity_end_time(), "HH:mm");
                    } else if (activityCount > 0) {
                        activityEndTime = "跨" + activityCount + "天 " + CommonUtils.formatDate(liveList.get(i).getActivity_end_time(), "HH:mm");
                    }
                    cell = row.createCell(10);//列
                    cell.setCellValue(activityEndTime);
                    cell = row.createCell(11);//时长
                    /*时长需要处理成用户可读,单位:分钟*/
                    long timeLength = (activityEnd - activityStart) / (60 * 1000);
                    cell.setCellValue(timeLength);
                    cell = row.createCell(12);//列
                    cell.setCellValue("");
                    cell = row.createCell(13);//列
                    cell.setCellValue("");
                }
            }
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            wb.write(os);
            byte[] content = os.toByteArray();
            InputStream is = new ByteArrayInputStream(content);
            response.setContentType("application/vnd.ms-excel;charset=utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + new String((fileName + ".xlsx").getBytes(), "iso-8859-1"));
            out = response.getOutputStream();
            bis = new BufferedInputStream(is);
            bos = new BufferedOutputStream(out);
            byte[] buff = new byte[2048];
            int bytesRead;
            while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
                bos.write(buff, 0, bytesRead);
            }
        } catch (final Exception e) {
            e.printStackTrace();
            try {
                if (bis != null) {
                    bis.close();
                }
                if (bos != null) {
                    bos.close();
                }
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        } finally {
            try {
                if (bis != null) {
                    bis.close();
                }
                if (bos != null) {
                    bos.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }
}