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

📄 chainio.java

📁 在J2ME中实现虚拟代理
💻 JAVA
字号:
package mobilevirproxy;
import java.io.*;
import javax.microedition.io.*;
import com.sun.midp.io.j2me.socket.*;
/**
 * <p>Title: Publish from SRTServer</p>
 * <p>Description: Java</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: Sigma-datas</p>
 * $author$ luweigan
 * $version$ 1.0
 */

public class ChainIO extends Thread {
  StreamConnection sc;
  public ChainIO(StreamConnection sc) {
    this.sc=sc;
  }
  public void run(){

    int nbyte=0;
    try {
      InputStream in = sc.openInputStream();
      Protocol protocol = new Protocol();
      protocol.connect("192.168.0.37", 8080, true);
      OutputStream out = protocol.openOutputStream();
      out = sc.openOutputStream();
      String readLine=null;
      while(true)
      {
        readLine=readLine(in);
        if(readLine.length()<1)break;
        if(readLine.toLowerCase().startsWith("user-agent"))
        {
          readLine="user-agent: SIE-SX1/1.1 SymbianOS/6.1 Series60/1.2 Profile/MIDP-1.0 Configuration/CLDC-1.0";
        }
        readLine+="\r\n";
        out.write(readLine.getBytes());
        out.flush();
      }
      while ( (nbyte = in.read()) != -1) {
        out.write(nbyte);
      }
      //out.close();
      in=protocol.openInputStream();
      out=sc.openOutputStream();
      while ( (nbyte = in.read()) != -1) {
        out.write(nbyte);
      }
      out.close();
    }
    catch (IOException ex) {
      ex.printStackTrace();
    }
  }
  public String readLine(InputStream in) throws java.io.IOException {
     byte[] bytes=new byte[1024];
     int index=0;
     int nbyte=0;
     boolean hasRead13=false;
     while((nbyte=in.read())>-1)
     {
       hasRead13=nbyte==13;
       if(index>=bytes.length)
       {
          byte[] tempByte=new byte[bytes.length+1024];
          System.arraycopy(bytes,0,tempByte,0,bytes.length);
          bytes=tempByte;
       }
       if(hasRead13)
       {
         if( (nbyte=in.read())==10)
           break;
         else
         {
             bytes[index++] = 13;
           if (nbyte < 0) {
             break;
           }
         }
       }
      bytes[index++]=(byte)nbyte;
     }
     return new String(bytes,0,index);
  }

}

⌨️ 快捷键说明

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