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:cl.nic.dte.util.XMLUtil.java

public static byte[] getBytesXML(XmlObject xml) {
    try {/*from w w w  . j  av a2  s  .c  om*/
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        XmlOptions opts = new XmlOptions();
        HashMap<String, String> namespaces = new HashMap<String, String>();
        namespaces.put("", "http://www.sii.cl/SiiDte");
        opts.setCharacterEncoding("ISO-8859-1");
        opts.setSaveImplicitNamespaces(namespaces);
        opts.setSaveOuter();
        opts.setSavePrettyPrint();
        opts.setSavePrettyPrintIndent(0);
        opts.setSaveNoXmlDecl();

        xml.save(out, opts);

        return out.toString("ISO-8859-1").getBytes("ISO-8859-1");
    } catch (UnsupportedEncodingException e) {
        // Nunca debe invocarse
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        // Nunca debe invocarse
        e.printStackTrace();
        return null;
    }
}

From source file:cl.nic.dte.util.XMLUtil.java

/**
 * Obtiene una representaci&oacute;n "limpia" de un elemento XML, esto
 * quiere decir, sin espacios ni nuevas l&iacute;neas entre tags. Este
 * m&eacute;todo se utiliza en la generaci&oacute;n PDF del &lt;TED&gt;.
 * // w  w w  .ja v  a  2s . c  o m
 * @param xml
 *            El nodo XML
 * @return El arreglo de bytes codificado con ISO-8859-1 (norma exigida por
 *         SII) del contenido del nodo (incluyendo los tags y caracteres
 *         especiales de XML como &amp;).
 */
public static byte[] getCleanedII(XmlObject xml) {
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        XmlOptions opts = new XmlOptions();
        HashMap<String, String> namespaces = new HashMap<String, String>();
        namespaces.put("", "http://www.sii.cl/SiiDte");
        opts.setCharacterEncoding("ISO-8859-1");
        opts.setSaveImplicitNamespaces(namespaces);
        opts.setSaveOuter();
        //opts.setSavePrettyPrint();
        //opts.setSavePrettyPrintIndent(0);
        opts.setSaveNoXmlDecl();
        xml.save(out, opts);

        return out.toByteArray();
    } catch (UnsupportedEncodingException e) {
        // Nunca debe invocarse
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        // Nunca debe invocarse
        e.printStackTrace();
        return null;
    }
}

From source file:cl.nic.dte.util.XMLUtil.java

/**
 * Obtiene una representaci&oacute;n "limpia" de un elemento XML, esto
 * quiere decir, sin espacios ni nuevas l&iacute;neas entre tags. Este
 * m&eacute;todo se utiliza en la generaci&oacute;n PDF del &lt;TED&gt;.
 * //from w ww  .  j  a v  a 2s. c  o  m
 * @param xml
 *            El nodo XML
 * @return El arreglo de bytes codificado con ISO-8859-1 (norma exigida por
 *         SII) del contenido del nodo (incluyendo los tags y caracteres
 *         especiales de XML como &amp;).
 */
public static byte[] getCleaned(XmlObject xml) {
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        XmlOptionCharEscapeMap escapes = new XmlOptionCharEscapeMap();
        escapes.addMapping('\'', XmlOptionCharEscapeMap.PREDEF_ENTITY);
        escapes.addMapping('&', XmlOptionCharEscapeMap.PREDEF_ENTITY);

        XmlOptions opts = new XmlOptions();
        HashMap<String, String> namespaces = new HashMap<String, String>();
        namespaces.put("", "http://www.sii.cl/SiiDte");
        opts.setCharacterEncoding("ISO-8859-1");
        opts.setSaveImplicitNamespaces(namespaces);
        opts.setSaveOuter();
        opts.setSavePrettyPrint();
        opts.setSavePrettyPrintIndent(0);
        opts.setSaveNoXmlDecl();

        opts.setSaveSubstituteCharacters(escapes);

        xml.save(out, opts);

        return out.toString("ISO-8859-1").replaceAll("\n", "").getBytes("ISO-8859-1");
        // return out.toString("ISO-8859-1").getBytes("ISO-8859-1");
    } catch (UnsupportedEncodingException e) {
        // Nunca debe invocarse
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        // Nunca debe invocarse
        e.printStackTrace();
        return null;
    } catch (XmlException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.gnizr.core.util.GnizrDaoUtil.java

public static String encodeURI(String uri) {
    try {/* w  w w .j  a v  a 2  s  .  c o  m*/
        return URLEncoder.encode(uri, "UTF-8");
    } catch (UnsupportedEncodingException e) {

        e.printStackTrace();
    }
    return null;

}

From source file:com.ai.runner.center.pay.web.business.payment.util.third.unionpay.sdk.SDKUtil.java

/**
 * ?fileContent?  base64DEFLATE?<br>
 * ??<br>//ww w  . j a va  2s  .  c  o m
 * @param resData<br>
 * @param encoding ?encoding<br>   
 */
public static void deCodeFileContent(Map<String, String> resData, String filePathRoot, String encoding) {
    // ?
    String fileContent = resData.get(SDKConstants.param_fileContent);
    if (null != fileContent && !"".equals(fileContent)) {
        try {
            byte[] fileArray = SecureUtil.inflater(SecureUtil.base64Decode(fileContent.getBytes(encoding)));
            String filePath = null;
            if (SDKUtil.isEmpty(resData.get("fileName"))) {
                filePath = filePathRoot + File.separator + resData.get("merId") + "_" + resData.get("batchNo")
                        + "_" + resData.get("txnTime") + ".txt";
            } else {
                filePath = filePathRoot + File.separator + resData.get("fileName");
            }
            File file = new File(filePath);
            if (file.exists()) {
                file.delete();
            }
            file.createNewFile();
            FileOutputStream out = new FileOutputStream(file);
            out.write(fileArray, 0, fileArray.length);
            out.flush();
            out.close();

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.ai.runner.center.pay.web.business.payment.util.third.unionpay.sdk.SDKUtil.java

/**
 * ???customerInfo<br>//  w w  w. jav  a 2 s.  co  m
 * ????? customerInfo????cvn2??pin?<br>
 * @param customerInfoMap ?? key???value?,?<br>
 *        customerInfoMap.put("certifTp", "01");               //?<br>
      customerInfoMap.put("certifId", "341126197709218366");   //???<br>
      customerInfoMap.put("customerNm", "?");            //??<br>
      customerInfoMap.put("phoneNo", "13552535506");         //?<br>
      customerInfoMap.put("smsCode", "123456");               //??<br>
      customerInfoMap.put("pin", "111111");                  //?<br>
      customerInfoMap.put("cvn2", "123");                    //??cvn2??<br>
      customerInfoMap.put("expired", "1711");                  // ???)<br>
 * @param accNo  customerInfoMap?????,customerInfoMap??pin???<br>
 * @param encoding ?encoding<br>              
 * @return base64????<br>
 */
public static String getCustomerInfo(Map<String, String> customerInfoMap, String accNo, String encoding) {

    StringBuffer sf = new StringBuffer("{");

    for (Iterator<String> it = customerInfoMap.keySet().iterator(); it.hasNext();) {
        String key = it.next();
        String value = customerInfoMap.get(key);
        if (key.equals("pin")) {
            if (null == accNo || "".equals(accNo.trim())) {
                LogUtil.writeLog(
                        "??PINgetCustomerInfoWithEncrypt???");
                return "{}";
            } else {
                value = SDKUtil.encryptPin(accNo, value, encoding);
            }
        }
        if (it.hasNext())
            sf.append(key + SDKConstants.EQUAL + value + SDKConstants.AMPERSAND);
        else
            sf.append(key + SDKConstants.EQUAL + value);
    }
    sf.append("}");

    String customerInfo = sf.toString();
    LogUtil.writeLog("customerInfo" + customerInfo);
    try {
        return new String(SecureUtil.base64Encode(sf.toString().getBytes(encoding)));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return customerInfo;
}

From source file:com.haoqee.chatsdk.net.Utility.java

/**
 * Construct a url encoded entity by parameters .
 * //w  ww .ja  v a2 s . c om
 * @param bundle
 *            :parameters key pairs
 * @return UrlEncodedFormEntity: encoed entity
 */
public static UrlEncodedFormEntity getPostParamters(Bundle bundle) {
    if (bundle == null || bundle.isEmpty()) {
        return null;
    }
    try {
        List<NameValuePair> form = new ArrayList<NameValuePair>();
        for (String key : bundle.keySet()) {
            form.add(new BasicNameValuePair(key, bundle.getString(key)));
        }
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(form, "UTF-8");
        return entity;
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.ai.runner.center.pay.web.business.payment.util.third.unionpay.sdk.SDKUtil.java

/**
 * ???customerInfo???? pinphoneNocvn2expired <br>
 *  <br>//from   w  w  w .ja  v a 2s. c  o  m
 * @param customerInfoMap ?? key???value?,? <br>
 *        customerInfoMap.put("certifTp", "01");               //? <br>
      customerInfoMap.put("certifId", "341126197709218366");   //??? <br>
      customerInfoMap.put("customerNm", "?");            //?? <br>
      customerInfoMap.put("smsCode", "123456");               //?? <br>
      customerInfoMap.put("pin", "111111");                  //? <br>
      customerInfoMap.put("phoneNo", "13552535506");         //? <br>
      customerInfoMap.put("cvn2", "123");                    //??cvn2? <br>
      customerInfoMap.put("expired", "1711");                  // ?? <br>
 * @param accNo  customerInfoMap?????,customerInfoMap??PIN???<br>
 * @param encoding ?encoding
 * @return base64???? <br>
 */
public static String getCustomerInfoWithEncrypt(Map<String, String> customerInfoMap, String accNo,
        String encoding) {

    StringBuffer sf = new StringBuffer("{");
    //??
    StringBuffer encryptedInfoSb = new StringBuffer("");

    for (Iterator<String> it = customerInfoMap.keySet().iterator(); it.hasNext();) {
        String key = it.next();
        String value = customerInfoMap.get(key);
        if (key.equals("phoneNo") || key.equals("cvn2") || key.equals("expired")) {
            encryptedInfoSb.append(key + SDKConstants.EQUAL + value + SDKConstants.AMPERSAND);
        } else {
            if (key.equals("pin")) {
                if (null == accNo || "".equals(accNo.trim())) {
                    LogUtil.writeLog(
                            "??PINgetCustomerInfoWithEncrypt???");
                    return "{}";
                } else {
                    value = SDKUtil.encryptPin(accNo, value, encoding);
                }
            }
            if (it.hasNext())
                sf.append(key + SDKConstants.EQUAL + value + SDKConstants.AMPERSAND);
            else
                sf.append(key + SDKConstants.EQUAL + value);
        }
    }

    if (!encryptedInfoSb.toString().equals("")) {
        //?&?
        encryptedInfoSb.setLength(encryptedInfoSb.length() - 1);

        LogUtil.writeLog("customerInfo encryptedInfo" + encryptedInfoSb.toString());
        if (sf.toString().equals("{")) //phoneNocvn2expired?&
            sf.append("encryptedInfo" + SDKConstants.EQUAL);
        else
            sf.append(SDKConstants.AMPERSAND + "encryptedInfo" + SDKConstants.EQUAL);

        sf.append(SDKUtil.encryptEpInfo(encryptedInfoSb.toString(), encoding));
    }
    sf.append("}");

    String customerInfo = sf.toString();
    LogUtil.writeLog("customerInfo" + customerInfo);
    try {
        return new String(SecureUtil.base64Encode(sf.toString().getBytes(encoding)));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return customerInfo;
}

From source file:marytts.util.string.StringUtils.java

public static InputStream toInputStream(String str) {
    ByteArrayInputStream stream = null;
    try {//from  w  w  w . j a  va  2  s . c  o  m
        stream = new ByteArrayInputStream(str.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return stream;
}

From source file:marytts.util.string.StringUtils.java

public static String urlEncode(String strRequest) {
    String encoded = strRequest;/*from  w  w  w . jav a2  s . c  om*/

    try {
        encoded = URLEncoder.encode(encoded, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return encoded;
}