當前位置: 首頁>>代碼示例>>Java>>正文


Java URLCodec類代碼示例

本文整理匯總了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;
    }
}
 
開發者ID:patrickfav,項目名稱:dice,代碼行數:22,代碼來源:ColumnRenderer.java

示例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();
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:41,代碼來源:EncodingUtil.java

示例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();
    }
}
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:22,代碼來源:GetClient.java

示例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();
    }
}
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:20,代碼來源:OldHttpClientApi.java

示例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;
}
 
開發者ID:hpe-idol,項目名稱:java-aci-api-ng,代碼行數:24,代碼來源:AciURLCodec.java

示例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;
}
 
開發者ID:hpe-idol,項目名稱:java-aci-api-ng,代碼行數:24,代碼來源:AciURLCodec.java

示例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));
}
 
開發者ID:opendatakit,項目名稱:aggregate,代碼行數:24,代碼來源:SubmissionServiceImpl.java

示例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));
}
 
開發者ID:apache,項目名稱:incubator-gobblin,代碼行數:18,代碼來源:AzkabanAjaxAPIClient.java

示例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;
}
 
開發者ID:groupon,項目名稱:DotCi-Plugins-Starter-Pack,代碼行數:18,代碼來源:SendRoomMessageWithCardRequest.java

示例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;

}
 
開發者ID:DoctorD1501,項目名稱:JAVMovieScraper,代碼行數:21,代碼來源:JavLibraryParsingProfile.java

示例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;
}
 
開發者ID:DoctorD1501,項目名稱:JAVMovieScraper,代碼行數:25,代碼來源:ExcaliburFilmsParsingProfile.java

示例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;
}
 
開發者ID:DoctorD1501,項目名稱:JAVMovieScraper,代碼行數:18,代碼來源:JavBusParsingProfile.java

示例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;
}
 
開發者ID:DoctorD1501,項目名稱:JAVMovieScraper,代碼行數:21,代碼來源:TheMovieDatabaseParsingProfile.java

示例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;
}
 
開發者ID:DoctorD1501,項目名稱:JAVMovieScraper,代碼行數:20,代碼來源:JavZooParsingProfile.java

示例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;
	

}
 
開發者ID:DoctorD1501,項目名稱:JAVMovieScraper,代碼行數:22,代碼來源:JavLibraryParsingProfile.java


注:本文中的org.apache.commons.codec.net.URLCodec類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。