Guest User

Untitled

a guest
Jun 21st, 2012
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. BufferedInputStream To String Conversion? [closed]
  2. BufferedInputStream in = new BufferedInputStream(sktClient.getInputStream() );
  3. String a= in.read();
  4.  
  5. BufferedInputStream in = new BufferedInputStream(sktClient.getInputStream() );
  6. byte[] contents = new byte[1024];
  7.  
  8. int bytesRead=0;
  9. String strFileContents;
  10. while( (bytesRead = bin.read(contents)) != -1){
  11. strFileContents = new String(contents, 0, bytesRead);
  12. }
  13. System.out.print(strFileContents);
  14.  
  15. new String(ByteStreams.toByteArray(inputStream),Charsets.UTF_8);
  16.  
  17. IOUtils.toString(inputStream, "UTF-8")
  18.  
  19. public String convertStreamToString(InputStream is)
  20. throws IOException {
  21. /*
  22. * To convert the InputStream to String we use the
  23. * Reader.read(char[] buffer) method. We iterate until the
  24. 35. * Reader return -1 which means there's no more data to
  25. 36. * read. We use the StringWriter class to produce the string.
  26. 37. */
  27. if (is != null) {
  28. Writer writer = new StringWriter();
  29.  
  30. char[] buffer = new char[1024];
  31. try
  32. {
  33. Reader reader = new BufferedReader(
  34. new InputStreamReader(is, "UTF-8"));
  35. int n;
  36. while ((n = reader.read(buffer)) != -1)
  37. {
  38. writer.write(buffer, 0, n);
  39. }
  40. }
  41. finally
  42. {
  43. is.close();
  44. }
  45. return writer.toString();
  46. } else {
  47. return "";
  48. }
  49. }
  50.  
  51. String text = IOUtils.toString(sktClient.getInputStream());
Advertisement
Add Comment
Please, Sign In to add comment