本文整理汇总了Java中org.apache.http.util.EncodingUtils.getString方法的典型用法代码示例。如果您正苦于以下问题:Java EncodingUtils.getString方法的具体用法?Java EncodingUtils.getString怎么用?Java EncodingUtils.getString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.util.EncodingUtils
的用法示例。
在下文中一共展示了EncodingUtils.getString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
}
示例3: 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 "";
}
}
示例4: getDataFromAssets
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
public static String getDataFromAssets(Context context, String string) {
String ENCODING = "UTF-8";
String result = "";
try {
InputStream is = context.getAssets().open(string);
int reads = is.available();
byte[] buffer = new byte[reads];
is.read(buffer);
result = EncodingUtils.getString(buffer, ENCODING);
result = result.replace("\r\n", "").replace(" ", "");
is.close();
} catch (IOException e) {
e.printStackTrace();
return null;
}
return result;
}
示例5: getDataFromAssetsNoChangeLine
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
public static String getDataFromAssetsNoChangeLine(Context context, String string) {
String ENCODING = "UTF-8";
String result = "";
try {
InputStream is = context.getAssets().open(string);
int reads = is.available();
byte[] buffer = new byte[reads];
is.read(buffer);
result = EncodingUtils.getString(buffer, ENCODING);
// result = result.replace("\r", "");
is.close();
} catch (IOException e) {
e.printStackTrace();
return null;
}
return result;
}
示例6: getFromRaw
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
public static String getFromRaw(Context context) {
String result = "";
try {
InputStream in = context.getResources().openRawResource(R.raw.data);
//获取文件的字节数
int lenght = in.available();
//创建byte数组
byte[] buffer = new byte[lenght];
//将文件中的数据读到byte数组中
in.read(buffer);
result = EncodingUtils.getString(buffer, "utf-8");
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
示例7: getTextFromAssets
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
/** 从assets 文件夹中获取文件并读取数据 */
public static String getTextFromAssets(final Context context, String fileName) {
String result = "";
try {
InputStream in = context.getResources().getAssets().open(fileName);
// 获取文件的字节数
int lenght = in.available();
// 创建byte数组
byte[] buffer = new byte[lenght];
// 将文件中的数据读到byte数组中
in.read(buffer);
result = EncodingUtils.getString(buffer, "UTF-8");
in.close();
} catch (Exception e) {
Logger.e("Assert:" + fileName);
Logger.e(e);
}
return result;
}
示例8: load
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
/**
* Loads the content of this page from a fetched
* HttpEntity.
*/
public void load(HttpEntity entity) throws Exception {
contentType = null;
Header type = entity.getContentType();
if (type != null) {
contentType = type.getValue();
}
contentEncoding = null;
Header encoding = entity.getContentEncoding();
if (encoding != null) {
contentEncoding = encoding.getValue();
}
ContentType ct = ContentType.get(entity);
if(ct != null&&ct.getCharset()!=null){
contentCharset = ct.getCharset().toString();
}
contentData = EntityUtils.toByteArray(entity);
if(contentCharset!=null && contentData!=null){
contentHtml = EncodingUtils.getString(contentData, contentCharset);
}
}
示例9: decode
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
/**
* Unescape and decode a given string regarded as an escaped string with the
* default protocol charset.
*
* @param escaped a string
* @return the unescaped string
* @throws HttpException if the string cannot be decoded (invalid)
*/
public static String decode(String escaped) throws HttpException {
try {
byte[] rawdata = URLCodec.decodeUrl(EncodingUtils.getAsciiBytes(escaped));
return EncodingUtils.getString(rawdata, UTF8_CHARSET_NAME);
} catch (DecoderException e) {
throw new HttpException(e.getMessage());
}
}
示例10: readStringFromFile
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
public static String readStringFromFile(Context context, String fileName) {
if (context == null) {
return null;
}
InputStream in = null;
try {
in = context.getAssets().open(fileName);
byte[] buffer = new byte[in.available()];
in.read(buffer);
String source = EncodingUtils.getString(buffer, Constants.UTF_8);
if (in == null) {
return source;
}
try {
in.close();
return source;
} catch (IOException e) {
e.printStackTrace();
return source;
}
} catch (IOException e2) {
e2.printStackTrace();
if (in != null) {
try {
in.close();
} catch (IOException e22) {
e22.printStackTrace();
}
}
return null;
} catch (Throwable th) {
if (in != null) {
try {
in.close();
} catch (IOException e222) {
e222.printStackTrace();
}
}
}
}
示例11: readStrFromAPP
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
public static String readStrFromAPP(String dir, String fileName) {
Exception exception;
String str = "";
try {
File file = new File(dir, fileName);
if (file.exists()) {
FileInputStream fis = new FileInputStream(file);
FileInputStream fileInputStream;
try {
byte[] buffer = new byte[fis.available()];
fis.read(buffer);
fis.close();
str = EncodingUtils.getString(buffer, "UTF-8");
fileInputStream = fis;
} catch (Exception e) {
exception = e;
fileInputStream = fis;
exception.printStackTrace();
return str;
}
}
return str;
} catch (Exception e2) {
exception = e2;
exception.printStackTrace();
return str;
}
}
示例12: decode
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
/**
* Unescape and decode a given string regarded as an escaped string with the
* default protocol charset.
*
* @param escaped a string
* @return the unescaped string
* @throws HttpException if the string cannot be decoded (invalid)
*/
public static String decode(String escaped) throws HttpException {
try {
byte[] rawdata = URLCodec.decodeUrl(EncodingUtils.getAsciiBytes(escaped));
return EncodingUtils.getString(rawdata, Charsets.UTF_8.name());
} catch (DecoderException e) {
throw new HttpException(e.getMessage());
}
}
示例13: readFileToString
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
/**
* 读取文件转为字符串(适用于小文件)
* @param context 上下文
* @param filePath 文件路径
* @param isAssets 是否asset目录文件
* @return String
*/
public static String readFileToString(Context context, String filePath, boolean isAssets) {
LogHelper.d(TAG, "readFileToString --> filePath = " + filePath);
String res = "";
InputStream in = null;
FileInputStream inFile = null;
int length;
try {
if (isAssets) {
in = context.getResources().getAssets().open(filePath);
length = in.available();
} else {
inFile = new FileInputStream(filePath);
length = inFile.available();
}
byte[] buffer = new byte[length];
int len;
if (inFile != null) {
len = inFile.read(buffer);
inFile.close();
} else {
len = in.read(buffer);
in.close();
}
if(len > 0){
res = EncodingUtils.getString(buffer, "UTF-8");
}
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
示例14: readTxtRawFile
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
public static String readTxtRawFile(int resId) {
String ret = "";
try {
InputStream in = context.getResources().openRawResource(resId);
int length = in.available();
byte[] buffer = new byte[length];
in.read(buffer);
ret = EncodingUtils.getString(buffer, "UTF-8");
in.close();
} catch (Exception e) {
showToast("read file error:" + e.getMessage());
}
return ret;
}
示例15: readSDFile
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
public static String readSDFile(String fileName) throws IOException {
File file = new File(fileName);
FileInputStream fis = new FileInputStream(file);
int length = fis.available();
byte [] buffer = new byte[length];
fis.read(buffer);
String res = EncodingUtils.getString(buffer, "UTF-8");
fis.close();
return res;
}