Java Code Examples for org.apache.commons.codec.DecoderException#getMessage()

The following examples show how to use org.apache.commons.codec.DecoderException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebClient.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
private WebResponse makeWebResponseForDataUrl(final WebRequest webRequest) throws IOException {
    final URL url = webRequest.getUrl();
    final List<NameValuePair> responseHeaders = new ArrayList<>();
    final DataURLConnection connection;
    try {
        connection = new DataURLConnection(url);
    }
    catch (final DecoderException e) {
        throw new IOException(e.getMessage());
    }
    responseHeaders.add(new NameValuePair(HttpHeader.CONTENT_TYPE_LC,
        connection.getMediaType() + ";charset=" + connection.getCharset()));

    try (InputStream is = connection.getInputStream()) {
        final DownloadedContent downloadedContent =
                HttpWebConnection.downloadContent(is, getOptions().getMaxInMemory());
        final WebResponseData data = new WebResponseData(downloadedContent, 200, "OK", responseHeaders);
        return new WebResponse(data, url, webRequest.getHttpMethod(), 0);
    }
}
 
Example 2
Source File: WebClient.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
private WebResponse makeWebResponseForDataUrl(final WebRequest webRequest) throws IOException {
    final URL url = webRequest.getUrl();
    final List<NameValuePair> responseHeaders = new ArrayList<>();
    final DataURLConnection connection;
    try {
        connection = new DataURLConnection(url);
    }
    catch (final DecoderException e) {
        throw new IOException(e.getMessage());
    }
    responseHeaders.add(new NameValuePair(HttpHeader.CONTENT_TYPE_LC,
        connection.getMediaType() + ";charset=" + connection.getCharset()));

    try (InputStream is = connection.getInputStream()) {
        final DownloadedContent downloadedContent =
                HttpWebConnection.downloadContent(is, getOptions().getMaxInMemory());
        final WebResponseData data = new WebResponseData(downloadedContent, 200, "OK", responseHeaders);
        return new WebResponse(data, url, webRequest.getHttpMethod(), 0);
    }
}
 
Example 3
Source File: URIUtil.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Decode url encoded string.
 * @param escaped encoded string
 * @return decoded string
 * @throws IOException on error
 */
public static String decode(String escaped) throws IOException {
    try {
        return getString(URLCodec.decodeUrl(getAsciiBytes(escaped)));
    } catch (DecoderException e) {
        throw new IOException(e.getMessage());
    }
}
 
Example 4
Source File: AbstractChecksumCompute.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Checksum compute(final String data, final TransferStatus status) throws ChecksumException {
    try {
        return this.compute(new ByteArrayInputStream(Hex.decodeHex(data.toCharArray())), status);
    }
    catch(DecoderException e) {
        throw new ChecksumException(LocaleFactory.localizedString("Checksum failure", "Error"), e.getMessage(), e);
    }
}
 
Example 5
Source File: InitializationRequestElement.java    From ebics-java-client with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Decodes an hexadecimal input.
 * @param hex the hexadecimal input
 * @return the decoded hexadecimal value
 * @throws EbicsException
 */
protected byte[] decodeHex(byte[] hex) throws EbicsException {
  if (hex == null) {
    throw new EbicsException("Bank digest is empty, HPB request must be performed before");
  }

  try {
    return Hex.decodeHex((new String(hex)).toCharArray());
  } catch (DecoderException e) {
    throw new EbicsException(e.getMessage());
  }
}
 
Example 6
Source File: InitializationRequestElement.java    From axelor-open-suite with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Decodes an hexadecimal input.
 *
 * @param hex the hexadecimal input
 * @return the decoded hexadecimal value
 * @throws EbicsException
 */
protected byte[] decodeHex(byte[] hex) throws AxelorException {
  if (hex == null) {
    throw new AxelorException(
        TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
        "Bank digest is empty, HPB request must be performed before");
  }

  try {
    return Hex.decodeHex((new String(hex)).toCharArray());
  } catch (DecoderException e) {
    throw new AxelorException(
        e.getCause(), TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, e.getMessage());
  }
}
 
Example 7
Source File: URIUtil.java    From bintray-client-java with Apache License 2.0 5 votes vote down vote up
/**
 * Unescape and decode a given string regarded as an escaped string with the
 * default protocol charset.
 *
 * @param escaped a string
 * @return the unescaped string
 * @throws HttpException if the string cannot be decoded (invalid)
 */
public static String decode(String escaped) throws HttpException {
    try {
        byte[] rawdata = URLCodec.decodeUrl(EncodingUtils.getAsciiBytes(escaped));
        return EncodingUtils.getString(rawdata, UTF8_CHARSET_NAME);
    } catch (DecoderException e) {
        throw new HttpException(e.getMessage());
    }
}
 
Example 8
Source File: URIUtil.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Unescape and decode a given string regarded as an escaped string with the
 * default protocol charset.
 *
 * @param escaped a string
 * @return the unescaped string
 * 
 * @throws URIException if the string cannot be decoded (invalid)
 * 
 * @see URI#getDefaultProtocolCharset
 */
public static String decode(String escaped) throws URIException {
    try {
        byte[] rawdata = URLCodec.decodeUrl(EncodingUtil.getAsciiBytes(escaped));
        return EncodingUtil.getString(rawdata, URI.getDefaultProtocolCharset());
    } catch (DecoderException e) {
        throw new URIException(e.getMessage());
    }
}
 
Example 9
Source File: URI.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Decodes URI encoded string.
 *
 * This is a two mapping, one from URI characters to octets, and
 * subsequently a second from octets to original characters:
 * <p><blockquote><pre>
 *   URI character sequence->octet sequence->original character sequence
 * </pre></blockquote><p>
 *
 * A URI must be separated into its components before the escaped
 * characters within those components can be allowedly decoded.
 * <p>
 * Notice that there is a chance that URI characters that are non UTF-8
 * may be parsed as valid UTF-8.  A recent non-scientific analysis found
 * that EUC encoded Japanese words had a 2.7% false reading; SJIS had a
 * 0.0005% false reading; other encoding such as ASCII or KOI-8 have a 0%
 * false reading.
 * <p>
 * The percent "%" character always has the reserved purpose of being
 * the escape indicator, it must be escaped as "%25" in order to be used
 * as data within a URI.
 * <p>
 * The unescape method is internally performed within this method.
 *
 * @param component the URI character sequence
 * @param charset the protocol charset
 * @return original character sequence
 * @throws URIException incomplete trailing escape pattern or unsupported
 * character encoding
 * 
 * @since 3.0
 */
protected static String decode(String component, String charset) 
    throws URIException {
    if (component == null) {
        throw new IllegalArgumentException("Component array of chars may not be null");
    }
    byte[] rawdata = null;
    try { 
        rawdata = URLCodec.decodeUrl(EncodingUtil.getAsciiBytes(component));
    } catch (DecoderException e) {
        throw new URIException(e.getMessage());
    }
    return EncodingUtil.getString(rawdata, charset);
}
 
Example 10
Source File: URI.java    From bintray-client-java with Apache License 2.0 3 votes vote down vote up
/**
 * Decodes URI encoded string.
 * <p/>
 * This is a two mapping, one from URI characters to octets, and
 * subsequently a second from octets to original characters:
 * <p><blockquote><pre>
 *   URI character sequence->octet sequence->original character sequence
 * </pre></blockquote><p>
 * <p/>
 * A URI must be separated into its components before the escaped
 * characters within those components can be allowedly decoded.
 * <p/>
 * Notice that there is a chance that URI characters that are non UTF-8
 * may be parsed as valid UTF-8.  A recent non-scientific analysis found
 * that EUC encoded Japanese words had a 2.7% false reading; SJIS had a
 * 0.0005% false reading; other encoding such as ASCII or KOI-8 have a 0%
 * false reading.
 * <p/>
 * The percent "%" character always has the reserved purpose of being
 * the escape indicator, it must be escaped as "%25" in order to be used
 * as data within a URI.
 * <p/>
 * The unescape method is internally performed within this method.
 *
 * @param component the URI character sequence
 * @param charset   the protocol charset
 * @return original character sequence
 * @throws HttpException incomplete trailing escape pattern or unsupported
 *                       character encoding
 * @since 3.0
 */
protected static String decode(String component, String charset)
        throws HttpException {
    if (component == null) {
        throw new IllegalArgumentException("Component array of chars may not be null");
    }
    byte[] rawdata = null;
    try {
        rawdata = URLCodec.decodeUrl(EncodingUtils.getAsciiBytes(component));
    } catch (DecoderException e) {
        throw new HttpException(e.getMessage());
    }
    return EncodingUtils.getString(rawdata, charset);
}