当前位置: 首页>>代码示例>>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;未经允许,请勿转载。