本文整理汇总了Java中org.apache.commons.codec.net.URLCodec类的典型用法代码示例。如果您正苦于以下问题:Java URLCodec类的具体用法?Java URLCodec怎么用?Java URLCodec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
URLCodec类属于org.apache.commons.codec.net包,在下文中一共展示了URLCodec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: request
import org.apache.commons.codec.net.URLCodec; //导入依赖的package包/类
@Override
public void request(String[] fillArray) {
for (int i = 0; i < fillArray.length; i++) {
byte[] rnd = drbg.nextBytes(length);
if (crc32) {
rnd = Bytes.wrap(rnd).transform(new ByteUtils.Crc32AppenderTransformer()).array();
}
String randomEncodedString = padding ? encoder.encodePadded(rnd) : encoder.encode(rnd);
if (urlencode) {
try {
randomEncodedString = new URLCodec().encode(randomEncodedString);
} catch (EncoderException e) {
throw new IllegalStateException("could not url encode", e);
}
}
fillArray[i] = randomEncodedString;
}
}
示例2: doFormUrlEncode
import org.apache.commons.codec.net.URLCodec; //导入依赖的package包/类
/**
* Form-urlencoding routine.
*
* The default encoding for all forms is `application/x-www-form-urlencoded'.
* A form data set is represented in this media type as follows:
*
* The form field names and values are escaped: space characters are replaced
* by `+', and then reserved characters are escaped as per [URL]; that is,
* non-alphanumeric characters are replaced by `%HH', a percent sign and two
* hexadecimal digits representing the ASCII code of the character. Line breaks,
* as in multi-line text field values, are represented as CR LF pairs, i.e. `%0D%0A'.
*
* @param pairs the values to be encoded
* @param charset the character set of pairs to be encoded
*
* @return the urlencoded pairs
* @throws UnsupportedEncodingException if charset is not supported
*
* @since 2.0 final
*/
private static String doFormUrlEncode(NameValuePair[] pairs, String charset)
throws UnsupportedEncodingException
{
StringBuffer buf = new StringBuffer();
for (int i = 0; i < pairs.length; i++) {
URLCodec codec = new URLCodec();
NameValuePair pair = pairs[i];
if (pair.getName() != null) {
if (i > 0) {
buf.append("&");
}
buf.append(codec.encode(pair.getName(), charset));
buf.append("=");
if (pair.getValue() != null) {
buf.append(codec.encode(pair.getValue(), charset));
}
}
}
return buf.toString();
}
示例3: get2
import org.apache.commons.codec.net.URLCodec; //导入依赖的package包/类
public void get2() throws IOException {
String APIKEY = "4b441cb500f431adc6cc0cb650b4a5d0";
String INFO = new URLCodec().encode("who are you", "utf-8");
String requesturl = "http://www.tuling123.com/openapi/api?key=" + APIKEY + "&info=" + INFO;
// 声明httpclient
CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse response = null;
try {
HttpGet httpGet = new HttpGet(requesturl);
response = httpclient.execute(httpGet);
HttpEntity entity = response.getEntity();
String content = EntityUtils.toString(entity, "utf-8");
log.info(content);
EntityUtils.consume(entity);
} catch (Exception e) {
log.error("" + e);
} finally {
if (response != null)
response.close();
}
}
示例4: get
import org.apache.commons.codec.net.URLCodec; //导入依赖的package包/类
public void get() throws UnsupportedEncodingException {
HttpClient client = new HttpClient();
String APIKEY = "4b441cb500f431adc6cc0cb650b4a5d0";
String INFO =new URLCodec().encode("who are you","utf-8");
String requesturl = "http://www.tuling123.com/openapi/api?key=" + APIKEY + "&info=" + INFO;
GetMethod getMethod = new GetMethod(requesturl);
try {
int stat = client.executeMethod(getMethod);
if (stat != HttpStatus.SC_OK)
log.error("get失败!");
byte[] responseBody = getMethod.getResponseBody();
String content=new String(responseBody ,"utf-8");
log.info(content);
}catch (Exception e){
log.error(""+e.getLocalizedMessage());
}finally {
getMethod.releaseConnection();
}
}
示例5: encode
import org.apache.commons.codec.net.URLCodec; //导入依赖的package包/类
/**
* Encodes a string into its URL safe form using the UTF-8 charset. Unsafe characters are escaped and the resulting
* string is returned in the US-ASCII charset.
* @param string The string to convert to a URL safe form
* @return URL safe string
* @throws AciURLCodecException If there was a problem during the encoding
*/
public String encode(final String string) {
// This is what we'll return...
String returnValue = null;
try {
if (string != null) {
returnValue = new String(URLCodec.encodeUrl(safeChars, string.getBytes(UTF8)), US_ASCII);
}
} catch (final UnsupportedEncodingException uee) {
// This should never ever happen as both charsets are required by the Java Spec.
throw new AciURLCodecException(uee);
}
// Return the result...
return returnValue;
}
示例6: decode
import org.apache.commons.codec.net.URLCodec; //导入依赖的package包/类
/**
* Decodes a URL safe string into its original form using the UTF-8 charset. Escaped characters are converted back
* to their original representation.
* @param string URL safe string to convert into its original form
* @return original string
* @throws AciURLCodecException Thrown if URL decoding is unsuccessful
*/
public String decode(final String string) throws AciURLCodecException {
// This is what we'll return...
String returnValue = null;
try {
if (string != null) {
returnValue = new String(URLCodec.decodeUrl(string.getBytes(US_ASCII)), UTF8);
}
} catch (final UnsupportedEncodingException | DecoderException uee) {
// This should never ever happen as both charsets are required by the Java Spec.
throw new AciURLCodecException(uee);
}
// Return the result...
return returnValue;
}
示例7: getSubmissionAuditCSV
import org.apache.commons.codec.net.URLCodec; //导入依赖的package包/类
@Override
public String getSubmissionAuditCSV(String keyString) throws AccessDeniedException, RequestFailureException, DatastoreFailureException{
HttpServletRequest req = this.getThreadLocalRequest();
CallingContext cc = ContextFactory.getCallingContext(this, req);
URLCodec urlCodec = new URLCodec();
String decode = null;
try {
decode = urlCodec.decode(keyString);
} catch (DecoderException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
SubmissionKey key = new SubmissionKey(decode);
List<SubmissionKeyPart> parts = key.splitSubmissionKey();
if (parts.get(0).getElementName().equals(PersistentResults.FORM_ID_PERSISTENT_RESULT))
return new String(getBytes(cc, key));
Submission sub = getSubmission(cc, parts);
BlobSubmissionType b = getBlobSubmissionType(parts, sub);
return new String(getBytes(cc, parts, b));
}
示例8: changeProjectDescription
import org.apache.commons.codec.net.URLCodec; //导入依赖的package包/类
private static void changeProjectDescription(String sessionId, String azkabanServerUrl, String azkabanProjectName,
String projectDescription)
throws IOException {
String encodedProjectDescription;
try {
encodedProjectDescription = new URLCodec().encode(projectDescription);
} catch (EncoderException e) {
throw new IOException("Could not encode Azkaban project description", e);
}
Map<String, String> params = Maps.newHashMap();
params.put("ajax", "changeDescription");
params.put("project", azkabanProjectName);
params.put("description", encodedProjectDescription);
executeGetRequest(prepareGetRequest(azkabanServerUrl + "/manager", sessionId, params));
}
示例9: getEncodedPath
import org.apache.commons.codec.net.URLCodec; //导入依赖的package包/类
protected String getEncodedPath() {
String path = getPath();
String[] tokens = path.split("/");
String encodedPath = "";
URLCodec urlCodec = new URLCodec();
try {
for (String token : tokens) {
if (!token.isEmpty()) {
//replace + to %20
encodedPath += "/" + urlCodec.encode(token).replace("+", "%20");
}
}
} catch (EncoderException e) {
throw new RuntimeException(e);
}
return encodedPath;
}
示例10: createSearchString
import org.apache.commons.codec.net.URLCodec; //导入依赖的package包/类
@Override
public String createSearchString(File file) {
scrapedMovieFile = file;
String fileNameNoExtension = findIDTagFromFile(file, isFirstWordOfFileIsID());
//return fileNameNoExtension;
URLCodec codec = new URLCodec();
try {
String fileNameURLEncoded = codec.encode(fileNameNoExtension);
String searchTerm = "http://www.javlibrary.com/" + siteLanguageToScrape + "/vl_searchbyid.php?keyword=" + fileNameURLEncoded;
return searchTerm;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
示例11: createSearchString
import org.apache.commons.codec.net.URLCodec; //导入依赖的package包/类
@Override
public String createSearchString(File file) {
String fileBaseName;
if (file.isFile())
fileBaseName = FilenameUtils.getBaseName(Movie.getUnstackedMovieName(file));
else
fileBaseName = file.getName();
String[] splitBySpace = fileBaseName.split(" ");
if (splitBySpace.length > 1) {
// check if last word in filename contains a year like (2012) or [2012]
// we want to remove this from our search because it freaks out the search on excalibur films and gives no results
if (splitBySpace[splitBySpace.length - 1].matches("[\\(\\[]\\d{4}[\\)\\]]")) {
fileBaseName = fileBaseName.replaceFirst("[\\(\\[]\\d{4}[\\)\\]]", "").trim();
}
}
URLCodec codec = new URLCodec();
try {
fileBaseName = codec.encode(fileBaseName);
} catch (EncoderException e) {
e.printStackTrace();
}
fileBaseName = "http://www.excaliburfilms.com/search/adultSearch.htm?searchString=" + fileBaseName + "&Case=ExcalMovies&Search=AdultDVDMovies&SearchFor=Title.x";
return fileBaseName;
}
示例12: createSearchString
import org.apache.commons.codec.net.URLCodec; //导入依赖的package包/类
@Override
public String createSearchString(File file) {
scrapedMovieFile = file;
String fileNameNoExtension = findIDTagFromFile(file, isFirstWordOfFileIsID());
URLCodec codec = new URLCodec();
try {
String fileNameURLEncoded = codec.encode(fileNameNoExtension);
String searchTerm = "http://www.javbus.com/" + getUrlLanguageToUse() + "/search/" + fileNameURLEncoded;
return searchTerm;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
示例13: createSearchString
import org.apache.commons.codec.net.URLCodec; //导入依赖的package包/类
@Override
public String createSearchString(File file) {
scrapedMovieFile = file;
URLCodec codec = new URLCodec();
try {
String movieName = getMovieNameFromFileWithYear(file);
String year = getYearFromFileWithYear(file);
String fileNameURLEncoded = codec.encode(movieName);
String includeAdultParameter = "";
if (includeAdult)
includeAdultParameter = "&include_adult=true";
if (year != null && year.length() == 4) {
return "http://api.themoviedb.org/3/search/movie?api_key=" + tmdbKey + includeAdultParameter + "&query=" + fileNameURLEncoded + "&year=" + year;
} else
return "http://api.themoviedb.org/3/search/movie?api_key=" + tmdbKey + includeAdultParameter + "&query=" + fileNameURLEncoded;
} catch (EncoderException e) {
e.printStackTrace();
}
return null;
}
示例14: createSearchString
import org.apache.commons.codec.net.URLCodec; //导入依赖的package包/类
@Override
public String createSearchString(File file) {
scrapedMovieFile = file;
String fileNameNoExtension = findIDTagFromFile(file, isFirstWordOfFileIsID());
//return fileNameNoExtension;
URLCodec codec = new URLCodec();
try {
String fileNameURLEncoded = codec.encode(fileNameNoExtension);
String searchTerm = "http://www.javdog.com/" + siteLanguageToScrape + "/search/" + fileNameURLEncoded;
return searchTerm;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
示例15: createSearchString
import org.apache.commons.codec.net.URLCodec; //导入依赖的package包/类
@Override
public String createSearchString(File file) {
scrapedMovieFile = file;
String fileNameNoExtension = findIDTagFromFile(file, isFirstWordOfFileIsID());
//return fileNameNoExtension;
URLCodec codec = new URLCodec();
try {
String fileNameURLEncoded = codec.encode(fileNameNoExtension);
String searchTerm = "http://www.javlibrary.com/" + siteLanguageToScrape + "/vl_searchbyid.php?keyword=" + fileNameURLEncoded;
return searchTerm;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}