Forum Stats

  • 3,752,284 Users
  • 2,250,483 Discussions
  • 7,867,783 Comments

Discussions

QueueSender failed to send compressed file via JMS queue : NullPointerException

user11269666
user11269666 Member Posts: 1
edited May 24, 2016 11:10AM in Java Message Service (JMS)

String fileSource = "C:\\input.txt";

try{

     byte[] buf = new byte[2048]; 

     ByteArrayOutputStream bos = new   ByteArrayOutputStream(1024 * 4);

     ZipOutputStream zos = new ZipOutputStream(bos);    

     BufferedInputStream bis = new BufferedInputStream(new     FileInputStream(fileSource));

    ZipEntry ze = new ZipEntry(fileSource);

    zos.putNextEntry(ze);

    int len;

       while ((len = bis.read(buf)) > 0) {

           zos.write(buf, 0, len);

           }

     bis.close();

     zos.closeEntry();

     zos.close();

    // to send compressed file to onMessage method of the QueueReceiver

    ByteMessage mMessage = new ByteMessage();

     mMessage = mSession.createBytesMessage();

     mMessage.writeBytes(bos.toByteArray());           

     QueueSender.send(mMessage); // this line shows NullPointerException.

Tagged:
This discussion has been closed.