當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。