1 2 29 30 package com.jcraft.jhttptunnel; 31 import java.io.*; 32 import java.net.*; 33 import java.util.*; 34 35 public class MySocket { 36 Socket socket=null; 37 private DataInputStream dataInputStream=null; 38 private OutputStream os=null; 39 40 MySocket(Socket s) throws IOException{ 41 42 try{ s.setTcpNoDelay(true); } 43 catch(Exception e){ 44 System.out.println(e+" tcpnodelay"); 45 } 46 socket=s; 47 BufferedInputStream bis=new BufferedInputStream(s.getInputStream()); 48 dataInputStream=new DataInputStream(bis); 49 os=s.getOutputStream(); 50 } 51 52 InputStream getInputStream(){ 53 try{ return dataInputStream;} 54 catch(Exception e){} 55 return null; 56 } 57 58 public void close(){ 59 try{ 60 socket.shutdownOutput(); 61 dataInputStream.close(); 62 os.close(); 63 socket.close(); 64 } 65 catch(IOException e){ } 66 } 67 public int read(byte[] buf, int s, int len){ 68 try{ return dataInputStream.read(buf, s, len); } 69 catch(IOException e){ return -1; } 70 } 71 public int readByte(){ 72 try{ int r=dataInputStream.readByte(); return(r&0xff); } 73 catch(IOException e){ return(-1); } 74 } 75 76 public String readLine(){ 77 try{ return(dataInputStream.readLine()); } 78 catch(IOException e){ return(null); } 79 } 80 81 public void write(byte[] foo, int start, int length) throws IOException{ 82 os.write(foo, start, length); 83 } 84 public void p(String s) throws IOException{ 85 os.write(s.getBytes()); 86 } 87 public void print(String s) throws IOException{ 88 os.write(s.getBytes()); 89 } 90 public void p(byte[] s) throws IOException{ 91 os.write(s); 92 } 93 public void print(byte[] s) throws IOException{ 94 os.write(s); 95 } 96 public void p(char c) throws IOException{ 97 os.write(c); 98 } 99 public void print(char c) throws IOException{ 100 os.write(c); 101 } 102 public void p(int c) throws IOException{ 103 os.write(Integer.toString(c).getBytes()); 104 } 105 public void print(int c) throws IOException{ 106 os.write(Integer.toString(c).getBytes()); 107 } 108 109 static final private byte[] _rn="\r\n".getBytes(); 110 public void pn(String s) throws IOException{ 111 println(s); 112 } 113 public void println(String s) throws IOException{ 114 print(s); print(_rn); 115 } 116 public void flush() throws IOException{ 117 os.flush(); 118 } 119 } 120 | Popular Tags |