Revision 8299
Added by Matt Jones about 11 years ago
src/edu/ucsb/nceas/metacat/DocumentImpl.java | ||
---|---|---|
1075 | 1075 |
fos = new FileOutputStream(documentPath); |
1076 | 1076 |
toXmlFromDb(fos, user, groups, true); |
1077 | 1077 |
fos.close(); |
1078 |
fos = null; |
|
1079 | 1078 |
} |
1080 | 1079 |
} catch (PropertyNotFoundException pnfe) { |
1081 | 1080 |
throw new McdbException("Could not write file: " + documentPath + " : " |
... | ... | |
1084 | 1083 |
throw new McdbException("Could not write file: " + documentPath + " : " |
1085 | 1084 |
+ ioe.getMessage()); |
1086 | 1085 |
} finally { |
1087 |
if (fos != null) { |
|
1088 |
try { |
|
1089 |
fos.close(); |
|
1090 |
} catch (IOException ioe) { |
|
1091 |
// Do nothing |
|
1092 |
} |
|
1093 |
} |
|
1086 |
IOUtils.closeQuietly(fos); |
|
1094 | 1087 |
} |
1095 | 1088 |
|
1096 | 1089 |
if (FileUtil.getFileSize(documentPath) == 0) { |
... | ... | |
1534 | 1527 |
|
1535 | 1528 |
fos.flush(); |
1536 | 1529 |
fos.close(); |
1537 |
fos = null; |
|
1538 | 1530 |
} catch (IOException ioe) { |
1539 | 1531 |
throw new McdbException("Could not write file: " + documentPath + " : " + ioe.getMessage()); |
1540 | 1532 |
} finally { |
1541 |
if (fos != null) { |
|
1542 |
try { |
|
1543 |
fos.close(); |
|
1544 |
} catch (IOException ioe) { |
|
1545 |
// Do nothing |
|
1546 |
} |
|
1547 |
} |
|
1533 |
IOUtils.closeQuietly(fos); |
|
1548 | 1534 |
} |
1549 | 1535 |
} |
1550 | 1536 |
|
src/edu/ucsb/nceas/metacat/replication/ReplicationService.java | ||
---|---|---|
55 | 55 |
import javax.servlet.http.HttpServletRequest; |
56 | 56 |
import javax.servlet.http.HttpServletResponse; |
57 | 57 |
|
58 |
import org.apache.commons.io.IOUtils; |
|
58 | 59 |
import org.apache.http.HttpResponse; |
59 | 60 |
import org.apache.http.conn.scheme.Scheme; |
60 | 61 |
import org.apache.http.conn.ssl.SSLSocketFactory; |
... | ... | |
1311 | 1312 |
fos = new FileOutputStream(documentPath); |
1312 | 1313 |
di.toXml(fos, null, null, true); |
1313 | 1314 |
fos.close(); |
1314 |
fos = null; |
|
1315 | 1315 |
} |
1316 | 1316 |
|
1317 | 1317 |
// read the file from disk and send it to outputstream |
... | ... | |
1356 | 1356 |
// e.printStackTrace(System.out); |
1357 | 1357 |
errorMsg = me.getMessage(); |
1358 | 1358 |
} finally { |
1359 |
if (fos != null) { |
|
1360 |
try { |
|
1361 |
fos.close(); |
|
1362 |
} catch (IOException ioe) { |
|
1363 |
// Do nothing |
|
1364 |
} |
|
1365 |
} |
|
1359 |
IOUtils.closeQuietly(fos); |
|
1366 | 1360 |
} |
1367 | 1361 |
|
1368 | 1362 |
// report any errors if we got here |
Also available in: Unified diff
Refactor to use IOUtils.closeQuietly() which handles nulls and streams that are already closed.