List of usage examples for org.apache.http.util EncodingUtils getString
public static String getString(byte[] bArr, String str)
From source file:de.bolz.android.taglocate.geom.OsmParser.java
/** * Deserializes an OSM file into an {@link Osm} object. * @param f the OSM file/* w ww . j a va 2 s . co m*/ */ private void parse(File f) { String input = ""; try { // Make sure to pass the file's content to the Serializer with UTF-8 encoding: InputStream is = new FileInputStream(f); byte[] ba = IOUtils.toByteArray(is); input = EncodingUtils.getString(ba, "UTF-8"); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // Deserialize: Serializer serial = new Persister(); try { osm = serial.read(Osm.class, input); } catch (NotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.BeeFramework.activity.CrashLogActivity.java
public void initLog() { try {/*from ww w . j av a2 s .c o m*/ String path = Environment.getExternalStorageDirectory().getAbsolutePath() + AppConst.LOG_DIR_PATH; getFiles(logFilesList, path); for (int i = 0; i < logFilesList.size(); i++) { File file = logFilesList.get(i); try { FileInputStream fin = new FileInputStream(file); int length = fin.available(); byte[] buffer = new byte[length]; fin.read(buffer); String content = EncodingUtils.getString(buffer, "UTF-8"); fin.close(); String fileName = file.getName(); String[] nameArray = fileName.split("\\."); if (nameArray.length > 0) { String intStr = nameArray[0]; long timestamp = Long.parseLong(intStr); Date currentTime = new Date(timestamp); CrashMessage crashMessage = new CrashMessage(); SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); String dateString = formatter.format(currentTime); crashMessage.crashTime = dateString; crashMessage.crashContent = content; crashMessageArrayList.add(crashMessage); } } catch (FileNotFoundException e) { } catch (IOException e2) { e2.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } finally { handler.sendEmptyMessage(0); } }
From source file:com.gotraveling.insthub.BeeFramework.activity.CrashLogActivity.java
public void initLog() { try {//from ww w . j a v a 2s .c o m String path = Environment.getExternalStorageDirectory().getAbsolutePath() + BeeFrameworkConst.LOG_DIR_PATH; getFiles(logFilesList, path); for (int i = 0; i < logFilesList.size(); i++) { File file = logFilesList.get(i); try { FileInputStream fin = new FileInputStream(file); int length = fin.available(); byte[] buffer = new byte[length]; fin.read(buffer); String content = EncodingUtils.getString(buffer, "UTF-8"); fin.close(); String fileName = file.getName(); String[] nameArray = fileName.split("\\."); if (nameArray.length > 0) { String intStr = nameArray[0]; long timestamp = Long.parseLong(intStr); Date currentTime = new Date(timestamp); CrashMessage crashMessage = new CrashMessage(); SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); String dateString = formatter.format(currentTime); crashMessage.crashTime = dateString; crashMessage.crashContent = content; crashMessageArrayList.add(crashMessage); } } catch (FileNotFoundException e) { } catch (IOException e2) { e2.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } finally { handler.sendEmptyMessage(0); } }
From source file:net.sourcewalker.garanbot.api.GaranboClient.java
protected String readEntity(HttpResponse response) { StringBuilder sb = new StringBuilder(); try {/* w w w .j av a 2 s . c o m*/ InputStream stream = response.getEntity().getContent(); byte[] buffer = new byte[1024]; int read; do { read = stream.read(buffer); if (read != -1) { if (read == buffer.length) { sb.append(EncodingUtils.getString(buffer, "utf-8")); } else { sb.append(EncodingUtils.getString(buffer, 0, read, "utf-8")); } } } while (read != -1); } catch (IOException e) { sb.append("ERROR: " + e.getMessage()); } return sb.toString(); }
From source file:com.plusub.lib.example.activity.tab4.Tab4Fragment.java
public String getFromAssets(String fileName) { String result = ""; try {// w w w .j av a 2s . com InputStream in = getActivity().getResources().getAssets().open(fileName); //? 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; }
From source file:com.zokin.common.Application.java
public String ReadFileData(String fileName) { String res = ""; try {//from ww w. j a va2s .c o m FileInputStream fin = 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:com.freecast.LudoCast.MainActivity.java
public void readFileData(String fileName) { String res = ""; try {/*from ww w. j a va2 s . c o m*/ FileInputStream fin = 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(); } if (res.equals("")) { } else { editText.setText(res); username = editText.getText().toString(); } }
From source file:com.development.androrb.listfolders.java
private String loaddata(String Urli) { try {/* ww w . j a v a 2 s. com*/ URLConnection conn; conn = new URL(Urli).openConnection(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(8192); // loading part int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } //Log.i(TAG, " *------ after while -----*: "+current); html = EncodingUtils.getString(baf.toByteArray(), "UTF-8"); } catch (Exception e) { TextUpdate = "Ups, check your Connection ..."; runOnUiThread(showTextUpdate); //Toast.makeText(this, "Shit, Loading Error!", Toast.LENGTH_SHORT).show(); } return html; }
From source file:com.development.androrb.Orband.java
private String loaddata(String Urli) { try {/* www . j a v a 2 s . co m*/ //Log.i(TAG, " *------ Load Data: "+Urli); URLConnection conn; conn = new URL(Urli).openConnection(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(8192); // loading part int current = 0; int countix = 0; int kbread = 0; while ((current = bis.read()) != -1) { countix++; baf.append((byte) current); if (countix >= 1000) { countix = 0; kbread++; TextUpdate = loadingmediadata + " (" + kbread + " kb)"; runOnUiThread(showTextUpdate); } } // Log.i(TAG, " *------ Load Data done -----*: "); html = EncodingUtils.getString(baf.toByteArray(), "UTF-8"); // ------ } catch (Exception e) { TextUpdate = "Ups, check your Connection ..."; runOnUiThread(showTextUpdate); } return html; }
From source file:org.kontalk.crypto.Coder.java
/** * Decrypt and verify the body of a message. Sets the encryption and signing * status of the message and errors that may occur are saved to the message. * @param message//from w w w .j a va 2 s. c o m */ public static void processInMessage(InMessage message) { // signing requires also encryption if (!message.getCoderStatus().isEncrypted()) { LOGGER.warning("message not encrypted"); return; } LOGGER.info("decrypting encrypted message..."); // get keys KeysResult keys = getKeys(message.getUser()); if (keys.myKey == null || keys.otherKey == null) { message.setSecurityErrors(keys.errors); return; } // decrypt String encryptedContent = message.getContent().getEncryptedContent(); if (encryptedContent.isEmpty()) { LOGGER.warning("no encrypted data in encrypted message"); } byte[] encryptedData = Base64.getDecoder().decode(encryptedContent); InputStream encryptedStream = new ByteArrayInputStream(encryptedData); DecryptionResult decResult = decryptAndVerify(encryptedStream, keys.myKey, keys.otherKey.encryptKey); EnumSet<Coder.Error> allErrors = decResult.errors; message.setSigning(decResult.signing); // parse ParsingResult parsingResult = null; if (decResult.decryptedStream.isPresent()) { // parse encrypted CPIM content String myUID = keys.myKey.getUserId(); String senderUID = keys.otherKey.userID; String encrText = EncodingUtils.getString(decResult.decryptedStream.get().toByteArray(), CPIMMessage.CHARSET); parsingResult = parseCPIM(encrText, myUID, senderUID); allErrors.addAll(parsingResult.errors); } // set errors message.setSecurityErrors(allErrors); if (parsingResult != null && parsingResult.content != null) { // everything went better than expected LOGGER.info("decryption successful"); message.setDecryptedContent(parsingResult.content); } else { LOGGER.warning("decryption failed"); } }