Revision 658
Added by berkley over 23 years ago
src/edu/ucsb/nceas/metacat/DataStreamTest.java | ||
---|---|---|
47 | 47 |
filename + " cookie: " + cookie); |
48 | 48 |
try |
49 | 49 |
{ |
50 |
echoSocket = DataFileServer.getSocket(host, port); |
|
50 |
echoSocket = DataFileServer.getSocket(host, port); //get the socket
|
|
51 | 51 |
while(echoSocket == null) |
52 | 52 |
{//loop until the port is there |
53 | 53 |
echoSocket = DataFileServer.getSocket(host, port); |
... | ... | |
67 | 67 |
catch (IOException e) |
68 | 68 |
{ |
69 | 69 |
System.err.println("Couldn't get I/O for " |
70 |
+ "the connection to: "+host);
|
|
70 |
+ "the connection to: " + host);
|
|
71 | 71 |
System.out.println("error: " + e.getMessage()); |
72 | 72 |
e.printStackTrace(System.out); |
73 | 73 |
System.exit(1); |
... | ... | |
75 | 75 |
|
76 | 76 |
try |
77 | 77 |
{ |
78 |
File file = new File(filename); |
|
79 |
dsout = new DataOutputStream(out); |
|
78 |
File file = new File(filename); //get the file from the local system
|
|
79 |
dsout = new DataOutputStream(out);
|
|
80 | 80 |
FileInputStream fs = new FileInputStream(file); |
81 | 81 |
// first convert the filename to a byte array |
82 | 82 |
String fn = file.getName(); |
... | ... | |
94 | 94 |
{ |
95 | 95 |
dsout.write(cook[i]); |
96 | 96 |
} |
97 |
dsout.write(0); |
|
97 |
dsout.write(0); //follow it with a 0
|
|
98 | 98 |
|
99 | 99 |
//write the length of the file followed by a 0 |
100 | 100 |
long flength = file.length(); |
101 | 101 |
System.out.println("file sized (B): " + flength); |
102 |
String sflength = String.valueOf(flength); |
|
102 |
String sflength = String.valueOf(flength); //note that this is changed |
|
103 |
//to a string |
|
103 | 104 |
|
104 | 105 |
byte[] fl = sflength.getBytes(); |
105 | 106 |
for(int i=0; i<fl.length; i++) |
106 | 107 |
{ |
107 | 108 |
dsout.write(fl[i]); |
108 | 109 |
} |
109 |
dsout.write(0); |
|
110 |
dsout.write(0); //following 0
|
|
110 | 111 |
|
111 | 112 |
//dsout.write((int)flength); |
112 | 113 |
//dsout.write(0); |
113 | 114 |
dsout.flush(); |
114 | 115 |
|
115 |
// now read response from server |
|
116 |
//InputStreamReader isr = new InputStreamReader(in); |
|
117 | 116 |
BufferedReader rin = new BufferedReader(isr); |
118 | 117 |
|
119 | 118 |
// now send the file data |
... | ... | |
122 | 121 |
int i = 0; |
123 | 122 |
while (cnt!=-1) |
124 | 123 |
{ |
125 |
cnt = fs.read(buf); |
|
124 |
cnt = fs.read(buf); //read the file
|
|
126 | 125 |
System.out.println("i = "+ i +" Bytes read = " + cnt); |
127 | 126 |
if (cnt!=-1) |
128 | 127 |
{ |
129 |
dsout.write(buf, 0, cnt); |
|
128 |
dsout.write(buf, 0, cnt); //write the byte to the server
|
|
130 | 129 |
} |
131 | 130 |
i++; |
132 | 131 |
} |
133 | 132 |
fs.close(); |
134 | 133 |
dsout.flush(); |
135 |
//dsout.close(); |
|
136 | 134 |
} |
137 | 135 |
catch (Exception w) |
138 | 136 |
{ |
... | ... | |
140 | 138 |
} |
141 | 139 |
|
142 | 140 |
try |
143 |
{ |
|
141 |
{ //get the server's response
|
|
144 | 142 |
while(!isr.ready()) |
145 | 143 |
{ |
146 | 144 |
//System.out.println("not ready"); |
... | ... | |
152 | 150 |
{ |
153 | 151 |
System.out.print((char)msg); |
154 | 152 |
System.out.flush(); |
155 |
msg = isr.read(); |
|
153 |
msg = isr.read(); //get the message a character at a time
|
|
156 | 154 |
retmsg += (char)msg; |
157 | 155 |
} |
158 | 156 |
System.out.println(); |
Also available in: Unified diff
added more documentation