/projs./apk/samsung-SGH-I727-Email/src/gnu/inet/ftp/FTPURLConnection.java

https://github.com/xl8or/- · Java · 317 lines · 281 code · 36 blank · 0 comment · 81 complexity · 2658d6158e4b4e71cf6ad806960916b3 MD5 · raw file

  1. package gnu.inet.ftp;
  2. import gnu.inet.ftp.FTPConnection;
  3. import gnu.inet.util.GetLocalHostAction;
  4. import gnu.inet.util.GetSystemPropertyAction;
  5. import java.io.FileNotFoundException;
  6. import java.io.FilterInputStream;
  7. import java.io.FilterOutputStream;
  8. import java.io.IOException;
  9. import java.io.InputStream;
  10. import java.io.OutputStream;
  11. import java.net.InetAddress;
  12. import java.net.URL;
  13. import java.net.URLConnection;
  14. import java.security.AccessController;
  15. import java.util.HashMap;
  16. import java.util.Map;
  17. public class FTPURLConnection extends URLConnection {
  18. protected FTPConnection connection;
  19. protected int fileStructure = -1;
  20. protected boolean passive = 1;
  21. protected int representationType = 3;
  22. protected int transferMode = -1;
  23. public FTPURLConnection(URL var1) {
  24. super(var1);
  25. }
  26. private void addRequestPropertyValue(Map var1, String var2) {
  27. String var3 = this.getRequestProperty(var2);
  28. var1.put(var2, var3);
  29. }
  30. public void addRequestProperty(String var1, String var2) {
  31. this.setRequestProperty(var1, var2);
  32. }
  33. public void connect() throws IOException {
  34. if(!this.connected) {
  35. String var1 = this.url.getHost();
  36. int var2 = this.url.getPort();
  37. String var3 = this.url.getUserInfo();
  38. Object var4 = null;
  39. String var10;
  40. String var11;
  41. if(var3 != null) {
  42. int var5 = var3.indexOf(58);
  43. if(var5 != -1) {
  44. int var6 = var5 + 1;
  45. String var7 = var3.substring(var6);
  46. String var8 = var3.substring(0, var5);
  47. var10 = var8;
  48. var11 = var7;
  49. } else {
  50. var10 = var3;
  51. var11 = (String)var4;
  52. }
  53. } else {
  54. String var26 = "anonymous";
  55. String var13 = (String)AccessController.doPrivileged(new GetSystemPropertyAction("user.name"));
  56. InetAddress var14 = (InetAddress)AccessController.doPrivileged(new GetLocalHostAction());
  57. StringBuilder var15 = (new StringBuilder()).append(var13).append("@");
  58. String var16;
  59. if(var14 == null) {
  60. var16 = "localhost";
  61. } else {
  62. var16 = var14.getHostName();
  63. }
  64. var11 = var15.append(var16).toString();
  65. var10 = var26;
  66. }
  67. FTPConnection var12 = new FTPConnection(var1, var2);
  68. this.connection = var12;
  69. if(!this.connection.authenticate(var10, var11)) {
  70. throw new SecurityException("Authentication failed");
  71. } else {
  72. FTPConnection var17 = this.connection;
  73. boolean var18 = this.passive;
  74. var17.setPassive(var18);
  75. if(this.representationType != -1) {
  76. FTPConnection var19 = this.connection;
  77. int var20 = this.representationType;
  78. var19.setRepresentationType(var20);
  79. }
  80. if(this.fileStructure != -1) {
  81. FTPConnection var21 = this.connection;
  82. int var22 = this.fileStructure;
  83. var21.setFileStructure(var22);
  84. }
  85. if(this.transferMode != -1) {
  86. FTPConnection var23 = this.connection;
  87. int var24 = this.transferMode;
  88. var23.setTransferMode(var24);
  89. }
  90. }
  91. }
  92. }
  93. public InputStream getInputStream() throws IOException {
  94. if(!this.connected) {
  95. this.connect();
  96. }
  97. String var1 = this.url.getPath();
  98. if(var1.startsWith("/")) {
  99. var1 = var1.substring(1);
  100. }
  101. int var2 = var1.lastIndexOf(47);
  102. String var6;
  103. if(var2 != -1) {
  104. int var3 = var2 + 1;
  105. String var4 = var1.substring(var3);
  106. String var5 = var1.substring(0, var2);
  107. if(!this.connection.changeWorkingDirectory(var5)) {
  108. throw new FileNotFoundException(var5);
  109. }
  110. var6 = var4;
  111. } else {
  112. var6 = null;
  113. }
  114. FTPURLConnection.ClosingInputStream var9;
  115. if(var6 != null && var6.length() > 0) {
  116. InputStream var7 = this.connection.retrieve(var6);
  117. var9 = new FTPURLConnection.ClosingInputStream(var7);
  118. } else {
  119. InputStream var8 = this.connection.list((String)null);
  120. var9 = new FTPURLConnection.ClosingInputStream(var8);
  121. }
  122. return var9;
  123. }
  124. public OutputStream getOutputStream() throws IOException {
  125. if(!this.connected) {
  126. this.connect();
  127. }
  128. String var1 = this.url.getPath();
  129. if(var1.startsWith("/")) {
  130. var1 = var1.substring(1);
  131. }
  132. String var2 = null;
  133. int var3 = var1.lastIndexOf(47);
  134. String var6;
  135. if(var3 != -1) {
  136. int var4 = var3 + 1;
  137. var2 = var1.substring(var4);
  138. String var5 = var1.substring(0, var3);
  139. if(!this.connection.changeWorkingDirectory(var5)) {
  140. throw new FileNotFoundException(var5);
  141. }
  142. var6 = var2;
  143. } else {
  144. var6 = var2;
  145. }
  146. if(var6 != null && var6.length() > 0) {
  147. OutputStream var7 = this.connection.store(var6);
  148. return new FTPURLConnection.ClosingOutputStream(var7);
  149. } else {
  150. throw new FileNotFoundException(var6);
  151. }
  152. }
  153. public Map getRequestProperties() {
  154. HashMap var1 = new HashMap();
  155. this.addRequestPropertyValue(var1, "passive");
  156. this.addRequestPropertyValue(var1, "representationType");
  157. this.addRequestPropertyValue(var1, "fileStructure");
  158. this.addRequestPropertyValue(var1, "transferMode");
  159. return var1;
  160. }
  161. public String getRequestProperty(String var1) {
  162. String var2;
  163. if("passive".equals(var1)) {
  164. var2 = Boolean.toString(this.passive);
  165. } else {
  166. if("representationType".equals(var1)) {
  167. switch(this.representationType) {
  168. case 1:
  169. var2 = "ASCII";
  170. return var2;
  171. case 2:
  172. var2 = "EBCDIC";
  173. return var2;
  174. case 3:
  175. var2 = "BINARY";
  176. return var2;
  177. }
  178. } else if("fileStructure".equals(var1)) {
  179. switch(this.fileStructure) {
  180. case 1:
  181. var2 = "FILE";
  182. return var2;
  183. case 2:
  184. var2 = "RECORD";
  185. return var2;
  186. case 3:
  187. var2 = "PAGE";
  188. return var2;
  189. }
  190. } else if("transferMode".equals(var1)) {
  191. switch(this.transferMode) {
  192. case 1:
  193. var2 = "STREAM";
  194. return var2;
  195. case 2:
  196. var2 = "BLOCK";
  197. return var2;
  198. case 3:
  199. var2 = "COMPRESSED";
  200. return var2;
  201. }
  202. }
  203. var2 = null;
  204. }
  205. return var2;
  206. }
  207. public void setDoInput(boolean var1) {
  208. this.doInput = var1;
  209. }
  210. public void setDoOutput(boolean var1) {
  211. this.doOutput = var1;
  212. }
  213. public void setRequestProperty(String var1, String var2) {
  214. if(this.connected) {
  215. throw new IllegalStateException();
  216. } else if("passive".equals(var1)) {
  217. boolean var3 = Boolean.valueOf(var2).booleanValue();
  218. this.passive = var3;
  219. } else if("representationType".equals(var1)) {
  220. if(!"A".equalsIgnoreCase(var2) && !"ASCII".equalsIgnoreCase(var2)) {
  221. if(!"E".equalsIgnoreCase(var2) && !"EBCDIC".equalsIgnoreCase(var2)) {
  222. if(!"I".equalsIgnoreCase(var2) && !"BINARY".equalsIgnoreCase(var2)) {
  223. throw new IllegalArgumentException(var2);
  224. } else {
  225. this.representationType = 3;
  226. }
  227. } else {
  228. this.representationType = 2;
  229. }
  230. } else {
  231. this.representationType = 1;
  232. }
  233. } else if("fileStructure".equals(var1)) {
  234. if(!"F".equalsIgnoreCase(var2) && !"FILE".equalsIgnoreCase(var2)) {
  235. if(!"R".equalsIgnoreCase(var2) && !"RECORD".equalsIgnoreCase(var2)) {
  236. if(!"P".equalsIgnoreCase(var2) && !"PAGE".equalsIgnoreCase(var2)) {
  237. throw new IllegalArgumentException(var2);
  238. } else {
  239. this.fileStructure = 3;
  240. }
  241. } else {
  242. this.fileStructure = 2;
  243. }
  244. } else {
  245. this.fileStructure = 1;
  246. }
  247. } else if("transferMode".equals(var1)) {
  248. if(!"S".equalsIgnoreCase(var2) && !"STREAM".equalsIgnoreCase(var2)) {
  249. if(!"B".equalsIgnoreCase(var2) && !"BLOCK".equalsIgnoreCase(var2)) {
  250. if(!"C".equalsIgnoreCase(var2) && !"COMPRESSED".equalsIgnoreCase(var2)) {
  251. throw new IllegalArgumentException(var2);
  252. } else {
  253. this.transferMode = 3;
  254. }
  255. } else {
  256. this.transferMode = 2;
  257. }
  258. } else {
  259. this.transferMode = 1;
  260. }
  261. }
  262. }
  263. class ClosingInputStream extends FilterInputStream {
  264. ClosingInputStream(InputStream var2) {
  265. super(var2);
  266. }
  267. public void close() throws IOException {
  268. super.close();
  269. FTPURLConnection.this.connection.logout();
  270. }
  271. }
  272. class ClosingOutputStream extends FilterOutputStream {
  273. ClosingOutputStream(OutputStream var2) {
  274. super(var2);
  275. }
  276. public void close() throws IOException {
  277. super.close();
  278. FTPURLConnection.this.connection.logout();
  279. }
  280. }
  281. }