Guest User

Untitled

a guest
Oct 1st, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. /**
  2. * TEST JSON
  3. */
  4. String convertToJsonArrayWithImageForMovieDetailTest(ResultSet rs) {
  5.  
  6. System.out.println("I am insied json converter");
  7. JSONArray list = new JSONArray();
  8. JSONObject obj ;
  9.  
  10. //File file;
  11. File locatedFile;
  12. FileInputStream fileInputStream;
  13. try {
  14.  
  15. while (rs.next()) {
  16. obj = new JSONObject();
  17. System.out.println("inside RS");
  18. System.out.println("date is there ha ha ");
  19.  
  20. obj.put("movie_name", rs.getString("name"));
  21. obj.put("movie_gener", rs.getString("type"));
  22. String is_free_stuff = rs.getString("is_free_stuff");
  23. if (is_free_stuff == "no") {
  24. is_free_stuff = "PAID";
  25. } else {
  26. is_free_stuff = "FREE";
  27. }
  28. obj.put("movie_type", is_free_stuff);
  29.  
  30. //String movie_image = rs.getString("preview_image");
  31.  
  32. //this does not work
  33. String movie_image = "http://www.hamropan.com/stores/slider/2016-09-10-852311027.jpg";
  34.  
  35. //this works for me
  36. // file = new File("C:/Users/Java Engineer/Desktop/Nike Zoom Basketball.jpg");
  37. locatedFile = new File(movie_image);
  38. // Reading a Image file from file system
  39. fileInputStream = new FileInputStream(locatedFile);
  40. if (locatedFile == null) {
  41. obj.put("movie_image", "NULL");
  42. } else {
  43. byte[] iarray = new byte[(int) locatedFile.length()];
  44. fileInputStream.read(iarray);
  45. byte[] img64 = com.sun.jersey.core.util.Base64
  46. .encode(iarray);
  47. String imageString = new String(img64);
  48. obj.put("movie_image", imageString);
  49. }
  50. list.add(obj);
  51. }
  52.  
  53.  
  54. } catch (Exception e) {
  55. e.printStackTrace();
  56. }
  57. return list.toString();
  58. }
Add Comment
Please, Sign In to add comment