Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. JSONArray jSONArray = jSONObject.getJSONArray(JSONConstant.BYTE_ARRAY_LIST);
  2. int len = jSONArray.length();
  3. for (int i = 0; i < len; i++) {
  4. byte[] b = jSONArray.get(i).toString().getBytes();
  5. //Following line creates pdf file of this byte arry "b"
  6. FileCreator.createPDF(b, "test PDF From Web Resource.pdf");
  7.  
  8. }
  9. }
  10.  
  11. FileCreator.createPDF(b, "test PDF From Web Resource.pdf");
  12.  
  13. JSONObject jSONObject = new JSONObject();
  14. jSONObject.put(JSONConstant.BYTE_ARRAY_LIST, bList);
  15.  
  16. public static void main(String... args) throws JSONException{
  17. JSONObject o = new JSONObject();
  18. byte[] b = "hello".getBytes();
  19. o.put("A", b);
  20. System.out.println(o.get("A"));
  21. }
  22.  
  23. [B@1bd8c6e
  24.  
  25. <dependency>
  26. <groupId>commons-codec</groupId>
  27. <artifactId>commons-codec</artifactId>
  28. <version>1.6</version>
  29. <type>jar</type>
  30. </dependency>
  31.  
  32. byte[] bArray=jSONObject.getString(key).toString().getBytes();
  33.  
  34. byte[] bArray=(myByteArray);
  35. //Following is the code that encoded my byte array and kept on String
  36. String encodedString = org.apache.commons.codec.binary.Base64.encodeBase64String(bArray);
  37. jSONObject.put(JSONConstant.BYTE_ARRAY_LIST , encodedString);
  38.  
  39. String getBackEncodedString = jSONObject.getString(JSONConstant.BYTE_ARRAY_LIST);
  40. //Following code decodes to encodedString and returns original byte array
  41. byte[] backByte = org.apache.commons.codec.binary.Base64.decodeBase64(getBackEncodedString);
  42. //Creating pdf file of this backByte
  43. FileCreator.createPDF(backByte, "fileAfterJSONObject.pdf");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement