List of usage examples for javax.servlet ServletInputStream close
public void close() throws IOException
From source file:cn.jcenterhome.web.action.CpAction.java
public ActionForward cp_videophoto(HttpServletRequest request, HttpServletResponse response) { Map<String, Object> sGlobal = (Map<String, Object>) request.getAttribute("sGlobal"); Map<String, Object> sConfig = (Map<String, Object>) request.getAttribute("sConfig"); Map<String, Object> space = (Map<String, Object>) request.getAttribute("space"); if (Common.empty(sConfig.get("videophoto"))) { return showMessage(request, response, "no_open_videophoto"); }/*from w w w . j a va 2 s.c om*/ String videoPic = (String) space.get("videopic"); int videoStatus = (Integer) space.get("videostatus"); String oldVideoPhoto = null; if (!Common.empty(videoPic)) { oldVideoPhoto = cpService.getVideoPic(videoPic); request.setAttribute("videophoto", oldVideoPhoto); } try { if (submitCheck(request, "uploadsubmit")) { ServletInputStream sis = null; FileOutputStream fos = null; PrintWriter out = null; try { response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "no-store, private, post-check=0, pre-check=0, max-age=0"); response.setHeader("Pragma", "no-cache"); response.setContentType("text/html"); out = response.getWriter(); if (!Common.empty(videoStatus) && Common.empty(sConfig.get("videophotochange"))) { out.write("-1"); return null; } if (videoStatus == 0 && !Common.empty(videoPic)) { out.write("-2"); return null; } int uid = (Integer) sGlobal.get("supe_uid"); int timestamp = (Integer) sGlobal.get("timestamp"); String newFileName = Common.md5(String.valueOf(timestamp).substring(0, 7) + uid); String jchRoot = JavaCenterHome.jchRoot + "/"; File file = new File(jchRoot + "data/video/" + newFileName.substring(0, 1) + "/" + newFileName.substring(1, 2)); if (!file.exists() && !file.isDirectory() && !file.mkdirs()) { out.write("Can not write to the data/video folder!"); return null; } if (oldVideoPhoto != null) { file = new File(jchRoot + oldVideoPhoto); if (file.exists()) file.delete(); } sis = request.getInputStream(); fos = new FileOutputStream(jchRoot + cpService.getVideoPic(newFileName)); byte[] buffer = new byte[256]; int count = 0; while ((count = sis.read(buffer)) > 0) { fos.write(buffer, 0, count); } boolean videoPhotoCheck = Common.empty(sConfig.get("videophotocheck")); videoStatus = videoPhotoCheck ? 1 : 0; dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("spacefield") + " SET videopic='" + newFileName + "' WHERE uid='" + uid + "'"); dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("space") + " SET videostatus='" + videoStatus + "' WHERE uid='" + uid + "'"); List<String> sets = new ArrayList<String>(); Map<String, Integer> reward = Common.getReward("videophoto", false, 0, "", true, request, response); int credit = reward.get("credit"); int experience = reward.get("experience"); if (credit != 0) { sets.add("credit=credit+" + credit); } if (experience != 0) { sets.add("experience=experience+" + experience); } sets.add("updatetime=" + timestamp); if (sets.size() > 0) { dataBaseService.executeUpdate("UPDATE " + JavaCenterHome.getTableName("space") + " SET " + Common.implode(sets, ",") + " WHERE uid='" + uid + "'"); } if (videoPhotoCheck) { out.write("2"); } else { out.write("1"); } return null; } catch (Exception e) { out.write("Upload an exception occurred during the"); return null; } finally { try { if (fos != null) { fos.flush(); fos.close(); fos = null; } if (sis != null) { sis.close(); sis = null; } if (out != null) { out.flush(); out.close(); out = null; } } catch (Exception e) { } } } } catch (Exception e) { return showMessage(request, response, e.getMessage()); } String op = request.getParameter("op"); if ("check".equals(op)) { if ((videoStatus > 0 && Common.empty(sConfig.get("videophotochange"))) || (videoStatus == 0 && !Common.empty(videoPic))) { request.getParameterMap().remove("op"); } else { String flashSrc = "image/videophoto.swf?post_url=" + Common.urlEncode(Common.getSiteUrl(request) + "cp.jsp") + "&agrs=" + Common.urlEncode("ac=videophoto&uid=" + sGlobal.get("supe_uid") + "&uploadsubmit=true&formhash=" + formHash(request)); String videoFlash = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" width=\"560\" height=\"390\" id=\"videoCheck\" align=\"middle\">" + "<param name=\"allowScriptAccess\" value=\"always\" />" + "<param name=\"scale\" value=\"exactfit\" />" + "<param name=\"wmode\" value=\"transparent\" />" + "<param name=\"quality\" value=\"high\" />" + "<param name=\"bgcolor\" value=\"#ffffff\" />" + "<param name=\"movie\" value=\"" + flashSrc + "\" />" + "<param name=\"menu\" value=\"false\" />" + "<embed src=\"" + flashSrc + "\" quality=\"high\" bgcolor=\"#ffffff\" width=\"560\" height=\"390\" name=\"videoCheck\" align=\"middle\" allowScriptAccess=\"always\" allowFullScreen=\"false\" scale=\"exactfit\" wmode=\"transparent\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />" + "</object>"; request.setAttribute("videoFlash", videoFlash); } } return include(request, response, sConfig, sGlobal, "cp_videophoto.jsp"); }