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:mobile.tiis.appv2.helpers.Utils.java

public static void appendParameter(StringBuilder sb, String key, String value) {
    if (isStringNotBlank(key) && isStringNotBlank(value)) {
        if (isStringNotBlank(sb)) {
            sb.append("&");
        }//w w  w.  j  a  v  a 2 s . c om
        sb.append(key).append("=");
        try {
            sb.append(URLEncoder.encode(value.trim(), "UTF-8"));
        } catch (UnsupportedEncodingException ex) {
            ex.printStackTrace();
        }
    }
}

From source file:com.oo58.game.UpdateUtils.java

/**
 * UTF-8ASCII3 /*from   w w  w .  j a  va 2  s  .co  m*/
 * @param text 
 * @param length 
 * @return
 */
public static ArrayList split(String text, int len) {
    try {
        return split(text, len, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.microsoft.projectoxford.face.rest.WebServiceRequest.java

public static String getUrl(String path, Map<String, Object> params) {
    StringBuffer url = new StringBuffer(path);

    boolean start = true;
    for (Map.Entry<String, Object> param : params.entrySet()) {
        if (start) {
            url.append("?");
            start = false;/* w  w w  . j av a 2  s.com*/
        } else {
            url.append("&");
        }

        try {
            url.append(param.getKey());
            url.append("=");
            url.append(URLEncoder.encode(param.getValue().toString(), "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    return url.toString();
}

From source file:de.mpg.escidoc.services.tools.scripts.person_grants.Util.java

/**
 * Queries an eSciDoc instance//from  w ww . j  av a  2 s . c  o m
 * 
 * @param url
 * @param query
 * @param adminUserName
 * @param adminPassword
 * @param frameworkUrl
 * @return
 */
public static Document queryFramework(String url, String query, String adminUserName, String adminPassword,
        String frameworkUrl) {
    try {
        DocumentBuilder documentBuilder;
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryImpl.newInstance();
        documentBuilderFactory.setNamespaceAware(true);
        documentBuilder = documentBuilderFactory.newDocumentBuilder();
        Document document = documentBuilder.newDocument();
        HttpClient client = new HttpClient();
        client.getParams().setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
        GetMethod getMethod = new GetMethod(url + "?query="
                + (query != null ? URLEncoder.encode(query, "UTF-8") : "") + "&eSciDocUserHandle="
                + Base64.encode(
                        getAdminUserHandle(adminUserName, adminPassword, frameworkUrl).getBytes("UTF-8")));
        System.out.println("Querying <" + url + "?query="
                + (query != null ? URLEncoder.encode(query, "UTF-8") : "") + "&eSciDocUserHandle="
                + Base64.encode(
                        getAdminUserHandle(adminUserName, adminPassword, frameworkUrl).getBytes("UTF-8")));
        client.executeMethod(getMethod);
        if (getMethod.getStatusCode() == 200) {
            document = documentBuilder.parse(getMethod.getResponseBodyAsStream());
        } else {
            System.out.println("Error querying: Status " + getMethod.getStatusCode() + "\n"
                    + getMethod.getResponseBodyAsString());
        }
        return document;
    } catch (Exception e) {
        try {
            System.out.println("Error querying Framework <" + url + "?query="
                    + (query != null ? URLEncoder.encode(query, "UTF-8") : "") + "&eSciDocUserHandle="
                    + Base64.encode(
                            getAdminUserHandle(adminUserName, adminPassword, frameworkUrl).getBytes("UTF-8"))
                    + ">");
        } catch (UnsupportedEncodingException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        e.printStackTrace();
    }
    return null;
}

From source file:com.znsx.util.licence.LicenceUtil.java

public static License parseLicense(InputStream in) {
    try {/*from   w  w  w.  j  a v a 2 s.  c  o m*/
        InputStreamReader reader = new InputStreamReader(in, "utf8");
        BufferedReader br = new BufferedReader(reader);
        String projectName = br.readLine();
        projectName = projectName.substring(projectName.indexOf(":") + 2);
        String linkMan = br.readLine();
        linkMan = linkMan.substring(linkMan.indexOf(":") + 2);
        String contact = br.readLine();
        contact = contact.substring(contact.indexOf(":") + 2);
        String userAmount = br.readLine();
        userAmount = userAmount.substring(userAmount.indexOf("=") + 2, userAmount.length());
        String cameraAmount = br.readLine();
        cameraAmount = cameraAmount.substring(cameraAmount.indexOf("=") + 2, cameraAmount.length());
        String deviceAmount = br.readLine();
        deviceAmount = deviceAmount.substring(deviceAmount.indexOf("=") + 2, deviceAmount.length());
        String expireTime = br.readLine();
        expireTime = expireTime.substring(expireTime.indexOf("=") + 2, expireTime.length());
        String motherBoardList = br.readLine();
        motherBoardList = motherBoardList.substring(motherBoardList.indexOf("=") + 2, motherBoardList.length());
        String cpuidList = br.readLine();
        cpuidList = cpuidList.substring(cpuidList.indexOf("=") + 2, cpuidList.length());
        String macList = br.readLine();
        macList = macList.substring(macList.indexOf("=") + 2, macList.length());
        String signature = br.readLine();
        signature = signature.substring(signature.indexOf(":") + 2, signature.length());

        License license = new License();
        license.setProjectName(projectName);
        license.setLinkMan(linkMan);
        license.setContact(contact);
        license.setCameraAmount(cameraAmount);
        license.setCpuidList(cpuidList);
        license.setExpireTime(expireTime);
        license.setMacList(macList);
        license.setMotherBoardList(motherBoardList);
        license.setDeviceAmount(deviceAmount);
        license.setSignature(signature);
        license.setUserAmount(userAmount);
        return license;
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        throw new BusinessException(ErrorCode.ENCODING_ERROR, "License file encode is not UTF-8 !");
    } catch (IOException e) {
        e.printStackTrace();
        throw new BusinessException(ErrorCode.NETWORK_IO_ERROR, "Network IO error !");
    } catch (Exception e) {
        e.printStackTrace();
        throw new BusinessException(ErrorCode.LICENSE_FORMAT_INVALID, "Format of license file invalid !");
    } finally {
        try {
            if (null != in) {
                in.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.googlecode.dex2jar.test.TestUtils.java

public static void verify(final ClassReader cr)
        throws AnalyzerException, IllegalArgumentException, IllegalAccessException {
    try {//from   w w  w  .  j  av  a2 s .c om
        verify(cr, new PrintWriter(new OutputStreamWriter(System.out, "UTF-8")));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}

From source file:cn.quickj.Setting.java

/**
 * setting.xml???//from www .j a va 2 s  .c  om
 * 
 * @param rootPath
 * @throws Exception
 * 
 */
public static void load(String rootPath) throws Exception {
    if (initFinished == true)
        return;
    XMLConfiguration config;
    String settingPath = "";
    if (rootPath == null) {
        // WebApplication Setting.xml
        String classPath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
        Pattern p = Pattern.compile("([\\S]+/)WEB-INF[\\S]+");
        Matcher m = p.matcher(classPath);

        if (m.find())
            webRoot = m.group(1);
    } else
        webRoot = rootPath;
    try {
        webRoot = URLDecoder.decode(webRoot, "utf-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    if (webRoot.endsWith(".xml")) {
        settingPath = webRoot;
        int lastPos = webRoot.lastIndexOf('\\');
        if (lastPos == -1)
            lastPos = webRoot.lastIndexOf('/');
        webRoot = webRoot.substring(0, lastPos);
    } else {
        if (!webRoot.endsWith("/") && !webRoot.endsWith("\\"))
            webRoot = webRoot + "/";
        settingPath = webRoot + "WEB-INF/setting.xml";
    }

    log.info("Loading setting file:" + settingPath);
    config = new XMLConfiguration();
    // ??????
    config.setDelimiterParsingDisabled(true);
    config.load(settingPath);

    /*
     * @Deprecated
     * ????unittest?runserver?
     * war?XML? String strRunMode =
     * config.getString("runmode", "development"); if
     * (strRunMode.equals("production")) runMode = PROD_MODE; else if
     * (strRunMode.equals("test")) runMode = TEST_MODE; else runMode =
     * DEV_MODE;
     */
    String strRunMode = getRunMode();

    packageRoot = config.getString("package", packageRoot);
    fieldBySetter = config.getBoolean("web.fieldBySetter", false);
    DEFAULT_CHARSET = config.getString("web.charset", "utf-8");
    longDateFormat = config.getString("web.long-dateformat", "yyyy-MM-dd HH:mm:ss");
    license = config.getString("license");
    shortDateFormat = config.getString("web.short-dateformat", "yyyy-MM-dd");
    String strLocale = config.getString("web.locale", Locale.getDefault().getDisplayName());
    theme = config.getString("web.theme");
    locale = new Locale(strLocale);
    sessionClass = config.getString("web.session.class", "cn.quickj.session.MemHttpSession");
    sessionDomain = config.getString("web.session.domain", null);
    sessionTimeOut = config.getInt("web.session.timeout", 30 * 60);
    defaultUri = config.getString("web.defaultUri");
    uploadDir = config.getString("web.upload.directory", System.getProperty("java.io.tmpdir"));
    uploadMaxSize = config.getInt("web.upload.max-size", 4096);
    jdbcDriver = config.getString("database." + strRunMode + ".driver", "");
    usedb = (jdbcDriver.length() != 0);
    jdbcUser = config.getString("database." + strRunMode + ".user", "root");
    jdbcUrl = config.getString("database." + strRunMode + ".url", "");
    jdbcPassword = config.getString("database." + strRunMode + ".password", "");
    maxActive = config.getInt("database." + strRunMode + ".pool.maxActive", 10);
    initActive = config.getInt("database." + strRunMode + ".pool.initActive", 2);
    maxIdle = config.getInt("database." + strRunMode + ".pool.maxIdle", 1800);
    dialect = config.getString("database." + strRunMode + ".dialect", null);
    tablePrefix = config.getString("database.prefix", "");

    cacheClass = config.getString("cache.class", "cn.quickj.cache.SimpleCache");
    cacheParam = config.getString("cache.param", "capacity=50000");
    // ??
    queueEnabled = "true".equalsIgnoreCase(config.getString("queue.enable", "false"));
    queueParam = config.getString("queue.param", "capacity=50000");
    loadPlugin(config);
    loadApplicationConfig();
    initFinished = true;
}

From source file:de.fmaul.android.cmis.utils.StorageUtils.java

public static void storeFeedInCache(Application app, String url, Document doc, String workspace)
        throws StorageException {
    File cacheFile = getFeedFile(app, workspace, md5(url));
    ensureOrCreatePathAndFile(cacheFile);

    try {// w  ww  .  j a v  a 2s  .c  om
        XMLWriter writer = new XMLWriter(new FileOutputStream(cacheFile));
        writer.write(doc);
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:devbox.com.br.minercompanion.LoginActivity.java

public static String POST(String url, String data) {
    InputStream inputStream = null;
    String result = "";

    try {/* w  w w . j  a v  a  2  s . co  m*/

        // 1. create HttpClient
        HttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());

        // 2. make POST request to the given URL
        HttpPost httpPost = new HttpPost(url);

        try {
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            //String usuarios = jsonParser.getAllUsuariosAsJson().toString();

            //Log.i("USUARIOS", usuarios);
            Log.d("Dados sendo enviado: ", data);

            //params.add(new BasicNameValuePair("usuarios", usuarios));
            params.add(new BasicNameValuePair("login", data));

            httpPost.setEntity(new UrlEncodedFormEntity(params));

            HttpResponse response = httpclient.execute(httpPost);

            inputStream = response.getEntity().getContent();

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

        // 10. convert inputstream to string
        if (inputStream != null)
            result = convertInputStreamToString(inputStream);
        else
            result = "Resultado Nulo";

    } catch (Exception e) {
        Log.i("InputStream", e.getLocalizedMessage());
    }

    // 11. return result
    return result;
}

From source file:cn.mdict.utils.IOUtil.java

public static boolean loadStringFromStream(InputStream inputStream, String encoding, StringBuffer str) {
    boolean result = true;
    int buffer_size = 512;
    char[] char_buf = new char[buffer_size];
    BufferedReader in = null;/*from   w  w  w.  j a v a2s  .c o m*/
    try {
        in = new BufferedReader(new InputStreamReader(inputStream, encoding));
        int read_size;
        while ((read_size = in.read(char_buf)) != -1) {
            str.append(char_buf, 0, read_size);
        }
    } catch (UnsupportedEncodingException e) {
        result = false;
        e.printStackTrace();
    } catch (IOException e) {
        result = false;
        e.printStackTrace();
    } finally {
        if (in != null)
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }
    return result;
}