用socket實現的檔案伺服器(2)
來源:互聯網
上載者:User
/**
* 商務邏輯層調用的介面
* @author HongSoft
*/
public class ForumFileDao
{
/**
* 得到主題貼內容
* 主題貼唯寫一行
* @param forumId
* @param topicId
* @return
*/
public static String getTopicContent(int forumId, int topicId)
{
String content = "";
ForumFileClient ffc = new ForumFileClient();
try
{
ffc.getOut().println("0" + "/0x1e" + forumId + "/0x1e" + topicId);
content = ffc.getIn().readLine();
}
catch (Exception e)
{
e.printStackTrace();
}
ffc.closeSocket();
return content;
}
/**
* 得到回帖列表
* @param forumId
* @param topicId
* @return
*/
public static List getReplyContent(int forumId, int topicId)
{
List replyList=new ArrayList();
String str="";
ForumFileClient ffc = new ForumFileClient();
try
{
ffc.getOut().println("1" + "/0x1e" + forumId + "/0x1e" + topicId);
while((str=ffc.getIn().readLine())!=null)
{
String[] strs=str.split("/0x1e");
ReplyRef rr=new ReplyRef();
rr.setUserId(strs[0]);
rr.setAddTime(strs[1]);
rr.setContent(strs[2]);
replyList.add(rr);
}
}
catch (Exception e)
{
e.printStackTrace();
}
ffc.closeSocket();
return replyList;
}
/**
* 發帖
* @param forumId
* @param topicId
* @return
*/
public static void addTopic(int forumId, int topicId,String content)
{
ForumFileClient ffc = new ForumFileClient();
try
{
ffc.getOut().println("2" + "/0x1e" + forumId + "/0x1e" + topicId+"/0x1e"+content);
}
catch (Exception e)
{
e.printStackTrace();
}
ffc.closeSocket();
}
/**
* 續貼(主題貼唯寫一行)
* @param forumId
* @param topicId
* @return
*/
public static void resumeTopic(int forumId, int topicId,String content)
{
ForumFileClient ffc = new ForumFileClient();
try
{
ffc.getOut().println("3" + "/0x1e" + forumId + "/0x1e" + topicId+"/0x1e"+content);
}
catch (Exception e)
{
e.printStackTrace();
}
ffc.closeSocket();
}
/**
* 回貼
* @param forumId
* @param topicId
* @return
*/
public static void addReply(int forumId, int topicId,String content,String qq,String replyTime)
{
ForumFileClient ffc = new ForumFileClient();
try
{
ffc.getOut().println("4" + "/0x1e" + forumId + "/0x1e" + topicId+"/0x1e"+content+"/0x1e"+qq+"/0x1e"+replyTime);
}
catch (Exception e)
{
e.printStackTrace();
}
ffc.closeSocket();
}
/**
* 刪主題貼(同時它的回貼也應該刪除)
* @param forumId
* @param topicId
* @return
*/
public static void deleteTopic(int forumId, int topicId)
{
ForumFileClient ffc = new ForumFileClient();
try
{
ffc.getOut().println("5" + "/0x1e" + forumId + "/0x1e" + topicId);
}
catch (Exception e)
{
e.printStackTrace();
}
ffc.closeSocket();
}
/**
* 刪某個回貼(但回貼數並不做改變)
* @param forumId
* @param topicId
* @return
*/
public static void deleteReply(int forumId, int topicId,int replyId)
{
ForumFileClient ffc = new ForumFileClient();
try
{
ffc.getOut().println("6" + "/0x1e" + forumId + "/0x1e" + topicId+"/0x1e"+replyId);
}
catch (Exception e)
{
e.printStackTrace();
}
ffc.closeSocket();
}
}