当前位置: 首页>>代码示例>>Java>>正文


Java EncodingUtils.getString方法代码示例

本文整理汇总了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;
}
 
开发者ID:nijigenirubasho,项目名称:mobiletailchanger,代码行数:20,代码来源:MainActivity.java

示例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;
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:19,代码来源:ResourceManager.java

示例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 "";  
    }  
}
 
开发者ID:dotcool,项目名称:mvideo,代码行数:19,代码来源:HttpUtil.java

示例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;
}
 
开发者ID:cdkd321,项目名称:pure,代码行数:18,代码来源:AssetUtils.java

示例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;
	}
 
开发者ID:cdkd321,项目名称:pure,代码行数:18,代码来源:AssetUtils.java

示例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;
}
 
开发者ID:zerob13,项目名称:PureColor-Android,代码行数:17,代码来源:DummyAssets.java

示例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;
}
 
开发者ID:Tinker-S,项目名称:VCameraSample,代码行数:20,代码来源:ResourceUtils.java

示例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);
	}
}
 
开发者ID:houdejun214,项目名称:lakeside-java,代码行数:30,代码来源:HttpPage.java

示例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());
    }
}
 
开发者ID:JFrogDev,项目名称:jfrog-idea-plugin,代码行数:17,代码来源:URIUtil.java

示例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();
            }
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:41,代码来源:AssetUtils.java

示例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;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:29,代码来源:FileUtil.java

示例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());
    }
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:17,代码来源:URIUtil.java

示例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;
}
 
开发者ID:Frank-Zhu,项目名称:AndroidAppCodeFramework,代码行数:39,代码来源:FileHelper.java

示例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;
}
 
开发者ID:steven2947,项目名称:NeXT_pyp,代码行数:15,代码来源:ComFun.java

示例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;
    }
 
开发者ID:youngytj,项目名称:android_MyPassword,代码行数:17,代码来源:IOHelper.java


注:本文中的org.apache.http.util.EncodingUtils.getString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。