---
title: "用socket实现的文件服务器(2)"
author: "hongsoft"
date: "2005-09-28T20:34:00Z"
tags: []
slug: "socket-2"
draft: false
lastmod: "2005-09-28T20:34:00Z"
id: 287450
url: "https://hongsoft.iteye.com/blog/287450"
---

/\**  
 * 业务逻辑层调用的接口  
 * @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();       
    }  
   }