I have made a jNetPcap project for which the code is below:
When I try executing the program I got this as result in the console tag:
"Can't read list of devices, error is"
and since jNetPcap depends on Libpcap C library which requires root privileges, it's obvious that's the reason why my program could not run. Could someone help me on that problem?
Note: I have tried to create .jar file in the src folder and create an .exe from this .jar file, but it throws the following errors:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jnetpcap/packet/PcapPacketHandler
Caused by: java.lang.ClassNotFoundException: org.jnetpcap.packet.PcapPacketHandler
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: Pcap_capture. Program will exit.
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.jnetpcap.Pcap;
import org.jnetpcap.PcapIf;
import org.jnetpcap.packet.PcapPacket;
import org.jnetpcap.packet.PcapPacketHandler;
/**
* Here is the output generated by this example :
*
* Network devices found:
* #0: \Device\NPF_{BC81C4FC-242F-4F1C-9DAD-EA9523CC992D} [Intel(R) PRO/100 VE]
* #1: \Device\NPF_{E048DA7F-D007-4EEF-909D-4238F6344971} [VMware Virtual Ethernet Adapter]
* #2: \Device\NPF_{5B62B373-3EC1-460D-8C71-54AA0BF761C7} [VMware Virtual Ethernet Adapter]
* #3: \Device\NPF_GenericDialupAdapter [Adapter for generic dialup and VPN capture]
*
* Choosing 'Intel(R) PRO/100 VE) ' on your behalf:
* Received packet at Tue Nov 03 18:52:42 EST 2009 caplen=1362 len=1362 jNetPcap rocks!
* Received packet at Tue Nov 03 18:52:45 EST 2009 caplen=82 len=82 jNetPcap rocks!
* Received packet at Tue Nov 03 18:52:45 EST 2009 caplen=145 len=145 jNetPcap rocks!
* Received packet at Tue Nov 03 18:52:45 EST 2009 caplen=62 len=62 jNetPcap rocks!
* Received packet at Tue Nov 03 18:52:45 EST 2009 caplen=164 len=164 jNetPcap rocks!
* Received packet at Tue Nov 03 18:52:45 EST 2009 caplen=62 len=62 jNetPcap rocks!
* Received packet at Tue Nov 03 18:52:45 EST 2009 caplen=54 len=54 jNetPcap rocks!
* Received packet at Tue Nov 03 18:52:45 EST 2009 caplen=1073 len=1073 jNetPcap rocks!
* Received packet at Tue Nov 03 18:52:45 EST 2009 caplen=1514 len=1514 jNetPcap rocks!
* Received packet at Tue Nov 03 18:52:45 EST 2009 caplen=279 len=279 jNetPcap rocks!
*/
public class Pcap_capture {
/**
* Main startup method
*
* #param args
* ignored
* #throws IOException
*/
public static void main(String[] args) throws IOException {
List<PcapIf> alldevs = new ArrayList<PcapIf>(); // Will be filled with NICs
StringBuilder errbuf = new StringBuilder(); // For any error msgs
boolean retval = false;
/***************************************************************************
* First get a list of devices on this system
**************************************************************************/
Process suprocess = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(suprocess.getOutputStream());
DataInputStream is = new DataInputStream(suprocess.getInputStream());
if (null != os && null != is)
{
// Getting the id of the current user to check if this is root
os.writeBytes("id\n");
os.flush();
String currUid = is.readLine();
boolean exitSu = false;
if (null == currUid)
{
retval = false;
exitSu = false;
}
else if (true == currUid.contains("uid=0"))
{
retval = true;
exitSu = true;
}
else
{
retval = false;
exitSu = true;
}
if (exitSu)
{
os.writeBytes("exit\n");
os.flush();
}
}
int r = Pcap.findAllDevs(alldevs, errbuf);
if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
System.err.printf("Can't read list of devices, error is %s", errbuf
.toString());
return;
}
System.out.println("Network devices found:");
int i = 0;
for (PcapIf device : alldevs) {
String description =
(device.getDescription() != null) ? device.getDescription()
: "No description available";
System.out.printf("#%d: %s [%s]\n", i++, device.getName(), description);
}
PcapIf device = alldevs.get(0); // We know we have atleast 1 device
System.out
.printf("\nChoosing '%s' on your behalf:\n",
(device.getDescription() != null) ? device.getDescription()
: device.getName());
/***************************************************************************
* Second we open up the selected device
**************************************************************************/
int snaplen = 64 * 1024; // Capture all packets, no trucation
int flags = Pcap.MODE_PROMISCUOUS; // capture all packets
int timeout = 10 * 1000; // 10 seconds in millis
Pcap pcap =
Pcap.openLive(device.getName(), snaplen, flags, timeout, errbuf);
if (pcap == null) {
System.err.printf("Error while opening device for capture: "
+ errbuf.toString());
return;
}
/***************************************************************************
* Third we create a packet handler which will receive packets from the
* libpcap loop.
**************************************************************************/
PcapPacketHandler<String> jpacketHandler = new PcapPacketHandler<String>() {
public void nextPacket(PcapPacket packet, String user) {
System.out.printf("Received packet at %s caplen=%-4d len=%-4d %s\n",
new Date(packet.getCaptureHeader().timestampInMillis()),
packet.getCaptureHeader().caplen(), // Length actually captured
packet.getCaptureHeader().wirelen(), // Original length
user // User supplied object
);
}
};
/***************************************************************************
* Fourth we enter the loop and tell it to capture 10 packets. The loop
* method does a mapping of pcap.datalink() DLT value to JProtocol ID, which
* is needed by JScanner. The scanner scans the packet buffer and decodes
* the headers. The mapping is done automatically, although a variation on
* the loop method exists that allows the programmer to sepecify exactly
* which protocol ID to use as the data link type for this pcap interface.
**************************************************************************/
pcap.loop(10, jpacketHandler, "jNetPcap rocks!");
/***************************************************************************
* Last thing to do is close the pcap handle
**************************************************************************/
pcap.close();
}
}
I'm not sure if you want help with (1) "Can't read list of devices" error or with (2) "Exception in Thread...." error.
Error message (2) means it cannot find the file specified(specified in the error message).
Extract the "com" and "org" folders from the jnetpcap.jar file and place them in the .jar file of your program. For example if the .jar file of your program is called "test.jar", place the above folders in test.jar
You can remove or put files/folders in a .jar file by using any compression program such as 7-zip.
Related
My console output is --
Exception in thread "main" java.lang.IllegalArgumentException: size of array must be MAX_ID_COUNT size
at org.jnetpcap.packet.JScanner.loadScanners(Native Method)
at org.jnetpcap.packet.JScanner.reloadAll(JScanner.java:376)
at org.jnetpcap.packet.JScanner.<init>(JScanner.java:313)
at org.jnetpcap.packet.JScanner.<init>(JScanner.java:293)
at org.jnetpcap.packet.JPacket.getDefaultScanner(JPacket.java:621)
at org.jnetpcap.packet.JPacket.scan(JPacket.java:1094)
at org.jnetpcap.packet.JMemoryPacket.<init>(JMemoryPacket.java:387)
at org.jnetpcap.packet.JMemoryPacket.<init>(JMemoryPacket.java:440)
at ClassicPcapExample.main(ClassicPcapExample.java:128)
Code:
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.jnetpcap.Pcap;
import org.jnetpcap.PcapIf;
import org.jnetpcap.packet.JMemoryPacket;
import org.jnetpcap.packet.JPacket;
import org.jnetpcap.packet.PcapPacket;
import org.jnetpcap.packet.PcapPacketHandler;
import org.jnetpcap.protocol.JProtocol;
import org.jnetpcap.protocol.lan.Ethernet;
import org.jnetpcap.protocol.network.Ip4;
import org.jnetpcap.protocol.tcpip.Tcp;
public class ClassicPcapExample{
/**
* Main startup method
*
* #param args
* ignored
*/
public static void main(String[] args) {
List<PcapIf> alldevs = new ArrayList<PcapIf>(); // Will be filled with NICs
StringBuilder errbuf = new StringBuilder(); // For any error msgs
/***************************************************************************
* First get a list of devices on this system
**************************************************************************/
int r = Pcap.findAllDevs(alldevs, errbuf);
if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
System.err.printf("Can't read list of devices, error is %s", errbuf
.toString());
return;
}
System.out.println("Network devices found:");
int i = 0;
for (PcapIf device : alldevs) {
String description =
(device.getDescription() != null) ? device.getDescription()
: "No description available";
System.out.printf("#%d: %s [%s]\n", i++, device.getName(), description);
}
PcapIf device = alldevs.get(0); // We know we have atleast 1 device
System.out
.printf("\nChoosing '%s' on your behalf:\n",
(device.getDescription() != null) ? device.getDescription()
: device.getName());
/***************************************************************************
* Second we open up the selected device
**************************************************************************/
int snaplen = 64 * 1024; // Capture all packets, no truncation
int flags = Pcap.MODE_PROMISCUOUS; // capture all packets
int timeout = 10 * 1000; // 10 seconds in milliseconds
Pcap pcap =
Pcap.openLive(device.getName(), snaplen, flags, timeout, errbuf);
if (pcap == null) {
System.err.printf("Error while opening device for capture: "
+ errbuf.toString());
return;
}
/***************************************************************************
* Third we create a packet handler which will receive packets from the
* libpcap loop.
**************************************************************************/
PcapPacketHandler<String> jpacketHandler = new PcapPacketHandler<String>() {
public void nextPacket(PcapPacket packet, String user) {
System.out.printf("Received packet at %s caplen=%-4d len=%-4d %s\n",
new Date(packet.getCaptureHeader().timestampInMillis()),
packet.getCaptureHeader().caplen(), // Length actually captured
packet.getCaptureHeader().wirelen(), // Original length
user // User supplied object
);
}
};
/***************************************************************************
* Fourth we enter the loop and tell it to capture 10 packets. The loop
* method does a mapping of pcap.datalink() DLT value to JProtocol ID, which
* is needed by JScanner. The scanner scans the packet buffer and decodes
* the headers. The mapping is done automatically, although a variation on
* the loop method exists that allows the programmer to specify exactly
* which protocol ID to use as the data link type for this pcap interface.
**************************************************************************/
//pcap.loop(5, jpacketHandler, "jNetPcap rocks!");//GETTING AN ERROR AT THIS LINE!!
pcap.close();
}
}
I started getting the same issue, when I downgraded to 1.3 from 1.4.r1425, which I was due to the 1.4.r1425 version jnetpcap.dll file which I had forgotten to replace with the 1.3 version dll. I would suggest you to ensure that you have the correct version of the native library file available (.dll for windows/.so for linux -as per ur environment).
I am reading this topic about java Thread.
And there is an example:
import java.util.Vector;
class Producer extends Thread {
static final int MAXQUEUE = 5;
private Vector messages = new Vector();
#Override
public void run() {
try {
while (true) {
putMessage();
//sleep(5000);
}
} catch (InterruptedException e) {
}
}
private synchronized void putMessage() throws InterruptedException {
while (messages.size() == MAXQUEUE) {
wait();
}
messages.addElement(new java.util.Date().toString());
System.out.println("put message");
notify();
//Later, when the necessary event happens, the thread that is running it calls notify() from a block synchronized on the same object.
}
// Called by Consumer
public synchronized String getMessage() throws InterruptedException {
notify();
while (messages.size() == 0) {
wait();//By executing wait() from a synchronized block, a thread gives up its hold on the lock and goes to sleep.
}
String message = (String) messages.firstElement();
messages.removeElement(message);
return message;
}
}
class Consumer extends Thread {
Producer producer;
Consumer(Producer p) {
producer = p;
}
#Override
public void run() {
try {
while (true) {
String message = producer.getMessage();
System.out.println("Got message: " + message);
//sleep(200);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
Producer producer = new Producer();
producer.start();
new Consumer(producer).start();
}
}
And the author said:
A possible output sequence:
Got message: Fri Dec 02 21:37:21 EST 2011
put message
put message
put message
put message
put message
Got message: Fri Dec 02 21:37:21 EST 2011
Got message: Fri Dec 02 21:37:21 EST 2011
Got message: Fri Dec 02 21:37:21 EST 2011
Got message: Fri Dec 02 21:37:21 EST 2011
Got message: Fri Dec 02 21:37:21 EST 2011
put message
put message
put message
put message
put message
Got message: Fri Dec 02 21:37:21 EST 2011
Got message: Fri Dec 02 21:37:21 EST 2011
Got message: Fri Dec 02 21:37:21 EST 2011
But when I run this code I got this result:
put message
put message
put message
put message
put message
put message
Got message: Tue Sep 24 16:44:59 CST 2013
Got message: Tue Sep 24 16:45:00 CST 2013
put message
Got message: Tue Sep 24 16:45:00 CST 2013
put message
Got message: Tue Sep 24 16:45:00 CST 2013
put message
..............
What is the problem?
Any one can explain it for me?
The author's entire point is that the order of tasks between different threads is unpredictable. He printed a possible output sequence, but many, many others are possible.
In addition to the already explained output I must add that the book you are reading doesn't seem to be a very good source to learn from. It teaches to:
extend Thread, a notorious bad practice;
invoke wait and notify on a Thread instance—another known, documented bad practice.
use the wait and notify mechanism in the first place, which has mostly been superseded by much more convenient and simpler java.util.concurrent tools such as CountDownLatch, Semaphore, and Phaser.
Your version of output is correct. Because "Got Message" is not possible without "put message". I mean, if there is no message in queue then how can you retrieve the message. Developer in his example might have given sample output which was not actual code run output but self made just for example.
Remember :
[Count of total "Got message" till particular line] will always be <= [Count of total "put message" till that very line]
The only strange thing is that there are 6 consecutive "put message" which seems to be impossible because the maximum queue size is 5.
But this is because the code sequence
producer.getMessage()
System.out.println("Got message: " + message);
is - of course - not atomic and has been interrupted by a thread switch.
By the way - always use notifyAll() instead of notify.
I am trying to load up my own UDF in pig. I have made it into a jar using eclipse's export function. I am trying to run it locally so I can make sure it works before I put the jar on HDFS. When running it locally, I get the following error:
ERROR 1070: Could not resolve myudfs.MONTH using imports: [, org.apache.pig.builtin., org.apache.pig.impl.builtin.]
Script
REGISTER myudfs.jar;
--DEFINE MONTH myudfs.MONTH;
A = load 'access_log_Jul95' using PigStorage(' ') as (ip:chararray, dash1:chararray, dash2:chararray, date:chararray, getRequset:chararray, status:int, port:int);
B = FOREACH A GENERATE myudfs.MONTH(date);
DUMP B;
Function
package myudfs;
import java.io.IOException;
import org.apache.pig.EvalFunc;
import org.apache.pig.data.Tuple;
import org.apache.pig.impl.util.WrappedIOException;
#SuppressWarnings("deprecation")
public class HOUR extends EvalFunc<String>
{
public String exec(Tuple input) throws IOException {
if (input == null || input.size() == 0)
return null;
try{
String str = (String)input.get(0);
return str.substring(1, 3);
}catch(Exception e){
throw WrappedIOException.wrap("Caught exception processing input row ", e);
}
}
}
Working Directory
1.pig 2.pig bin myudfs.jar
pig.jar pig-withouthadoop.jar src/
Running command
pig -x local 2.pig
Structure of jar
0 Thu May 02 12:16:26 MDT 2013 META-INF/
68 Thu May 02 12:16:26 MDT 2013 META-INF/MANIFEST.MF
0 Thu May 02 12:05:50 MDT 2013 myudfs/
573 Thu May 02 12:15:10 MDT 2013 myudfs/HOUR.java
I am really close to start chucking monitors, so I am just looking for some help and direction. Let me know what could be wrong.
Your UDF class name is called HOUR
So shouldn't your pig latin be this?
B = FOREACH A GENERATE myudfs.HOUR(date);
I'm trying to note down workstation/System screen Lock and Unlock of each employee working in windows OS. I needed to store these record in a DataBase, using JAVA. I have searched all over and got on idea how to do it using JAVA. where ever I searched I get code for VB only.
You can do it in pure Java using JNA. Add jna.jar and jna-platform.jar to your project. And in this file com.sun.jna.platform.win32.Win32WindowDemo there is a full example of lock and unlock listener and much more. Here is the necessary code from thah Win32WindowDemo:
public class WorkstationLockListening implements WindowProc
{
/**
* Instantiates a new win32 window test.
*/
public WorkstationLockListening()
{
// define new window class
final WString windowClass = new WString("MyWindowClass");
final HMODULE hInst = Kernel32.INSTANCE.GetModuleHandle("");
WNDCLASSEX wClass = new WNDCLASSEX();
wClass.hInstance = hInst;
wClass.lpfnWndProc = WorkstationLockListening.this;
wClass.lpszClassName = windowClass;
// register window class
User32.INSTANCE.RegisterClassEx(wClass);
getLastError();
// create new window
final HWND hWnd = User32.INSTANCE.CreateWindowEx(User32.WS_EX_TOPMOST, windowClass, "'TimeTracker hidden helper window to catch Windows events", 0, 0, 0, 0, 0, null, // WM_DEVICECHANGE contradicts parent=WinUser.HWND_MESSAGE
null, hInst, null);
getLastError();
System.out.println("window sucessfully created! window hwnd: " + hWnd.getPointer().toString());
Wtsapi32.INSTANCE.WTSRegisterSessionNotification(hWnd, Wtsapi32.NOTIFY_FOR_THIS_SESSION);
MSG msg = new MSG();
while (User32.INSTANCE.GetMessage(msg, hWnd, 0, 0) != 0)
{
User32.INSTANCE.TranslateMessage(msg);
User32.INSTANCE.DispatchMessage(msg);
}
/// This code is to clean at the end. You can attach it to your custom application shutdown listener
Wtsapi32.INSTANCE.WTSUnRegisterSessionNotification(hWnd);
User32.INSTANCE.UnregisterClass(windowClass, hInst);
User32.INSTANCE.DestroyWindow(hWnd);
System.out.println("program exit!");
}
/*
* (non-Javadoc)
*
* #see com.sun.jna.platform.win32.User32.WindowProc#callback(com.sun.jna.platform .win32.WinDef.HWND, int, com.sun.jna.platform.win32.WinDef.WPARAM, com.sun.jna.platform.win32.WinDef.LPARAM)
*/
public LRESULT callback(HWND hwnd, int uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WinUser.WM_DESTROY:
{
User32.INSTANCE.PostQuitMessage(0);
return new LRESULT(0);
}
case WinUser.WM_SESSION_CHANGE:
{
this.onSessionChange(wParam, lParam);
return new LRESULT(0);
}
default:
return User32.INSTANCE.DefWindowProc(hwnd, uMsg, wParam, lParam);
}
}
/**
* Gets the last error.
*
* #return the last error
*/
public int getLastError()
{
int rc = Kernel32.INSTANCE.GetLastError();
if (rc != 0)
System.out.println("error: " + rc);
return rc;
}
/**
* On session change.
*
* #param wParam
* the w param
* #param lParam
* the l param
*/
protected void onSessionChange(WPARAM wParam, LPARAM lParam)
{
switch (wParam.intValue())
{
case Wtsapi32.WTS_SESSION_LOCK:
{
this.onMachineLocked(lParam.intValue());
break;
}
case Wtsapi32.WTS_SESSION_UNLOCK:
{
this.onMachineUnlocked(lParam.intValue());
break;
}
}
}
/**
* On machine locked.
*
* #param sessionId
* the session id
*/
protected void onMachineLocked(int sessionId)
{
System.out.println("Machine locked right now!");
}
/**
* On machine unlocked.
*
* #param sessionId
* the session id
*/
protected void onMachineUnlocked(int sessionId)
{
System.out.println("Machine unlocked right now!");
}
}
We have solved this problem in Google Group Workstation Lock / Unlock listener. You can find there my own implementation but this code right here is much better! Enjoy :)
One more way, without any windows system libs, ect.
Main idea - screenshots for locked PC will be totally black, so you can take one and simply check that some critical points are black
-16777216 - magic number, that means FFFFFFFFFF000000xH and last 00 00 00 means RGB color code (actually black color)
BufferedImage image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
boolean isBlack;
isBlack = (image.getRGB(1,1)==-16777216)
&(image.getRGB(1,image.getHeight()-1)==-16777216)
&(image.getRGB(image.getWidth()-1,1)==-16777216)
&(image.getRGB(image.getWidth()-1,image.getHeight()-1)==-16777216)
&(image.getRGB(image.getWidth()/2,image.getHeight()/2)==-16777216);
return isBlack;
Actually, there could be only one case with incorrect lock identification - when you have totally black wallpaper, with hidden taskbar and hidden icons.
Use JNI (Java Native Interface) to invoke functions from the Windows system dll.
Here is the sample code for use of functions which check workstation locking state: http://brutaldev.com/post/2008/05/23/Checking-if-the-workstation-is-locked.aspx
And here is the article about invoking dll-functions from Java via JNI:
http://edn.embarcadero.com/article/20679
With JDK9 (JDK11) you can use java.awt.Desktop :
Desktop tempDesktop = Desktop.getDesktop();
tempDesktop.addAppEventListener(new UserSessionListener() {
#Override
public void userSessionDeactivated(UserSessionEvent aE) {
LOG.info("Desktop:userSessionDeactivated Reason=" + aE.getReason() + " Source=" + aE.getSource());
// Windows Key L:
// Tue Aug 31 11:22:49 CEST 2021:info:MainController:userSessionDeactivated Reason=LOCK
// Close Lid:
// Tue Aug 31 11:24:38 CEST 021:info:MainController:userSessionDeactivated Reason=LOCK
// Tue Aug 31 11:24:39 CEST 2021:info:MainController:systemAboutToSleep Source=java.awt.Desktop#741f67cd
ptcUserStatus = PtcUserStatus.AWAY;
}
#Override
public void userSessionActivated(UserSessionEvent aE) {
LOG.info("Desktop:userSessionActivated Reason=" + aE.getReason() + " Source=" + aE.getSource());
// Logon after Windows Key L
// Tue Aug 31 11:22:53 CEST 2021:info:MainController:userSessionActivated Reason=LOCK
// Open Lid:
// Tue Aug 31 11:24:56 CEST 2021:info:MainController:systemAwoke Source=java.awt.Desktop#741f67cd
// Tue Aug 31 11:25:06 CEST 2021:info:MainController:userSessionActivated Reason=LOCK
ptcUserStatus = PtcUserStatus.BACK;
}
});
Have a look at Unlock Administrator
The purpose of the program is allow the admin at assign who can unlock the computer but it also has logging capability. It also allows you to run a script whenever the computer is locked or unlocked. This may be helpful to you.
Using JDIC Library,
To Check the system is Locked or Not
SystemInfo.isSessionLocked()
i have com.sun.mail.pop3.POP3Message object, in that content i have the following format code,
Delivery has failed to these recipients or distribution lists:
anandnarekar#gmail.coxm
An error occurred while trying to deliver this message to the recipient's e-mail address. Microsoft Exchange will not try to redeliver this message for you. Please try resending this message, or provide the following diagnostic text to your system administrator.
Diagnostic information for administrators:
Generating server: delivery
anandnarekar#gmail.coxm
#< #5.0.0 smtp; 554 5.4.4 [internal] Domain Lookup Failed> #SMTP#
Original message headers:
X-AuditID: ac1ec426-b7b3aae0000036b3-7c-4e3009fd2d34
Received: from SVHJ0032 ( [172.30.1.11]) by svhj0367.ideaconnect.com (Symantec
Brightmail Gateway) with SMTP id BA.D0.14003.DF9003E4; Wed, 27 Jul 2011
18:22:13 +0530 (IST)
Message-ID: <1502435725.1311770110726.JavaMail.wasadmin#SVHJ0032>
Date: Wed, 27 Jul 2011 18:05:10 +0530
From: <ebill.mh#idea.adityabirla.com>
To: <anandnarekar#gmail.coxm>
Subject: Your Idea Bill
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_67575_1171670486.1311770110725"
Thread-Topic: rsweb_7202772011060510
X-Brightmail-Tracker: AAAAAQAAAZE= </pre>
> Blockquote
how can I retrieve the value of Thread-Topic?
Loop through the text that gets returned to you and look for "Thread-Topic".
Once you find it, you can use the indexOf and substring functions to parse out your topic.
Sample code shown below:
E:\jdk1.6.0_23\bin>type Test.java
public class Test
{
public static void main(String[] args) {
String str = "Thread-Topic: rsweb_7202772011060510";
if (str.indexOf("Thread-Topic") != -1) {
String topic = str.substring(str.indexOf(":") + 2);
System.out.println(topic);
}
}
}
E:\jdk1.6.0_23\bin>javac Test.java
E:\jdk1.6.0_23\bin>java Test
rsweb_7202772011060510