| | |
| | | import com.google.gson.JsonSyntaxException; |
| | | import com.whyc.pojo.UserInf; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | import sun.misc.BASE64Decoder; |
| | |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.Locale; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | public class ActionUtil { |
| | | |
| | |
| | | public static SimpleDateFormat sdfwithday = new SimpleDateFormat("yyyy-MM-dd"); |
| | | public static SimpleDateFormat sdfwithtime = new SimpleDateFormat("HH:mm:ss"); |
| | | public static SimpleDateFormat sdfwithtime_yyyyMMdd_HH_mm_ss = new SimpleDateFormat(time_yyyyMMdd_HH_mm_ss); |
| | | |
| | | public static Object objeNull = null; |
| | | /* |
| | | * 获取HttpServletRequest |
| | | */ |
| | |
| | | inputStream = new FileInputStream(imgFile); |
| | | data = new byte[inputStream.available()]; |
| | | inputStream.read(data); |
| | | inputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }finally { |
| | | if(inputStream!=null){ |
| | | try { |
| | | inputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | // 加密 |
| | | BASE64Encoder encoder = new BASE64Encoder(); |
| | | return encoder.encode(data); |
| | |
| | | * @return |
| | | */ |
| | | public static boolean generateImage(String imgStr, String path) { |
| | | if (imgStr == null) { |
| | | return false; |
| | | boolean bl=false; |
| | | OutputStream out=null; |
| | | if (imgStr == null) { |
| | | bl=false; |
| | | } |
| | | BASE64Decoder decoder = new BASE64Decoder(); |
| | | try { |
| | |
| | | b[i] += 256; |
| | | } |
| | | } |
| | | OutputStream out = new FileOutputStream(path); |
| | | out = new FileOutputStream(path); |
| | | out.write(b); |
| | | out.flush(); |
| | | out.close(); |
| | | return true; |
| | | bl=true; |
| | | } catch (Exception e) { |
| | | return false; |
| | | } |
| | | bl=false; |
| | | }finally { |
| | | if(out!=null){ |
| | | try { |
| | | out.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | return bl; |
| | | } |
| | | |
| | | /** |
| | |
| | | public static String getLang() { |
| | | Locale locale = Locale.getDefault();//对Locale类实例化定义 |
| | | String lang = locale.getLanguage(); |
| | | //String lang = "zh"; |
| | | String str = (String) ActionUtil.getSession().getAttribute("lang"); |
| | | if (str != null) { |
| | | lang = str; |
| | | } |
| | | return lang; |
| | | } |
| | | |
| | | /** |
| | | * 输入验证:路径遍历,防止恶意符号影响文件体系 |
| | | * 过滤掉特殊字符 ”/\" : | * ? < >” |
| | | */ |
| | | public static String filterFileName(String fileName){ |
| | | Pattern pattern = Pattern.compile("[\\s\\\\/:\\*\\?\\\"<>\\|]"); |
| | | Matcher matcher = pattern.matcher(fileName); |
| | | fileName = matcher.replaceAll(""); |
| | | return FilenameUtils.getName(fileName); |
| | | } |
| | | |
| | | } |