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:hudson.plugins.jetty.security.Password.java

@SuppressFBWarnings({ "SF_SWITCH_FALLTHROUGH", "SF_SWITCH_NO_DEFAULT" })
public static String obfuscate(String s) {
    if (StringUtils.isEmpty(s)) {
        return "";
    }//from www . ja  v a 2s.com
    StringBuffer buf = new StringBuffer();
    byte[] b = new byte[0];
    try {
        b = (s == null) ? "".getBytes("UTF-8") : s.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    synchronized (buf) {
        buf.append(__OBFUSCATE);
        for (int i = 0; i < b.length; i++) {
            byte b1 = b[i];
            byte b2 = b[s.length() - (i + 1)];
            int i1 = 127 + b1 + b2;
            int i2 = 127 + b1 - b2;
            int i0 = i1 * 256 + i2;
            String x = Integer.toString(i0, 36);
            switch (x.length()) {
            case 1:
                buf.append('0');
            case 2:
                buf.append('0');
            case 3:
                buf.append('0');
            default:
                buf.append(x);
            }
        }
        return buf.toString();
    }
}

From source file:Main.java

public static void composeEmail(Context context, String email, String subject, String body) {
    try {/*  ww w  .  ja  v a 2 s. com*/
        String url = "mailto:";
        if (email != null) {
            url += email;
        }
        url += "?";

        if (subject != null) {
            String subjectEncoded = URLEncoder.encode(subject, "UTF-8");
            subjectEncoded = subjectEncoded.replace("+", "%20");
            url += "subject=" + subjectEncoded;
        }

        if (body != null) {
            if (subject != null) {
                url += "&";
            }
            String bodyEncoded = URLEncoder.encode(body, "UTF-8");
            bodyEncoded = bodyEncoded.replace("+", "%20");
            url += "body=" + bodyEncoded;
        }

        viewURL(context, url);
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.alibaba.wasp.util.ResultInHBasePrinter.java

public static void printTablesRs(String type, Configuration conf, String tablename, String indexName, Log LOG)
        throws IOException {
    StorageActionManager manager = new StorageActionManager(conf);

    String indexTableName = FConstants.WASP_TABLE_INDEX_PREFIX + tablename + FConstants.TABLE_ROW_SEP
            + indexName;//www . j a v  a2 s . c o  m

    try {
        LOG.info("rs begin " + type);
        // manager.scan(".META.", new Scan());
        // manager.scan(StorageTableNameBuilder.buildEntityTableName("TEST_TABLE"),
        // new Scan());
        // ResultScanner fmeters = manager.scan("_FMETA_", new Scan());
        ResultScanner indexrs = manager.scan(indexTableName, new Scan());
        ResultScanner rs = manager.scan(FConstants.WASP_TABLE_ENTITY_PREFIX + tablename, new Scan());
        // LOG.info("rs fmeta");
        // print(fmeters);
        LOG.info("rs table " + type);
        print(rs, LOG);
        LOG.info("rs index, table name = " + indexTableName);
        // WASP_INDEX_TEST_TABLE_test_index
        print(indexrs, LOG);
        LOG.info("rs end");
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    // TEST!!!
}

From source file:com.alta189.cyborg.commandkit.util.HttpUtil.java

public static String encode(String raw) {
    String result = null;/*from ww w.  jav  a2  s . co  m*/
    try {
        result = URLEncoder.encode(raw, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:com.alta189.cyborg.commandkit.util.HttpUtil.java

public static String decode(String raw) {
    String result = null;//www  . j  a  va  2 s .  c  om
    try {
        result = URLDecoder.decode(raw, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:com.tbggwp.imit.ImitTurn.java

static public ImitTurn unpersist(byte[] byteArray) {

    if (byteArray == null) {
        Log.d(TAG, "Empty array---possible bug.");
        return new ImitTurn();
    }/*  w w w  . j  av a2 s.  c  o m*/

    String st = null;
    try {
        st = new String(byteArray, "UTF-16");
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
        return null;
    }

    Log.d(TAG, "====UNPERSIST \n" + st);

    ImitTurn retVal = new ImitTurn();

    try {
        JSONObject obj = new JSONObject(st);

        if (obj.has("data")) {
            retVal.data = obj.getString("data");
        }
        if (obj.has("turnCounter")) {
            retVal.turnCounter = obj.getInt("turnCounter");
        }

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return retVal;
}

From source file:org.angellist.angellistmobile.ApiCalls.java

private static String GetData(String url) {
    byte[] result = null;
    String str = "";
    HttpClient client = new DefaultHttpClient();
    HttpGet get = new HttpGet(url);
    try {//from  w w w  . j  a  v a  2 s  .c o m

        HttpResponse response = client.execute(get);
        StatusLine statusLine = response.getStatusLine();
        if (statusLine.getStatusCode() == HttpURLConnection.HTTP_OK) {
            result = EntityUtils.toByteArray(response.getEntity());
            str = new String(result, "UTF-8");
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return str;

}

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

/**
 *  Cookie// w  w w  .  j a  v a2s. c  o m
 * 
 * @param name
 *            ??
 * @param value
 *            
 * @param maxAge
 *            ??
 */
public static void setCookie(HttpServletResponse response, String name, String value, int maxAge) {
    Cookie cookie = new Cookie(name, null);
    if (StringUtils.isNotBlank(SpringContextHolder.getApplicationContext().getApplicationName())) {
        cookie.setPath(SpringContextHolder.getApplicationContext().getApplicationName());
    } else {
        cookie.setPath("/");
    }
    cookie.setMaxAge(maxAge);
    try {
        cookie.setValue(URLEncoder.encode(value, "utf-8"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    response.addCookie(cookie);
}

From source file:com.example.skeletongoogle.SkeletonTurn.java

static public SkeletonTurn unpersist(byte[] byteArray) {

    if (byteArray == null) {
        Log.d(TAG, "Empty array---possible bug.");
        return new SkeletonTurn();
    }//ww w. j a v  a  2  s .  co m

    String st = null;
    try {
        st = new String(byteArray, "UTF-16");
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
        return null;
    }

    Log.d(TAG, "====UNPERSIST \n" + st);

    SkeletonTurn retVal = new SkeletonTurn();

    try {
        JSONObject obj = new JSONObject(st);

        if (obj.has("data")) {
            retVal.data = obj.getString("data");
        }
        if (obj.has("turnCounter")) {
            retVal.turnCounter = obj.getInt("turnCounter");
        }

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return retVal;
}

From source file:com.google.example.tbmpskeleton.SkeletonTurn.java

static public SkeletonTurn unpersist(byte[] byteArray) {

    if (byteArray == null) {
        Log.d(TAG, "Empty array---possible bug.");
        return new SkeletonTurn();
    }/* w ww  .j  av a2s.com*/

    String st = null;
    try {
        st = new String(byteArray, "UTF-8");
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
        return null;
    }

    Log.d(TAG, "====UNPERSIST \n" + st);

    SkeletonTurn retVal = new SkeletonTurn();

    try {
        JSONObject obj = new JSONObject(st);

        if (obj.has("data")) {
            retVal.data = obj.getString("data");
        }
        if (obj.has("turnCounter")) {
            retVal.turnCounter = obj.getInt("turnCounter");
        }

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return retVal;
}