Here you can find the source of urlencode(byte[] unencodedBytes)
Parameter | Description |
---|---|
unencodedBytes | The bytes to encode |
public static String urlencode(byte[] unencodedBytes)
//package com.java2s; /*//from w ww . j a va 2 s . com * Copyright (c) 2010 Matthew J. Francis and Contributors of the Bobbin Project * This file is distributed under the MIT licence. See the LICENCE file for further information. */ public class Main { /** * Encodes an array of plain bytes into a urlencoded string * * @param unencodedBytes The bytes to encode * @return A urlencoded string */ public static String urlencode(byte[] unencodedBytes) { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < unencodedBytes.length; i++) { if (((unencodedBytes[i] >= 'a') && (unencodedBytes[i] <= 'z')) || ((unencodedBytes[i] >= 'A') && (unencodedBytes[i] <= 'Z')) || ((unencodedBytes[i] >= '0') && (unencodedBytes[i] <= '9')) || (unencodedBytes[i] == '.') || (unencodedBytes[i] == '-') || (unencodedBytes[i] == '*') || (unencodedBytes[i] == '_')) { buffer.append((char) unencodedBytes[i]); } else if (unencodedBytes[i] == ' ') { buffer.append('+'); } else { buffer.append(String.format("%%%02x", unencodedBytes[i])); } } return buffer.toString(); } }