⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 socketwrapper.java

📁 StandBayeMail
💻 JAVA
字号:
/** * <p>Title: StandBayeMail </p> * <p>Description: A bayesian spam filter</p> * <p>Copyright: Copyright (c) 2004 by Luca M. Viola</p> * <p>Company: 3AM.it</p> * @author Luca M. Viola <luca@3am.it> * @version 1.0  This program is free software; you can redistribute it and/or  modify it under the terms of the GNU General Public License  as published by the Free Software Foundation; either version 2  of the License, or (at your option) any later version.  This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License for more details.  You should have received a copy of the GNU General Public License  along with this program; if not, write to the Free Software  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */package pop3proxy;import java.io.*;import java.net.*;class SocketWrapper{    public static final int POP3_PORT = 110;    protected Socket         socket = null;    protected PrintWriter    output = null;    protected BufferedReader input  = null;    public SocketWrapper( Socket socket ) throws Exception    {        setSocket(socket);    }    public SocketWrapper( String host ) throws Exception    {        int port = SocketWrapper.POP3_PORT;        int colon = host.indexOf(':');        if ( colon != -1 )        {            port = Integer.parseInt(host.substring(colon + 1));            host = host.substring(0, colon);        }        setSocket(new Socket(host, port));    }    private void setSocket( Socket socket ) throws Exception    {        try        {            this.socket = socket;            output      = new PrintWriter(socket.getOutputStream());            input       = new BufferedReader(new InputStreamReader(socket.getInputStream()));        }        catch ( Exception e )        {            close();            throw e;        }    }    public void close()    {        try        {            if ( socket != null )            {                socket.close();            }        }        catch ( IOException e )        {        }        socket = null;        input  = null;        output = null;    }    public String read() throws IOException    {        if ( input == null )            return null;        return input.readLine();    }    public void write( String s )    {        write( s, false );    }    public void write( String s, boolean f )    {        if ( output != null )        {            output.write( s + "\r\n" );            if ( f )                output.flush();        }    }    public void flush()    {        if ( output != null )            output.flush();    }    public String writeread( String s ) throws IOException    {        write(s, true);        return read();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -