Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Checking for duplicate jms Textmessages in a folder

Posted on 2013-11-06
3
Medium Priority
?
134 Views
Last Modified: 2013-11-07
Hi guys
I have a scenario where I have a folder c:\messages.
I am listening a queue for text messages (jms.Textmessage)
I have two requirments
To save the Textmessage in the messages folder. The Textmessage file name should be the messageid.( messageid is unique for each Textmessage).

If the Textmessage file already exists in the messages folder then it should not be saved.

Any idea how I can go about doing this? Any help with code is greatly appreciated.
Thanks.
0
Comment
Question by:royjayd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 36

Expert Comment

by:mccarl
ID: 39629315
Have you already got some code that we can start from?
0
 

Author Comment

by:royjayd
ID: 39629344
Yeah,


// my listener which is listening for Textmessages on the Queue.
Public class Mylistener{

Public void onMessage(Jaxax.jms.Message message){
if (message instanceOf Jaxax.jms.TextMessage){
String messageId = message.getJmsMessageId();

// here I want to check if a Textmessage file with filename as messageId already exists in the
// C:\messages folder. If it doesn't exist then add the Textmessage to the messages folder.
}
}
}

Thx.
0
 
LVL 36

Accepted Solution

by:
mccarl earned 2000 total points
ID: 39629375
Ok, so the code that you would need to insert is simply something like this...
String filename = "C:\\messages\\" + messageId;             // Customize this further if you want all the files to have a file extension, etc  (eg. you could add        + ".txt"      to the end of that to make them all text files)
File file = new File(fileName);
if (!file.exists()) {
    FileOutputStream os = new FileOutputStream(file);
    os.write(((TextMessage) message).getText().getBytes());
    os.close();
}

Open in new window

0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question