用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();     
    }
   }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.