1 47 48 package com.enterprisedt.net.ftp; 49 50 import java.io.IOException ; 51 import java.io.InputStream ; 52 import java.io.OutputStream ; 53 54 import java.net.Socket ; 55 import java.net.ServerSocket ; 56 57 58 66 67 public class FTPDataSocket { 68 69 72 private static String cvsId = "@(#)$Id: FTPDataSocket.java,v 1.1.1.1 2005/06/23 15:22:58 smontoro Exp $"; 73 74 77 private ServerSocket activeSocket = null; 78 79 82 private Socket passiveSocket = null; 83 84 87 FTPDataSocket(ServerSocket s) { 88 activeSocket = s; 89 } 90 91 94 FTPDataSocket(Socket s) { 95 passiveSocket = s; 96 } 97 98 99 108 void setTimeout(int millis) 109 throws IOException { 110 111 if (passiveSocket != null) 112 passiveSocket.setSoTimeout(millis); 113 else if (activeSocket != null) 114 activeSocket.setSoTimeout(millis); 115 } 116 117 118 125 OutputStream getOutputStream() throws IOException { 126 127 if (passiveSocket != null) { 128 return passiveSocket.getOutputStream(); 129 } 130 else { 131 passiveSocket = activeSocket.accept(); 133 return passiveSocket.getOutputStream (); 135 } 136 } 137 138 145 InputStream getInputStream() throws IOException { 146 147 if (passiveSocket != null) { 148 return passiveSocket.getInputStream(); 149 } else { 150 passiveSocket = activeSocket.accept(); 152 return passiveSocket.getInputStream (); 154 } 155 } 156 157 160 void close() throws IOException { 161 162 if (passiveSocket != null) 163 passiveSocket.close(); 164 if (activeSocket != null) 165 activeSocket.close(); 166 } 167 } 168 | Popular Tags |