<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Reading a byte array from a json file and then convert it into xlsx file in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/Reading-a-byte-array-from-a-json-file-and-then-convert-it-into/m-p/2359617#M124369</link>
    <description>&lt;P&gt;I have a small use case wherein I need to fetch an excel file from an api response. The api response is of json format and I need to&lt;/P&gt;&lt;P&gt;1.) read the json element which contains byte array (byte[])&lt;/P&gt;&lt;P&gt;2.) convert the byte array to a excel file.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0695b00000HB7wgAAD.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/148404i064DAE274D5A2EF9/image-size/large?v=v2&amp;amp;px=999" role="button" title="0695b00000HB7wgAAD.png" alt="0695b00000HB7wgAAD.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have set the data type as byte[] for my JSON coloumn containing the byte array.&lt;/P&gt;&lt;P&gt;The output.file_contents contains the byte array which I am sending to java routine to convert it into a xlsx file.&lt;/P&gt;&lt;P&gt;The code for my tjava is quite a simple one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;System.out.println(input_row.file_contents);&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;Write.ByteArrayToFile(input_row.file_contents, context.finalPath) ;&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The for my routine is &lt;/P&gt;&lt;P&gt;package routines;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;public class Write {&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;public static void ByteArrayToFile(byte[] input, String filepath) {&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;try&amp;nbsp;&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;java.io.File fp = new java.io.File(filepath);&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;java.io.FileOutputStream fos = new java.io.FileOutputStream(fp);&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;fos.write(input);&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;fos.close();&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;}&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;catch(Exception err)&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;{&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;err.printStackTrace();&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;}&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;}&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;}&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The talend code is executing and also creating an xlsx file at desired location. However, everytime when I open my excel it gives an error as&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0695b00000HB7zBAAT.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/152127i546E1E8AD8B80D29/image-size/large?v=v2&amp;amp;px=999" role="button" title="0695b00000HB7zBAAT.png" alt="0695b00000HB7zBAAT.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help in this will be really apprciated. I think the isse is how I am reading the json file. However when I am trying to print the byte array I can properly see it values as&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0695b00000HB81bAAD.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/143719iCB98C2314B602796/image-size/large?v=v2&amp;amp;px=999" role="button" title="0695b00000HB81bAAD.png" alt="0695b00000HB81bAAD.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 08 Aug 2021 08:34:48 GMT</pubDate>
    <dc:creator>diggi86</dc:creator>
    <dc:date>2021-08-08T08:34:48Z</dc:date>
    <item>
      <title>Reading a byte array from a json file and then convert it into xlsx file</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Reading-a-byte-array-from-a-json-file-and-then-convert-it-into/m-p/2359617#M124369</link>
      <description>&lt;P&gt;I have a small use case wherein I need to fetch an excel file from an api response. The api response is of json format and I need to&lt;/P&gt;&lt;P&gt;1.) read the json element which contains byte array (byte[])&lt;/P&gt;&lt;P&gt;2.) convert the byte array to a excel file.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0695b00000HB7wgAAD.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/148404i064DAE274D5A2EF9/image-size/large?v=v2&amp;amp;px=999" role="button" title="0695b00000HB7wgAAD.png" alt="0695b00000HB7wgAAD.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have set the data type as byte[] for my JSON coloumn containing the byte array.&lt;/P&gt;&lt;P&gt;The output.file_contents contains the byte array which I am sending to java routine to convert it into a xlsx file.&lt;/P&gt;&lt;P&gt;The code for my tjava is quite a simple one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;System.out.println(input_row.file_contents);&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;Write.ByteArrayToFile(input_row.file_contents, context.finalPath) ;&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The for my routine is &lt;/P&gt;&lt;P&gt;package routines;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;public class Write {&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;public static void ByteArrayToFile(byte[] input, String filepath) {&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;try&amp;nbsp;&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;java.io.File fp = new java.io.File(filepath);&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;java.io.FileOutputStream fos = new java.io.FileOutputStream(fp);&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;fos.write(input);&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;fos.close();&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;}&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;catch(Exception err)&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;{&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;err.printStackTrace();&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;}&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;}&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;}&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The talend code is executing and also creating an xlsx file at desired location. However, everytime when I open my excel it gives an error as&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0695b00000HB7zBAAT.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/152127i546E1E8AD8B80D29/image-size/large?v=v2&amp;amp;px=999" role="button" title="0695b00000HB7zBAAT.png" alt="0695b00000HB7zBAAT.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help in this will be really apprciated. I think the isse is how I am reading the json file. However when I am trying to print the byte array I can properly see it values as&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0695b00000HB81bAAD.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/143719iCB98C2314B602796/image-size/large?v=v2&amp;amp;px=999" role="button" title="0695b00000HB81bAAD.png" alt="0695b00000HB81bAAD.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Aug 2021 08:34:48 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Reading-a-byte-array-from-a-json-file-and-then-convert-it-into/m-p/2359617#M124369</guid>
      <dc:creator>diggi86</dc:creator>
      <dc:date>2021-08-08T08:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a byte array from a json file and then convert it into xlsx file</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Reading-a-byte-array-from-a-json-file-and-then-convert-it-into/m-p/2359618#M124370</link>
      <description>&lt;P&gt;To test your routine code, you can use tFileInputRaw to read the whole file as a bytes array. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Shong&lt;/P&gt;</description>
      <pubDate>Mon, 09 Aug 2021 09:12:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Reading-a-byte-array-from-a-json-file-and-then-convert-it-into/m-p/2359618#M124370</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-08-09T09:12:23Z</dc:date>
    </item>
  </channel>
</rss>

