Tuesday, 28 January 2020

Get base64 from excel created using Apache POI in java


Apache POI is the most common way to create excel dynamically or statically in our java code. However, most of the times we do it by importing maven dependency for POI and giving the path to excel in FileOutputStream.

Use of FileOutputStreams, doesn't work when the same created excel needs to be transferred over network (encryption is needed --> base64 format). 

Chin up!!!

 ByteArrayOutputStream is the option to go for it (Create excel using Apache POI, write it in workbook using ByteArrayOutputStream, convert it in byte followed by base64 encoder).
Below is the snippet:

ByteArrayOutputStream b = new ByteArrayOutputStream();
try {
    workbook.write(b);
}catch(FileNotFoundException e){
  e.printStackTrace();
}catch(Exception e){
  e.printStackTrace();
}
byte[] bytes = bos.toByteArray();
Base64.encodeBase64String(bytes);

This solution worked for me, As first excel was created using Apache POI then applied above code and converted it to base64, which when decoded over network, encoded file was got opened in a excel application as expected. 😀😀

Monday, 27 January 2020

My missing piece???


Oh!! It's just a *COMPLETE A PICTURE PUZZLE GAME*,  why am I posting this.
In a first thought, yeah!! True it is just a simple game to place 4th picture and complete the hen....
But....

Did you think, just one missing leg is making the hen's life incomplete. So, is our life . Everyone component has a massive role.....

May be for grown ups, above picture is a seconds game but for a child, it's full brain indulging activity as well as for a hen, her leg is a life line above.

Our life is also placed on the same platform. Life is just a bowl of cherries only if your surrounding is your reason to smile . If one of the part goes missing from life then it is no more like bed of Roses...⚘⚘🌹

But the positivity of the life is of you  hit the nail on the head,  then you know which is the missing piece for hen's leg as well as our life  then it is no more a missing piece, just wait for the right time to place the piece.......And the life will be as beautiful as ever :)  ...
Happy reading.... :) 

Tech blog.... technicality of a life ...