Revision 650
Added by berkley about 24 years ago
src/edu/ucsb/nceas/metacat/DataFileServer.java | ||
---|---|---|
164 | 164 |
File outfile = new File(filedir + filename); |
165 | 165 |
//System.out.println("outfile: " + filedir + filename); |
166 | 166 |
boolean nameInUse = outfile.exists(); |
167 |
if(!nameInUse) |
|
167 |
int filenametemp = 1; |
|
168 |
while(nameInUse) |
|
168 | 169 |
{ |
169 |
try |
|
170 |
filename += filenametemp; |
|
171 |
outfile = new File (filedir + filename); |
|
172 |
nameInUse = outfile.exists(); |
|
173 |
filenametemp++; |
|
174 |
} |
|
175 |
|
|
176 |
try |
|
177 |
{ |
|
178 |
AccessionNumber anum = new AccessionNumber(); |
|
179 |
String accnum = anum.generate(null, "INSERT"); |
|
180 |
//osw.write(restext,0,restext.length()); |
|
181 |
//osw.flush(); |
|
182 |
FileOutputStream out = new FileOutputStream(outfile); |
|
183 |
byte[] buf = new byte[1024]; |
|
184 |
int cnt = 0; |
|
185 |
while (cnt!=-1) |
|
170 | 186 |
{ |
171 |
AccessionNumber anum = new AccessionNumber(); |
|
172 |
String accnum = anum.generate(null, "INSERT"); |
|
173 |
//osw.write(restext,0,restext.length()); |
|
174 |
//osw.flush(); |
|
175 |
FileOutputStream out = new FileOutputStream(outfile); |
|
176 |
byte[] buf = new byte[1024]; |
|
177 |
int cnt = 0; |
|
178 |
while (cnt!=-1) |
|
187 |
cnt = in.read(buf, 0, 1024); |
|
188 |
if (cnt!=-1) |
|
179 | 189 |
{ |
180 |
cnt = in.read(buf, 0, 1024); |
|
181 |
if (cnt!=-1) |
|
182 |
{ |
|
183 |
out.write(buf, 0, cnt); |
|
184 |
} |
|
190 |
out.write(buf, 0, cnt); |
|
185 | 191 |
} |
186 |
out.flush(); |
|
187 |
out.close(); |
|
188 |
//put the new document info into the DB |
|
189 |
updateDB(accnum, filename, user); |
|
190 | 192 |
} |
191 |
catch(Exception e) |
|
192 |
{ |
|
193 |
System.out.println("error in DataFileServer.run(): " + e.getMessage()); |
|
194 |
e.printStackTrace(System.out); |
|
195 |
} |
|
193 |
out.flush(); |
|
194 |
out.close(); |
|
195 |
//put the new document info into the DB |
|
196 |
updateDB(accnum, filename, user); |
|
196 | 197 |
} |
197 |
else
|
|
198 |
{//error the file name is already in use on the server
|
|
199 |
//send an error message here!
|
|
200 |
System.out.println("error: name in use.");
|
|
198 |
catch(Exception e)
|
|
199 |
{ |
|
200 |
System.out.println("error in DataFileServer.run(): " + e.getMessage());
|
|
201 |
e.printStackTrace(System.out);
|
|
201 | 202 |
} |
202 | 203 |
} |
203 | 204 |
catch (IOException ex) |
Also available in: Unified diff
multiple files with the same names no longer overwrite each other.