/**
* Data Packet content Parsing
*
* @ Author hongsoft
*/
Public class packetparserthread extends thread
{
Private Socket socket;
Private bufferedreader in;
Private printwriter out;
Public packetparserthread (socket s) throws ioexception
{
Socket = s;
In = new bufferedreader (New inputstreamreader (socket. getinputstream ()));
Out = new printwriter (New bufferedwriter (New outputstreamwriter (socket
. Getoutputstream (), true );
Start ();
}
Public void run ()
{
Try
{
String STR = in. Readline ();
If (STR = NULL | Str. Length () = 0)
{
// Do nothing
}
Else
{
Doparse (STR, out );
}
}
Catch (ioexception E)
{
E. printstacktrace ();
}
Finally
{
Try
{
Socket. Close ();
}
Catch (ioexception E)
{
E. printstacktrace ();
}
}
}
/**
* All are separated by ox1e.
* @ Param Str
* @ Param out
*/
Public static void doparse (string STR, printwriter out)
{
String [] STRs = Str. Split ("/0x1e ");
If ("0". Equals (STRs [0]) // read the topic
{
Int forumid = integer. parseint (STRs [1]);
Int topicid = integer. parseint (STRs [2]);
Out. println (forumfileoperator. gettopiccontent (forumid, topicid ));
}
Else if ("1". Equals (STRs [0]) // read replies
{
Int forumid = integer. parseint (STRs [1]);
Int topicid = integer. parseint (STRs [2]);
List list = forumfileoperator. getreplylist (forumid, topicid );
// Write the job here
Iterator it = List. iterator ();
While (it. hasnext ())
{
Out. println (it. Next (). tostring ());
}
}
Else if ("2". Equals (STRs [0]) // post
{
Int forumid = integer. parseint (STRs [1]);
Int topicid = integer. parseint (STRs [2]);
Forumfileoperator. addtopic (forumid, topicid, STRs [3]);
}
Else if ("3". Equals (STRs [0]) // resume the post
{
Int forumid = integer. parseint (STRs [1]);
Int topicid = integer. parseint (STRs [2]);
Forumfileoperator. resumetopic (forumid, topicid, STRs [3]);
}
Else if ("4". Equals (STRs [0]) // reply
{
Int forumid = integer. parseint (STRs [1]);
Int topicid = integer. parseint (STRs [2]);
Forumfileoperator. addreply (forumid, topicid, STRs [3], STRs [4], STRs [5]);
}
Else if ("5". Equals (STRs [0]) // Delete the topic
{
Int forumid = integer. parseint (STRs [1]);
Int topicid = integer. parseint (STRs [2]);
Forumfileoperator. deletetopic (forumid, topicid );
}
Else if ("6". Equals (STRs [0]) // delete
{
Int forumid = integer. parseint (STRs [1]);
Int topicid = integer. parseint (STRs [2]);
Int replyid = integer. parseint (STRs [3]);
Forumfileoperator. deletereply (forumid, topicid, replyid );
}
}
}