List of usage examples for org.apache.http.util EncodingUtils getString
public static String getString(byte[] bArr, String str)
From source file:Main.java
public static String getStringFromTextFile(File f) { byte[] b = getBytesFromFile(f); if (b == null) return null; return EncodingUtils.getString(b, "UTF-8"); }
From source file:Main.java
/** * @param fileName//from www.ja va 2 s.co m */ public static String readFileByLines(String fileName) { String res = ""; try { FileInputStream fin = new FileInputStream(fileName); int length = fin.available(); byte[] buffer = new byte[length + 1024]; fin.read(buffer); res = EncodingUtils.getString(buffer, "UTF-8"); fin.close(); } catch (Exception e) { e.printStackTrace(); } return res; }
From source file:Main.java
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);/* ww w .j a va 2s. c o m*/ String res = EncodingUtils.getString(buffer, "UTF-8"); fis.close(); return res; }
From source file:Main.java
/** * (java) read from file/* w w w .ja v a2 s . c om*/ * * @param path * @return */ public static String readFile(File file) { String str = ""; FileInputStream in; try { in = new FileInputStream(file); int length = (int) file.length(); byte[] temp = new byte[length]; in.read(temp, 0, length); str = EncodingUtils.getString(temp, FILE_ENCODING); in.close(); } catch (IOException e) { Log.e("", "read error!"); } return str; }
From source file:Main.java
public static String responseAsString(HttpResponse response) throws IOException { StatusLine status = response.getStatusLine(); if (status.getStatusCode() != HTTP_STATUS_OK) { throw new IOException("Invalid response from server! " + status.toString()); }/*from w w w . j a va 2s . c o m*/ //do the herdy gerdy and convert the response to a String InputStream ist = response.getEntity().getContent(); ByteArrayOutputStream content = new ByteArrayOutputStream(); int readCount = 0; while ((readCount = ist.read(buff)) != -1) content.write(buff, 0, readCount); String thePagesContent = EncodingUtils.getString(content.toByteArray(), "UTF-8"); return thePagesContent; }
From source file:com.kyon.klib.base.KFileUtils.java
public static String readFile(Context context, String fileName) throws IOException { String res = ""; try {/* w w w . ja v a 2 s .c o m*/ FileInputStream fIn = context.openFileInput(fileName); int length = fIn.available(); byte[] buffer = new byte[length]; fIn.read(buffer); res = EncodingUtils.getString(buffer, "UTF-8"); fIn.close(); } catch (Exception e) { e.printStackTrace(); } return res; }
From source file:de.berlin.magun.nfcmime.core.NdefMimeRecord.java
/** * @return MIME definition as String.//from ww w. j a v a2s .c o m */ public String getMimeString() { // return new String(this.mime, Charset.forName("US-ASCII")); return EncodingUtils.getString(this.mime, "UTF-8"); }
From source file:info.papdt.blacklight.support.http.FeedbackUtility.java
private static String readLog() { String res = ""; try {//from www . j a v a 2 s. c o m FileInputStream fin = new FileInputStream(CrashHandler.CRASH_LOG); int length = fin.available(); byte[] buffer = new byte[length]; fin.read(buffer); res = EncodingUtils.getString(buffer, "UTF-8"); fin.close(); } catch (Exception e) { e.printStackTrace(); return ""; } return res; }
From source file:de.bolz.android.taglocate.protocol.FileIdResolver.java
@Override public Coordinates resolve(String id) { try {// ww w. j a v a 2 s .c o m // Deserialize link file: File referencefile = new File( SettingsSingleton.getInstance().getDatapath() + SettingsSingleton.getInstance().getDatafile()); InputStream is; ReferenceList list = null; String input = ""; // Make sure file's content is decoded using UTF-8: is = new FileInputStream(referencefile); byte[] ba = IOUtils.toByteArray(is); input = EncodingUtils.getString(ba, "UTF-8"); // Create a serializer that adheres to the XML's camel case element style: Serializer s = new Persister(new Format(new CamelCaseStyle())); list = s.read(ReferenceList.class, input); if (list != null) { List<Reference> links = list.getReferences(); String trigger; // Match ID against each item in the link list (=reference table): for (int i = 0; i < links.size(); i++) { trigger = (new Source(links.get(i).getTrigger().getTag().getTagStr())).getValue(); if (id.equalsIgnoreCase(trigger)) { return (new GeoUri(links.get(i).getTarget().getTargetStr())).getCoordinate(); } } } } catch (FileNotFoundException e) { e.printStackTrace(); return null; } catch (IOException e) { e.printStackTrace(); return null; } catch (Exception e) { e.printStackTrace(); return null; } return null; }
From source file:com.twinflag.coofiletouch.AuthorityUtil.java
public boolean isAuthorityExpired() { boolean retValue = true; if (DeviceUtil.isSdCardExist()) { String deviceInfo = null; String licenseFileContent = null; String decodedContent = null; String validContent = null; String dateInfo = null;/*from w w w. j a v a 2 s . c o m*/ String deviceInfoTmp = null; String decodeKey = null; String lincenseFileFullName = null; String lincenseFileName = null; deviceInfo = DeviceUtil.getDeviceInfo(); lincenseFileName = deviceInfo + ".license"; // deviceInfo = "6523-8769-2234-85746873"; // lincenseFileName = "6523-8769-2234-85746873.license"; lincenseFileFullName = CoofileTouchApplication.getAppResBasePath() + File.separator + Constant.APP_RES_AUTHORITY_FOLDER + File.separator + lincenseFileName; deviceInfoTmp = deviceInfo.replace("-", ""); if (deviceInfoTmp.length() >= LICENSE_DECODE_KEY_LEN) decodeKey = deviceInfoTmp.substring(deviceInfoTmp.length() - LICENSE_DECODE_KEY_LEN, deviceInfoTmp.length()); File authFile = new File(lincenseFileFullName); if (authFile.exists()) { try { FileInputStream fin = new FileInputStream(authFile); int length = fin.available(); byte[] buffer = new byte[length]; fin.read(buffer); licenseFileContent = EncodingUtils.getString(buffer, "UTF-8"); fin.close(); } catch (Exception e) { e.printStackTrace(); } if (licenseFileContent != null) { try { decodedContent = DES.decryptDES(licenseFileContent, decodeKey); } catch (Exception e) { e.printStackTrace(); } if (decodedContent.length() >= DEVICE_INFO_CONTENT_LEN) { validContent = decodedContent.substring(0, 10) + decodedContent.substring(17, decodedContent.length()); dateInfo = decodedContent.substring(10, 16); if (validContent.equalsIgnoreCase(deviceInfo) && isLaterThanToday(dateInfo)) { retValue = false; } } } } } return retValue; }