Guest User

Untitled

a guest
Oct 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. Log.d(LOG_TAG, "fileUriString = " + fileUriString);
  2. Uri tempuri = Uri.parse(fileUriString);
  3. InputStream is = cR.openInputStream(tempuri);
  4. String str=is.toString();
  5. byte[] b3=str.getBytes();
  6. Log.d(LOG_TAG, "len of data is " + imageByteArray.length
  7. + " bytes");
  8.  
  9. public byte[] readBytes(InputStream inputStream) throws IOException {
  10. // this dynamically extends to take the bytes you read
  11. ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
  12.  
  13. // this is storage overwritten on each iteration with bytes
  14. int bufferSize = 1024;
  15. byte[] buffer = new byte[bufferSize];
  16.  
  17. // we need to know how may bytes were read to write them to the byteBuffer
  18. int len = 0;
  19. while ((len = inputStream.read(buffer)) != -1) {
  20. byteBuffer.write(buffer, 0, len);
  21. }
  22.  
  23. // and then we can return your byte array.
  24. return byteBuffer.toByteArray();
  25. }
  26.  
  27. byte[] recordData = IOUtils.toByteArray(inStream);
  28.  
  29. while ((len = inputStream.read(buffer)) != -1)
  30.  
  31. while (inputStream.available() >0 && (len = inputStream.read(buffer)) != -1)
  32.  
  33. InputStream is = ...;
  34. byte[] bytes = ByteStream.toByteArray(is);
  35.  
  36. private static byte[] getStringFromInputStream(InputStream is)
  37. {
  38.  
  39. BufferedReader br = null;
  40. StringBuilder sb = new StringBuilder();
  41. byte[] bReturn = new byte[0];
  42.  
  43. String line;
  44. try
  45. {
  46.  
  47. br = new BufferedReader(new InputStreamReader(is, "Big5"));
  48. while ((line = br.readLine()) != null)
  49. {
  50. sb.append(line);
  51. }
  52. String sContent = sb.toString();
  53. bReturn = sContent.getBytes();
  54. }
  55. catch (IOException e)
  56. {
  57. e.printStackTrace();
  58. }
  59. finally
  60. {
  61. if (br != null)
  62. {
  63. try
  64. {
  65. br.close();
  66. }
  67. catch (IOException e)
  68. {
  69. e.printStackTrace();
  70. }
  71. }
  72. }
  73. return bReturn;
  74. }
  75.  
  76. InputStream is=getContentResolver().openInputStream(uri);
  77. InputStreamReader ir=new InputStreamReader(is);
  78. bu=new BufferedReader(ir);
  79. String s;
  80. while ((s=bu.readLine())!=null){
  81. //do something with the line...
  82. }
  83. bu.close();
Add Comment
Please, Sign In to add comment