Example usage for java.io UnsupportedEncodingException printStackTrace

List of usage examples for java.io UnsupportedEncodingException printStackTrace

Introduction

In this page you can find the example usage for java.io UnsupportedEncodingException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.xidu.framework.common.util.EnDecoderUtils.java

/**
 * encode input string by specific coding.
 * /*from ww w.  j a  v  a 2  s .  co  m*/
 * @Date : 2011-3-23
 * @param input
 *            - string
 * @param coding
 *            - the coding name
 * @return encoded string
 */
public static String encode(String input, String coding) {
    if (StringUtils.isBlank(input)) {
        return "";
    }
    try {
        return URLEncoder.encode(input, coding);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return input;
}

From source file:com.xidu.framework.common.util.EnDecoderUtils.java

/**
 * decode input string by specific coding.
 * /*from w  w w.j  a  v  a 2  s. c  o  m*/
 * @Date : 2011-3-23
 * @param input
 *            - string
 * @param coding
 *            - coding string
 * @return encoded string
 */
public static String decode(String input, String coding) {
    if (StringUtils.isBlank(input)) {
        return "";
    }
    try {
        return URLDecoder.decode(input, coding);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return input;
}

From source file:com.hangum.tadpole.commons.utils.zip.util.ZipUtils.java

/**
 * // w w w  . j av  a  2s. c  o m
 * @param base_dir
 * @param zipFile
 * @return
 * @throws Exception
 */
public static String pack(String base_dir, String zipFile) throws Exception {
    String zipFullPath = PublicTadpoleDefine.TEMP_DIR + zipFile + ".zip";
    ZipUtil.pack(new File(base_dir), new File(zipFullPath), new NameMapper() {
        public String map(String name) {
            try {
                if (!StringUtils.equals(name, StringEscapeUtils.escapeJava(name))) {
                    name = "download_files" + StringUtils.substring(name, StringUtils.lastIndexOf(name, '.'));
                }
                name = new String(name.getBytes(), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return name;
        }
    });

    return zipFullPath;
}

From source file:com.hongqiang.shop.common.utils.StringUtils.java

/**
 * ?/*from  w  w w . j  a  va2  s  . co  m*/
 * @param str 
 * @param length ?
 * @return
 */
public static String abbr(String str, int length) {
    if (str == null) {
        return "";
    }
    try {
        StringBuilder sb = new StringBuilder();
        int currentLength = 0;
        for (char c : str.toCharArray()) {
            currentLength += String.valueOf(c).getBytes("GBK").length;
            if (currentLength <= length - 3) {
                sb.append(c);
            } else {
                sb.append("...");
                break;
            }
        }
        return sb.toString();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:com.waku.mmdataextract.ComprehensiveSearch.java

@SuppressWarnings("deprecation")
private static MultipartEntity getMultipartEntity(String brandId, int pageNumber) {
    MultipartEntity reqEntity = new MultipartEntity();
    try {//ww  w . j a v a2  s .c  o  m
        reqEntity.addPart("flag", new StringBody("search"));
        reqEntity.addPart("brandId", new StringBody(brandId));
        reqEntity.addPart("currentPage", new StringBody(pageNumber + ""));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return reqEntity;
}

From source file:com.sniper.springmvc.utils.CookieUtils.java

/**
 * Cookie//from w w  w  .  jav  a 2 s .  c  om
 * 
 * @param request
 *            
 * @param response
 *            ?
 * @param name
 *            ??
 * @param isRemove
 *            ?
 * @return 
 */
public static String getCookie(HttpServletRequest request, HttpServletResponse response, String name,
        boolean isRemove) {
    String value = null;
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals(name)) {
                try {
                    value = URLDecoder.decode(cookie.getValue(), "utf-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                if (isRemove) {
                    cookie.setMaxAge(0);
                    response.addCookie(cookie);
                }
            }
        }
    }
    return value;
}

From source file:com.jeysan.modules.utils.encode.EncodeUtils.java

/**
 * ?????/* w ww.  j  av  a2s .com*/
 * @param source
 * @param charsetFrom
 * @param charsetTo
 * @return
 */
public static String encode(String source, String charsetFrom, String charsetTo) {
    try {
        return new String(source.getBytes(charsetFrom), charsetTo);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return source;
}

From source file:Main.java

static String nullPadString(final String original) {
    String output = original;/*w  w w . j av  a 2 s  . c o  m*/
    int remain = 0;
    try {
        remain = output.getBytes("UTF8").length % BLOCK_SIZE;
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    if (remain != 0) {
        remain = BLOCK_SIZE - remain;
        for (int i = 0; i < remain; i++) {
            output += PADDING;
        }
    }
    return output;
}

From source file:com.zimbra.common.util.CliUtil.java

public static boolean confirm(String msg) {
    System.out.print(msg + " [Y]es, [N]o: ");
    BufferedReader in;//w w  w  .j  a v a2  s .  c  o  m
    try {
        in = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
        String line = StringUtil.readLine(in);
        if ("y".equalsIgnoreCase(line) || "yes".equalsIgnoreCase(line)) {
            return true;
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:me.rgcjonas.portableMinecraftLauncher.Main.java

/**
 * returns the working directory for the portable minecraft instance
 *//*  w  ww .  j a  v a  2 s  .  c o  m*/
public static File getWorkingDirectory() {
    String path = Main.class.getProtectionDomain().getCodeSource().getLocation().getPath();
    String decodedPath = null;
    try {
        decodedPath = URLDecoder.decode(path, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        //this is very unlikely to happen, we're just making eclipse happy
        e.printStackTrace();
    }

    File ourDir = null;
    if (decodedPath.endsWith(".jar")) {
        //inside a jar file -> new dir named like the jar file
        ourDir = new File(decodedPath.substring(0, decodedPath.length() - 4));
    } else {
        //subdir 'minecraft'
        ourDir = new File(decodedPath, "minecraft");
    }

    //HACK: make it absolute here, since the other code requires
    File workDir = new File(ourDir.getAbsolutePath());
    return workDir;
}