Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- JSONArray jSONArray = jSONObject.getJSONArray(JSONConstant.BYTE_ARRAY_LIST);
- int len = jSONArray.length();
- for (int i = 0; i < len; i++) {
- byte[] b = jSONArray.get(i).toString().getBytes();
- //Following line creates pdf file of this byte arry "b"
- FileCreator.createPDF(b, "test PDF From Web Resource.pdf");
- }
- }
- FileCreator.createPDF(b, "test PDF From Web Resource.pdf");
- JSONObject jSONObject = new JSONObject();
- jSONObject.put(JSONConstant.BYTE_ARRAY_LIST, bList);
- public static void main(String... args) throws JSONException{
- JSONObject o = new JSONObject();
- byte[] b = "hello".getBytes();
- o.put("A", b);
- System.out.println(o.get("A"));
- }
- [B@1bd8c6e
- <dependency>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- <version>1.6</version>
- <type>jar</type>
- </dependency>
- byte[] bArray=jSONObject.getString(key).toString().getBytes();
- byte[] bArray=(myByteArray);
- //Following is the code that encoded my byte array and kept on String
- String encodedString = org.apache.commons.codec.binary.Base64.encodeBase64String(bArray);
- jSONObject.put(JSONConstant.BYTE_ARRAY_LIST , encodedString);
- String getBackEncodedString = jSONObject.getString(JSONConstant.BYTE_ARRAY_LIST);
- //Following code decodes to encodedString and returns original byte array
- byte[] backByte = org.apache.commons.codec.binary.Base64.decodeBase64(getBackEncodedString);
- //Creating pdf file of this backByte
- FileCreator.createPDF(backByte, "fileAfterJSONObject.pdf");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement