本文整理汇总了Java中org.apache.http.util.EncodingUtils类的典型用法代码示例。如果您正苦于以下问题:Java EncodingUtils类的具体用法?Java EncodingUtils怎么用?Java EncodingUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EncodingUtils类属于org.apache.http.util包,在下文中一共展示了EncodingUtils类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTxtHistory
import org.apache.http.util.EncodingUtils; //导入依赖的package包/类
public static String getTxtHistory(File file) {
String res = "";
if (!file.exists()) {
return "";
}
try {
FileInputStream fin = new FileInputStream(file.getAbsolutePath());
byte[] buffer = new byte[fin.available()];
fin.read(buffer);
res = new StringBuilder(String.valueOf(res)).append(EncodingUtils.getString(buffer, "UTF-8")).toString();
fin.close();
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
示例2: fileTxtRead
import org.apache.http.util.EncodingUtils; //导入依赖的package包/类
String fileTxtRead(String fileName)
{
String res="";
try
{
File file = new File(fileName);
FileInputStream fis = new FileInputStream(file);
int length = fis.available();
byte [] buffer = new byte[length];
fis.read(buffer);
res = EncodingUtils.getString(buffer, "UTF-8");
fis.close();
}
catch (IOException e)
{
e.printStackTrace();
}
return res;
}
示例3: readCountryFromAsset
import org.apache.http.util.EncodingUtils; //导入依赖的package包/类
public static String readCountryFromAsset(Context context, String assetName) {
String content = "";
try {
InputStream is = context.getAssets().open(assetName);
if (is == null) {
return content;
}
DataInputStream dIs = new DataInputStream(is);
byte[] buffer = new byte[dIs.available()];
dIs.read(buffer);
content = EncodingUtils.getString(buffer, "UTF-8");
is.close();
return content;
} catch (IOException e) {
e.printStackTrace();
return content;
}
}
示例4: NTLMMessage
import org.apache.http.util.EncodingUtils; //导入依赖的package包/类
/** Constructor to use when message contents are known */
NTLMMessage(String messageBody, int expectedType) throws NTLMEngineException {
messageContents = Base64.decodeBase64(EncodingUtils.getBytes(messageBody,
DEFAULT_CHARSET));
// Look for NTLM message
if (messageContents.length < SIGNATURE.length)
throw new NTLMEngineException("NTLM message decoding error - packet too short");
int i = 0;
while (i < SIGNATURE.length) {
if (messageContents[i] != SIGNATURE[i])
throw new NTLMEngineException(
"NTLM message expected - instead got unrecognized bytes");
i++;
}
// Check to be sure there's a type 2 message indicator next
int type = readULong(SIGNATURE.length);
if (type != expectedType)
throw new NTLMEngineException("NTLM type " + Integer.toString(expectedType)
+ " message expected - instead got type " + Integer.toString(type));
currentOutputPosition = messageContents.length;
}
示例5: handleException
import org.apache.http.util.EncodingUtils; //导入依赖的package包/类
/**
* Handles the given exception and generates an HTTP response to be sent
* back to the client to inform about the exceptional condition encountered
* in the course of the request processing.
*
* @param ex the exception.
* @param response the HTTP response.
*/
protected void handleException(final HttpException ex, final HttpResponse response) {
if (ex instanceof MethodNotSupportedException) {
response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
} else if (ex instanceof UnsupportedHttpVersionException) {
response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
} else if (ex instanceof ProtocolException) {
response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
} else {
response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
String message = ex.getMessage();
if (message == null) {
message = ex.toString();
}
byte[] msg = EncodingUtils.getAsciiBytes(message);
ByteArrayEntity entity = new ByteArrayEntity(msg);
entity.setContentType("text/plain; charset=US-ASCII");
response.setEntity(entity);
}
示例6: readDataUri
import org.apache.http.util.EncodingUtils; //导入依赖的package包/类
private OpenForReadResult readDataUri(Uri uri) {
String uriAsString = uri.getSchemeSpecificPart();
int commaPos = uriAsString.indexOf(',');
if (commaPos == -1) {
return null;
}
String[] mimeParts = uriAsString.substring(0, commaPos).split(";");
String contentType = null;
boolean base64 = false;
if (mimeParts.length > 0) {
contentType = mimeParts[0];
}
for (int i = 1; i < mimeParts.length; ++i) {
if ("base64".equalsIgnoreCase(mimeParts[i])) {
base64 = true;
}
}
String dataPartAsString = uriAsString.substring(commaPos + 1);
byte[] data = base64 ? Base64.decode(dataPartAsString, Base64.DEFAULT) : EncodingUtils.getBytes(dataPartAsString, "UTF-8");
InputStream inputStream = new ByteArrayInputStream(data);
return new OpenForReadResult(uri, inputStream, contentType, data.length, null);
}
示例7: readDataFromFile
import org.apache.http.util.EncodingUtils; //导入依赖的package包/类
private void readDataFromFile() {
ThreadPoolUtils.getInstance().execute(new Runnable() {
@Override
public void run() {
try {
FileInputStream fis = openFileInput(filename);
byte[] buffer = new byte[fis.available()];
fis.read(buffer);
fis.close();
String fileContent = EncodingUtils.getString(buffer, "UTF-8");
parseDataFromJson(fileContent);
sendParseDataMessage(REFRESH_ERROR);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
示例8: readDataFromFile
import org.apache.http.util.EncodingUtils; //导入依赖的package包/类
private void readDataFromFile() {
new Thread(new Runnable() {
@Override
public void run() {
try {
FileInputStream fis;
fis = openFileInput(mFileName);
byte[] buffer = new byte[fis.available()];
fis.read(buffer);
fis.close();
final String fileContent = EncodingUtils.getString(buffer, "UTF-8");
runOnUiThread(new Runnable() {
@Override
public void run() {
parseWeatherData(fileContent);
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
示例9: NTLMMessage
import org.apache.http.util.EncodingUtils; //导入依赖的package包/类
/** Constructor to use when message contents are known */
NTLMMessage(final String messageBody, final int expectedType) throws NTLMEngineException {
messageContents = Base64.decode(EncodingUtils.getBytes(messageBody, DEFAULT_CHARSET),
Base64.NO_WRAP);
// Look for NTLM message
if (messageContents.length < SIGNATURE.length) {
throw new NTLMEngineException("NTLM message decoding error - packet too short");
}
int i = 0;
while (i < SIGNATURE.length) {
if (messageContents[i] != SIGNATURE[i]) {
throw new NTLMEngineException(
"NTLM message expected - instead got unrecognized bytes");
}
i++;
}
// Check to be sure there's a type 2 message indicator next
final int type = readULong(SIGNATURE.length);
if (type != expectedType) {
throw new NTLMEngineException("NTLM type " + Integer.toString(expectedType)
+ " message expected - instead got type " + Integer.toString(type));
}
currentOutputPosition = messageContents.length;
}
示例10: 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());
}
示例11: 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());
}
示例12: loadWebapp
import org.apache.http.util.EncodingUtils; //导入依赖的package包/类
public static void loadWebapp(WebView webView, AppSettings appSettings, boolean doLogin) {
Context context = webView.getContext();
Uri url;
try {
url = Uri.parse(appSettings.getProfilePathFull());
} catch (Exception e) {
webView.loadData(context.getString(R.string.no_valid_path), "text/html", "UTF-16");
return;
}
String url_s = url.toString();
if (appSettings.isProfileEmpty()) {
webView.loadData(context.getString(R.string.no_valid_path), "text/html", "UTF-16");
} else {
webView.loadUrl(url_s);
if (doLogin) {
url_s += "?a=checklogin";
String postData = "name=" + appSettings.getProfileLoginUsername() + "&password=" + appSettings.getProfileLoginPassword();
webView.postUrl(url_s, EncodingUtils.getBytes(postData, "base64"));
}
}
}
示例13: getHtmlString
import org.apache.http.util.EncodingUtils; //导入依赖的package包/类
public static String getHtmlString(String urlString) {
try {
URL url = new URL(urlString);
URLConnection ucon = url.openConnection();
InputStream instr = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(instr);
ByteArrayBuffer baf = new ByteArrayBuffer(500);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
return EncodingUtils.getString(baf.toByteArray(), "utf-8");
} catch (Exception e) {
Log.d("win","lllll"+e.toString());
return "";
}
}