Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3177

Re: Generate PDF from URL

$
0
0

Hi Emir!

 

You can use following method in your java mapping or UDF (though I didn't test it myself as UDF) to get byte array from URL link:

 

     public byte[] getByteArrayFromURL(String url) {

          ByteArrayOutputStream os=new ByteArrayOutputStream();

          try {

               URL httpURL = new URL(url);

               ReadableByteChannel rbc = Channels.newChannel(httpURL.openStream());

               WritableByteChannel osc=Channels.newChannel(os);

 

               ByteBuffer byteBuf=ByteBuffer.allocate(65536);

               while (rbc.read(byteBuf) != -1) {

                    byteBuf.flip();

                    osc.write(byteBuf);

                    byteBuf.clear();

               }

          }

          catch (Exception e) {

               e.printStackTrace();

          }

          return os.toByteArray();

     }

 

Regards, Evgeniy.


Viewing all articles
Browse latest Browse all 3177

Trending Articles