Example usage for java.io UnsupportedEncodingException UnsupportedEncodingException

List of usage examples for java.io UnsupportedEncodingException UnsupportedEncodingException

Introduction

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

Prototype

public UnsupportedEncodingException() 

Source Link

Document

Constructs an UnsupportedEncodingException without a detail message.

Usage

From source file:br.com.caelum.vraptor.observer.upload.MockFileItem.java

@Override
public String getString(String charsetName) throws UnsupportedEncodingException {
    try {/*from   w  w w. ja  v  a2  s  .co m*/
        return new String(content, Charset.forName(charsetName));
    } catch (Exception e) {
        throw new UnsupportedEncodingException();
    }
}

From source file:org.colombbus.tangara.io.ScriptReader.java

private String extractScriptWithoutHeader(ByteBuffer content) throws UnsupportedEncodingException {
     for (Charset cs : COMMON_CHARSETS) {
         String decodedScript = tryDecodeBufferWithCharset(content, cs);
         if (containsWitnessChar(decodedScript)) {
             lastScriptCharset = cs;//from w  ww.  j ava2 s .c om
             return decodedScript;
         }
     }

     for (Charset cs : Charset.availableCharsets().values()) {
         String decodedScript = tryDecodeBufferWithCharset(content, cs);
         if (decodedScript != null) {
             lastScriptCharset = cs;
             return decodedScript;
         }
     }

     throw new UnsupportedEncodingException();
 }

From source file:com.zrlh.llkc.funciton.Http_Utility.java

/**
 * Construct a url encoded entity by parameters .
 * //from  ww  w .  j a va2s. c  om
 * @param bundle
 *            :parameters key pairs
 * @return UrlEncodedFormEntity: encoed entity
 */
public static UrlEncodedFormEntity getPostParamters(Bundle bundle) throws Exception {
    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) {
        throw new UnsupportedEncodingException();
    }
}

From source file:com.temenos.interaction.core.rim.TestHeaderHelper.java

@Test(expected = RuntimeException.class)
public void testEncodeQueryParametersURLEncoderThrowsException() throws Exception {
    PowerMockito.spy(HeaderHelper.class);
    PowerMockito.doThrow(new UnsupportedEncodingException()).when(HeaderHelper.class, "encodeQueryParameter",
            anyString());/*  w  ww.j  a  v  a2 s.  co m*/
    MultivaluedMap<String, String> values = new MultivaluedMapImpl<String>();
    values.add("customerNam=", "J&ck");
    values.add("customerName", "Jack");
    values.add("customerName", "Jill");
    values.add("trans&ction", "!0!");
    HeaderHelper.encodeMultivalueQueryParameters(values);
}

From source file:de.hybris.platform.addonsupport.controllers.page.AbstractAddOnPageController.java

/**
 * Checks request URL against properly resolved URL and returns null if url is proper or redirection string if not.
 * //  w  w  w .j  a  v a 2s  .co m
 * @param request
 *           - request that contains current URL
 * @param response
 *           response to write "301 Moved Permanently" status to if redirected
 * @param resolvedUrlPath
 *           - properly resolved URL
 * @param responseStatusAttributeName
 *           - response attribute name to which write the "301 Moved Permanently" status
 * @return null if url is properly resolved or redirection string if not
 * @throws UnsupportedEncodingException
 */
protected String checkRequestUrl(final HttpServletRequest request, final HttpServletResponse response,
        final String resolvedUrlPath, final String responseStatusAttributeName)
        throws UnsupportedEncodingException {
    try {
        final String resolvedUrl = response.encodeURL(request.getContextPath() + resolvedUrlPath);
        final String requestURI = URIUtil.decode(request.getRequestURI(), "utf-8");
        final String decoded = URIUtil.decode(resolvedUrl, "utf-8");
        if (StringUtils.isNotEmpty(requestURI) && requestURI.endsWith(decoded)) {
            return null;
        } else {
            request.setAttribute(responseStatusAttributeName, HttpStatus.MOVED_PERMANENTLY);
            final String queryString = request.getQueryString();
            if (queryString != null && !queryString.isEmpty()) {
                return "redirect:" + resolvedUrlPath + "?" + queryString;
            }
            return "redirect:" + resolvedUrlPath;
        }
    } catch (final URIException e) {
        throw new UnsupportedEncodingException();
    }
}

From source file:com.epam.cme.storefront.controllers.pages.AbstractPageController.java

/**
 * Checks request URL against properly resolved URL and returns null if url is proper or
 * redirection string if not.//from w ww  .j a  va 2s  . co m
 * 
 * @param request
 *            - request that contains current URL
 * @param response
 *            - response to write "301 Moved Permanently" status to if redirected
 * @param resolvedUrl
 *            - properly resolved URL
 * @return null if url is properly resolved or redirection string if not
 * @throws UnsupportedEncodingException
 */
protected String checkRequestUrl(final HttpServletRequest request, final HttpServletResponse response,
        final String resolvedUrl) throws UnsupportedEncodingException {
    try {
        final String requestURI = URIUtil.decode(request.getRequestURI(), "utf-8");
        final String decoded = URIUtil.decode(resolvedUrl, "utf-8");
        if (StringUtils.isNotEmpty(requestURI) && requestURI.endsWith(decoded)) {
            return null;
        } else {
            request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, HttpStatus.MOVED_PERMANENTLY);
            final String queryString = request.getQueryString();
            if (queryString != null && !queryString.isEmpty()) {
                return "redirect:" + resolvedUrl + "?" + queryString;
            }
            return "redirect:" + resolvedUrl;
        }
    } catch (final URIException e) {
        throw new UnsupportedEncodingException();
    }
}

From source file:it.govpay.model.Versamento.java

public static Causale decode(String encodedCausale) throws UnsupportedEncodingException {
    if (encodedCausale == null || encodedCausale.trim().isEmpty())
        return null;

    String[] causaleSplit = encodedCausale.split(" ");
    if (causaleSplit[0].equals("01")) {
        CausaleSemplice causale = new Versamento().new CausaleSemplice();
        if (causaleSplit.length > 1 && causaleSplit[1] != null) {
            causale.setCausale(new String(Base64.decodeBase64(causaleSplit[1].getBytes()), "UTF-8"));
            return causale;
        } else {/*from w w w .j a  v  a2  s  .c o m*/
            return null;
        }
    }

    if (causaleSplit[0].equals("02")) {
        List<String> spezzoni = new ArrayList<String>();
        for (int i = 1; i < causaleSplit.length; i++) {
            spezzoni.add(new String(Base64.decodeBase64(causaleSplit[i].getBytes()), "UTF-8"));
        }
        CausaleSpezzoni causale = new Versamento().new CausaleSpezzoni();
        causale.setSpezzoni(spezzoni);
        return causale;
    }

    if (causaleSplit[0].equals("03")) {
        List<String> spezzoni = new ArrayList<String>();
        List<BigDecimal> importi = new ArrayList<BigDecimal>();

        for (int i = 1; i < causaleSplit.length; i = i + 2) {
            spezzoni.add(new String(Base64.decodeBase64(causaleSplit[i].getBytes()), "UTF-8"));
            importi.add(BigDecimal.valueOf(Double
                    .parseDouble(new String(Base64.decodeBase64(causaleSplit[i + 1].getBytes()), "UTF-8"))));
        }
        CausaleSpezzoniStrutturati causale = new Versamento().new CausaleSpezzoniStrutturati();
        causale.setSpezzoni(spezzoni);
        causale.setImporti(importi);
        return causale;
    }
    throw new UnsupportedEncodingException();
}

From source file:com.exxonmobile.ace.hybris.storefront.controllers.pages.AbstractPageController.java

/**
 * Checks request URL against properly resolved URL and returns null if url is proper or redirection string if not.
 * //from  w w w  .ja  v a  2 s  .com
 * @param request
 *           - request that contains current URL
 * @param response
 *           - response to write "301 Moved Permanently" status to if redirected
 * @param resolvedUrlPath
 *           - properly resolved URL
 * @return null if url is properly resolved or redirection string if not
 * @throws UnsupportedEncodingException
 */
protected String checkRequestUrl(final HttpServletRequest request, final HttpServletResponse response,
        final String resolvedUrlPath) throws UnsupportedEncodingException {
    try {
        final String resolvedUrl = response.encodeURL(request.getContextPath() + resolvedUrlPath);
        final String requestURI = URIUtil.decode(request.getRequestURI(), "utf-8");
        final String decoded = URIUtil.decode(resolvedUrl, "utf-8");
        if (StringUtils.isNotEmpty(requestURI) && requestURI.endsWith(decoded)) {
            return null;
        } else {
            request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, HttpStatus.MOVED_PERMANENTLY);
            final String queryString = request.getQueryString();
            if (queryString != null && !queryString.isEmpty()) {
                return "redirect:" + resolvedUrlPath + "?" + queryString;
            }
            return "redirect:" + resolvedUrlPath;
        }
    } catch (final URIException e) {
        throw new UnsupportedEncodingException();
    }
}

From source file:org.jivesoftware.community.util.StringUtils.java

public static String URLEncode(String original, String charset) throws UnsupportedEncodingException {
    if (original == null)
        return null;
    byte octets[];
    try {/*from  www  . jav a2  s  .c o m*/
        octets = original.getBytes(charset);
    } catch (UnsupportedEncodingException error) {
        throw new UnsupportedEncodingException();
    }
    StringBuffer buf = new StringBuffer(octets.length);
    byte arr$[] = octets;
    int len$ = arr$.length;
    for (int i$ = 0; i$ < len$; i$++) {
        byte octet = arr$[i$];
        char c = (char) octet;
        if (allowed_query.get(c)) {
            buf.append(c);
        } else {
            buf.append('%');
            char hexadecimal = Character.forDigit(octet >> 4 & 0xf, 16);
            buf.append(Character.toUpperCase(hexadecimal));
            hexadecimal = Character.forDigit(octet & 0xf, 16);
            buf.append(Character.toUpperCase(hexadecimal));
        }
    }

    return buf.toString();
}

From source file:com.android.messaging.mmslib.pdu.CharacterSets.java

/**
 * Map an MIBEnum number to the name of the charset which this number
 * is assigned to by IANA.//from   w  w  w  .  j a  va  2s  .c  o m
 *
 * @param mibEnumValue An IANA assigned MIBEnum number.
 * @return The name string of the charset.
 */
public static String getMimeName(final int mibEnumValue) throws UnsupportedEncodingException {
    final String name = MIBENUM_TO_NAME_MAP.get(mibEnumValue);
    if (name == null) {
        throw new UnsupportedEncodingException();
    }
    return name;
}