Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * TEST JSON
- */
- String convertToJsonArrayWithImageForMovieDetailTest(ResultSet rs) {
- System.out.println("I am insied json converter");
- JSONArray list = new JSONArray();
- JSONObject obj ;
- //File file;
- File locatedFile;
- FileInputStream fileInputStream;
- try {
- while (rs.next()) {
- obj = new JSONObject();
- System.out.println("inside RS");
- System.out.println("date is there ha ha ");
- obj.put("movie_name", rs.getString("name"));
- obj.put("movie_gener", rs.getString("type"));
- String is_free_stuff = rs.getString("is_free_stuff");
- if (is_free_stuff == "no") {
- is_free_stuff = "PAID";
- } else {
- is_free_stuff = "FREE";
- }
- obj.put("movie_type", is_free_stuff);
- //String movie_image = rs.getString("preview_image");
- //this does not work
- String movie_image = "http://www.hamropan.com/stores/slider/2016-09-10-852311027.jpg";
- //this works for me
- // file = new File("C:/Users/Java Engineer/Desktop/Nike Zoom Basketball.jpg");
- locatedFile = new File(movie_image);
- // Reading a Image file from file system
- fileInputStream = new FileInputStream(locatedFile);
- if (locatedFile == null) {
- obj.put("movie_image", "NULL");
- } else {
- byte[] iarray = new byte[(int) locatedFile.length()];
- fileInputStream.read(iarray);
- byte[] img64 = com.sun.jersey.core.util.Base64
- .encode(iarray);
- String imageString = new String(img64);
- obj.put("movie_image", imageString);
- }
- list.add(obj);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return list.toString();
- }
Add Comment
Please, Sign In to add comment