Home | History | Annotate | Download | only in proxyhandler
      1 package com.android.proxyhandler;
      2 
      3 import java.io.IOException;
      4 import java.io.InputStream;
      5 import java.io.OutputStream;
      6 import java.net.Socket;
      7 
      8 /**
      9  * @hide
     10  */
     11 public class SocketConnect extends Thread {
     12 
     13     private InputStream from;
     14     private OutputStream to;
     15 
     16     public SocketConnect(Socket from, Socket to) throws IOException {
     17         this.from = from.getInputStream();
     18         this.to = to.getOutputStream();
     19         start();
     20     }
     21 
     22     @Override
     23     public void run() {
     24         final byte[] buffer = new byte[512];
     25 
     26         try {
     27             while (true) {
     28                 int r = from.read(buffer);
     29                 if (r < 0) {
     30                     break;
     31                 }
     32                 to.write(buffer, 0, r);
     33             }
     34             from.close();
     35             to.close();
     36         } catch (IOException io) {
     37 
     38         }
     39     }
     40 
     41     public static void connect(Socket first, Socket second) {
     42         try {
     43             SocketConnect sc1 = new SocketConnect(first, second);
     44             SocketConnect sc2 = new SocketConnect(second, first);
     45             try {
     46                 sc1.join();
     47             } catch (InterruptedException e) {
     48             }
     49             try {
     50                 sc2.join();
     51             } catch (InterruptedException e) {
     52             }
     53         } catch (IOException e) {
     54             e.printStackTrace();
     55         }
     56     }
     57 
     58 
     59 }
     60