1 /*
2 * Copyright (c) 1994, 2002, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.net;
27
28 import java.lang.StringIndexOutOfBoundsException;
29 import java.io.*;
30 import java.util.Vector;
31 import sun.net.NetworkClient;
32
33 /**
34 * This class implements that basic intefaces of transfer protocols.
35 * It is used by subclasses implementing specific protocols.
36 *
37 * @author Jonathan Payne
38 * @see sun.net.ftp.FtpClient
39 * @see sun.net.nntp.NntpClient
40 */
41
42 public class TransferProtocolClient extends NetworkClient {
43 static final boolean debug = false;
44
45 /** Array of strings (usually 1 entry) for the last reply
46 from the server. */
47 protected Vector serverResponse = new Vector(1);
48
49 /** code for last reply */
50 protected int lastReplyCode;
51
52
53 /**
54 * Pulls the response from the server and returns the code as a
55 * number. Returns -1 on failure.
56 */
57 public int readServerResponse() throws IOException {
58 StringBuffer replyBuf = new StringBuffer(32);
59 int c;
60 int continuingCode = -1;
61 int code;
62 String response;
63
64 serverResponse.setSize(0);
65 while (true) {
66 while ((c = serverInput.read()) != -1) {
67 if (c == '\r') {
106 continuingCode = code;
107 continue;
108 } else {
109 break;
110 }
111 }
112
113 return lastReplyCode = code;
114 }
115
116 /** Sends command <i>cmd</i> to the server. */
117 public void sendServer(String cmd) {
118 serverOutput.print(cmd);
119 if (debug) {
120 System.out.print("Sending: " + cmd);
121 }
122 }
123
124 /** converts the server response into a string. */
125 public String getResponseString() {
126 return (String) serverResponse.elementAt(0);
127 }
128
129 /** Returns all server response strings. */
130 public Vector getResponseStrings() {
131 return serverResponse;
132 }
133
134 /** standard constructor to host <i>host</i>, port <i>port</i>. */
135 public TransferProtocolClient(String host, int port) throws IOException {
136 super(host, port);
137 }
138
139 /** creates an uninitialized instance of this class. */
140 public TransferProtocolClient() {}
141 }
|
1 /*
2 * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.net;
27
28 import java.io.*;
29 import java.util.Vector;
30
31 /**
32 * This class implements that basic intefaces of transfer protocols.
33 * It is used by subclasses implementing specific protocols.
34 *
35 * @author Jonathan Payne
36 * @see sun.net.ftp.FtpClient
37 * @see sun.net.nntp.NntpClient
38 */
39
40 public class TransferProtocolClient extends NetworkClient {
41 static final boolean debug = false;
42
43 /** Array of strings (usually 1 entry) for the last reply
44 from the server. */
45 protected Vector<String> serverResponse = new Vector<String>(1);
46
47 /** code for last reply */
48 protected int lastReplyCode;
49
50
51 /**
52 * Pulls the response from the server and returns the code as a
53 * number. Returns -1 on failure.
54 */
55 public int readServerResponse() throws IOException {
56 StringBuffer replyBuf = new StringBuffer(32);
57 int c;
58 int continuingCode = -1;
59 int code;
60 String response;
61
62 serverResponse.setSize(0);
63 while (true) {
64 while ((c = serverInput.read()) != -1) {
65 if (c == '\r') {
104 continuingCode = code;
105 continue;
106 } else {
107 break;
108 }
109 }
110
111 return lastReplyCode = code;
112 }
113
114 /** Sends command <i>cmd</i> to the server. */
115 public void sendServer(String cmd) {
116 serverOutput.print(cmd);
117 if (debug) {
118 System.out.print("Sending: " + cmd);
119 }
120 }
121
122 /** converts the server response into a string. */
123 public String getResponseString() {
124 return serverResponse.elementAt(0);
125 }
126
127 /** Returns all server response strings. */
128 public Vector<String> getResponseStrings() {
129 return serverResponse;
130 }
131
132 /** standard constructor to host <i>host</i>, port <i>port</i>. */
133 public TransferProtocolClient(String host, int port) throws IOException {
134 super(host, port);
135 }
136
137 /** creates an uninitialized instance of this class. */
138 public TransferProtocolClient() {}
139 }
|