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


Java EncodingUtils.getAsciiString方法代碼示例

本文整理匯總了Java中org.apache.http.util.EncodingUtils.getAsciiString方法的典型用法代碼示例。如果您正苦於以下問題:Java EncodingUtils.getAsciiString方法的具體用法?Java EncodingUtils.getAsciiString怎麽用?Java EncodingUtils.getAsciiString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.util.EncodingUtils的用法示例。


在下文中一共展示了EncodingUtils.getAsciiString方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testBasicAuthentication

import org.apache.http.util.EncodingUtils; //導入方法依賴的package包/類
@Test
public void testBasicAuthentication() throws Exception {
    final UsernamePasswordCredentials creds =
        new UsernamePasswordCredentials("testuser", "testpass");

    final Header challenge = new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"test\"");

    final BasicScheme authscheme = new BasicScheme();
    authscheme.processChallenge(challenge);

    final HttpRequest request = new BasicHttpRequest("GET", "/");
    final HttpContext context = new BasicHttpContext();
    final Header authResponse = authscheme.authenticate(creds, request, context);

    final String expected = "Basic " + EncodingUtils.getAsciiString(
        Base64.encodeBase64(EncodingUtils.getAsciiBytes("testuser:testpass")));
    Assert.assertEquals(AUTH.WWW_AUTH_RESP, authResponse.getName());
    Assert.assertEquals(expected, authResponse.getValue());
    Assert.assertEquals("test", authscheme.getRealm());
    Assert.assertTrue(authscheme.isComplete());
    Assert.assertFalse(authscheme.isConnectionBased());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:23,代碼來源:TestBasicScheme.java

示例2: testBasicProxyAuthentication

import org.apache.http.util.EncodingUtils; //導入方法依賴的package包/類
@Test
public void testBasicProxyAuthentication() throws Exception {
    final UsernamePasswordCredentials creds =
        new UsernamePasswordCredentials("testuser", "testpass");

    final Header challenge = new BasicHeader(AUTH.PROXY_AUTH, "Basic realm=\"test\"");

    final BasicScheme authscheme = new BasicScheme();
    authscheme.processChallenge(challenge);

    final HttpRequest request = new BasicHttpRequest("GET", "/");
    final HttpContext context = new BasicHttpContext();
    final Header authResponse = authscheme.authenticate(creds, request, context);

    final String expected = "Basic " + EncodingUtils.getAsciiString(
        Base64.encodeBase64(EncodingUtils.getAsciiBytes("testuser:testpass")));
    Assert.assertEquals(AUTH.PROXY_AUTH_RESP, authResponse.getName());
    Assert.assertEquals(expected, authResponse.getValue());
    Assert.assertEquals("test", authscheme.getRealm());
    Assert.assertTrue(authscheme.isComplete());
    Assert.assertFalse(authscheme.isConnectionBased());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:23,代碼來源:TestBasicScheme.java

示例3: loadPage

import org.apache.http.util.EncodingUtils; //導入方法依賴的package包/類
private String loadPage(String file) throws Exception {
	InputStream inputStream = null;
	byte[] buffer = null;

	try {
		inputStream = getResources().getAssets().open(file);
		buffer = new byte[inputStream.available()];

		inputStream.read(buffer);
		inputStream.close();
		return EncodingUtils.getAsciiString(buffer);
	} finally {
		if (inputStream != null) {
			try {
				inputStream.close();
			} catch (Exception exception) { }
		}
	}
}
 
開發者ID:city0666,項目名稱:attic-android,代碼行數:20,代碼來源:AboutActivity.java

示例4: loadPage

import org.apache.http.util.EncodingUtils; //導入方法依賴的package包/類
private String loadPage(String file) throws Exception {
       InputStream is = null;
       byte[] buffer;

       try {
       	is = getResources().getAssets().open(file);
       	buffer = new byte[is.available()];  

       	is.read(buffer);
       	is.close();
       	return EncodingUtils.getAsciiString(buffer);
       } finally {
       	if (is != null) {
       		try {
       			is.close();
       		} catch (Exception e) {
       		}
       	}
       }        
}
 
開發者ID:city0666,項目名稱:attic-android,代碼行數:21,代碼來源:AboutActivity.java

示例5: getResponse

import org.apache.http.util.EncodingUtils; //導入方法依賴的package包/類
/**
 * Returns the response that has been generated after shrinking the
 * array if required and base64 encodes the response.
 *
 * @return The response as above.
 */
String getResponse() {
    byte[] resp;
    if (messageContents.length > currentOutputPosition) {
        byte[] tmp = new byte[currentOutputPosition];
        for (int i = 0; i < currentOutputPosition; i++) {
            tmp[i] = messageContents[i];
        }
        resp = tmp;
    } else {
        resp = messageContents;
    }
    return EncodingUtils.getAsciiString(Base64.encodeBase64(resp));
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:NTLMEngineImpl.java

示例6: getResponse

import org.apache.http.util.EncodingUtils; //導入方法依賴的package包/類
/**
 * Returns the response that has been generated after shrinking the
 * array if required and base64 encodes the response.
 *
 * @return The response as above.
 */
String getResponse() {
    final byte[] resp;
    if (messageContents.length > currentOutputPosition) {
        final byte[] tmp = new byte[currentOutputPosition];
        System.arraycopy(messageContents, 0, tmp, 0, currentOutputPosition);
        resp = tmp;
    } else {
        resp = messageContents;
    }
    return EncodingUtils.getAsciiString(Base64.encode(resp, Base64.NO_WRAP));
}
 
開發者ID:xxonehjh,項目名稱:remote-files-sync,代碼行數:18,代碼來源:NTLMEngineImpl.java

示例7: getResponse

import org.apache.http.util.EncodingUtils; //導入方法依賴的package包/類
/**
 * Returns the response that has been generated after shrinking the
 * array if required and base64 encodes the response.
 *
 * @return The response as above.
 */
String getResponse() {
    final byte[] resp;
    if (messageContents.length > currentOutputPosition) {
        final byte[] tmp = new byte[currentOutputPosition];
        System.arraycopy(messageContents, 0, tmp, 0, currentOutputPosition);
        resp = tmp;
    } else {
        resp = messageContents;
    }
    return EncodingUtils.getAsciiString(Base64.encodeBase64(resp));
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:18,代碼來源:NTLMEngineImpl.java

示例8: testValidMethodCalls

import org.apache.http.util.EncodingUtils; //導入方法依賴的package包/類
private void testValidMethodCalls(String cmdString, Object... parameters) throws Exception {
    ViSearchHttpClientImpl client = new ViSearchHttpClientImpl(validEndpoint, validAccessKey, validSecretKey, mockedHttpClient);
    ArgumentCaptor<HttpUriRequest> argument = ArgumentCaptor.forClass(HttpUriRequest.class);

    CloseableHttpResponse response = mock(CloseableHttpResponse.class);
    Header[] headers = { new BasicHeader("test-param", "123") };
    when(response.getAllHeaders()).thenReturn(headers);
    when(response.getEntity()).thenReturn(new StringEntity("test"));
    when(mockedHttpClient.execute(argument.capture())).thenReturn(response);

    CommandType cmd = determineCommandType(cmdString);
    switch (cmd) {
        case GET:
            client.get((String) parameters[0], (Multimap<String, String>) parameters[1]);
            break;
        case POST:
            client.post((String) parameters[0], (Multimap<String, String>) parameters[1]);
            break;
        case POST_IMAGE_01:
            client.postImage((String) parameters[0], (Multimap<String, String>) parameters[1], (File) parameters[2]);
            break;
        case POST_IMAGE_02:
            client.postImage((String) parameters[0], (Multimap<String, String>) parameters[1], (InputStream) parameters[2], (String) parameters[3]);
            break;
        default:
            break;
    }

    HttpUriRequest request = argument.getValue();
    Header[] headerArray = request.getAllHeaders();
    String expected = "Basic " + EncodingUtils.getAsciiString(Base64.encodeBase64(EncodingUtils.getAsciiBytes(validAccessKey + ":" + validSecretKey)));

    boolean isFound = false;
    for (int i = 0; i < headerArray.length; i++) {
        if (headerArray[i].getValue().equals(expected)) {
            isFound = true; // found credentials
            break;
        }
    }
    assertTrue(isFound);
}
 
開發者ID:visenze,項目名稱:visearch-sdk-java,代碼行數:42,代碼來源:ViSearchHttpClientTest.java

示例9: encode

import org.apache.http.util.EncodingUtils; //導入方法依賴的package包/類
/**
 * Escape and encode a given string with allowed characters not to be
 * escaped and a given charset.
 *
 * @param unescaped a string
 * @param allowed   allowed characters not to be escaped
 * @param charset   the charset
 * @return the escaped string
 */
public static String encode(String unescaped, BitSet allowed,
                            String charset) throws HttpException {
    byte[] rawdata = URLCodec.encodeUrl(allowed,
            EncodingUtils.getBytes(unescaped, charset));
    return EncodingUtils.getAsciiString(rawdata);
}
 
開發者ID:JFrogDev,項目名稱:jfrog-idea-plugin,代碼行數:16,代碼來源:URIUtil.java

示例10: encode

import org.apache.http.util.EncodingUtils; //導入方法依賴的package包/類
/**
 * Escape and encode a given string with allowed characters not to be
 * escaped and a given charset.
 *
 * @param unescaped a string
 * @param allowed allowed characters not to be escaped
 * @param charset the charset
 * @return the escaped string
 */
public static String encode(String unescaped, BitSet allowed,
        String charset) throws URIException {
    byte[] rawdata = URLCodec.encodeUrl(allowed, 
        EncodingUtils.getBytes(unescaped, charset));
    return EncodingUtils.getAsciiString(rawdata);
}
 
開發者ID:parisbutterfield,項目名稱:alexa-stocks,代碼行數:16,代碼來源:URIUtils.java

示例11: encode

import org.apache.http.util.EncodingUtils; //導入方法依賴的package包/類
/**
 * Escape and encode a given string with allowed characters not to be
 * escaped and a given charset.
 *
 * @param unescaped a string
 * @param allowed   allowed characters not to be escaped
 * @param charset   the charset
 * @return the escaped string
 */
public static String encode(String unescaped, BitSet allowed,
        String charset) throws HttpException {
    byte[] rawdata = URLCodec.encodeUrl(allowed,
            EncodingUtils.getBytes(unescaped, charset));
    return EncodingUtils.getAsciiString(rawdata);
}
 
開發者ID:alancnet,項目名稱:artifactory,代碼行數:16,代碼來源:URIUtil.java


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