Java URL Encode encodeSrcUrl(String fullUri)

Here you can find the source of encodeSrcUrl(String fullUri)

Description

encode Src Url

License

Open Source License

Declaration

private static String encodeSrcUrl(String fullUri) 

Method Source Code


//package com.java2s;
//  in accordance with the terms of the license agreement accompanying it.

import java.io.*;

public class Main {
    private static String encodeSrcUrl(String fullUri) {
        try {/*from   ww w  .ja  va2s.  co m*/
            int length = fullUri.length();
            StringBuffer buf = new StringBuffer(length);
            for (int i = 0; i < length; i++) {
                char c = fullUri.charAt(i);
                if (c <= 127) {
                    buf.append(c);
                } else {
                    byte[] bytes = fullUri.substring(i, i + 1).getBytes("UTF-8");
                    for (int j = 0; j < bytes.length; j++) {
                        int b = bytes[j] & 255;
                        buf.append('%');
                        if (b < 16) {
                            buf.append('0');
                        }
                        buf.append(Integer.toHexString(b));
                    }
                }
            }
            return buf.toString();
        } catch (UnsupportedEncodingException e) {
            // will not happen because UTF-8 is required on all JVM's
            return fullUri;
        }
    }
}

Related

  1. encode(String value)
  2. encode(String value, String charset)
  3. encode(String value, String encoding)
  4. encodeArray(final String[] val)
  5. encodeForUrl(final String s)
  6. encodeStringURL(String str)
  7. encodeUri(String url)
  8. encodeURIComponent(String input)
  9. encodeURL(BitSet urlsafe, byte[] bytes)