1 2 29 30 package com.jcraft.jhttptunnel; 31 32 import java.io.*; 33 import javax.microedition.io.*; 34 35 public class InBoundConnector extends InBound{ 36 private InputStream in=null; 37 private HttpConnection con=null; 38 39 public void connect() throws IOException{ 40 close(); 41 String host=getHost(); 42 int port=getPort(); 43 con=(HttpConnection)Connector.open("http://"+host+":"+port+"/index.html?crap=1"); 44 con.setRequestMethod(HttpConnection.GET); 45 in=con.openInputStream(); 46 } 47 public int receiveData(byte[] buf, int s, int l) throws IOException{ 48 if(l<=0){ 50 return -1; 51 } 52 while(true){ 53 try{ 55 if(buf==null){ 56 if(l<=0) return -1; 57 long bar=in.skip((long)l); 58 l-=bar; 59 continue; 60 } 61 int i=in.read(buf, s, l); 62 if(i>0){ 63 return i; 64 } 65 connect(); 66 } 67 catch(IOException e){ 71 throw e; 73 } 75 } 76 } 77 public void close() throws IOException{ 78 if(con!=null){ 80 if(in!=null){ try{in.close();}catch(IOException e){} } 81 try{con.close();}catch(IOException e){} 82 con=null; 83 } 84 } 85 } 86 | Popular Tags |