Project

General

Profile

« Previous | Next » 

Revision 8297

Added by Matt Jones about 11 years ago

Closing FileOutputStream handles so that the OS limits on filehandles are not exceeded.

View differences:

src/edu/ucsb/nceas/metacat/DocumentImpl.java
1064 1064
			throws McdbException {
1065 1065
		String documentDir = null;
1066 1066
		String documentPath = null;
1067
		FileOutputStream fos = null;
1067 1068
		try {
1068 1069
			String separator = PropertyService.getProperty("document.accNumSeparator");
1069 1070
			documentDir = PropertyService.getProperty("application.documentfilepath");
......
1071 1072

  
1072 1073
			if (FileUtil.getFileStatus(documentPath) == FileUtil.DOES_NOT_EXIST
1073 1074
					|| FileUtil.getFileSize(documentPath) == 0) {
1074
				FileOutputStream fos = new FileOutputStream(documentPath);
1075
				fos = new FileOutputStream(documentPath);
1075 1076
				toXmlFromDb(fos, user, groups, true);
1077
				fos.close();
1078
				fos = null;
1076 1079
			}
1077 1080
		} catch (PropertyNotFoundException pnfe) {
1078 1081
			throw new McdbException("Could not write file: " + documentPath + " : "
......
1080 1083
		} catch (IOException ioe) {
1081 1084
			throw new McdbException("Could not write file: " + documentPath + " : "
1082 1085
					+ ioe.getMessage());
1083
		}
1086
        } finally {
1087
            if (fos != null) {
1088
                try {
1089
                    fos.close();
1090
                } catch (IOException ioe) {
1091
                    // Do nothing
1092
                }
1093
            }
1094
        }
1084 1095
		
1085 1096
		if (FileUtil.getFileSize(documentPath) == 0) {
1086 1097
			throw new McdbException("Attempting to read a zero length document from disk: " + documentPath);
src/edu/ucsb/nceas/metacat/replication/ReplicationService.java
1276 1276
		String urlString = null;
1277 1277
		String documentPath = null;
1278 1278
		String errorMsg = null;
1279
		FileOutputStream fos = null;
1279 1280
		try {
1280 1281
			// try to open a https stream to test if the request server's public
1281 1282
			// key
......
1307 1308
			// it to disk.
1308 1309
			if (FileUtil.getFileStatus(documentPath) == FileUtil.DOES_NOT_EXIST
1309 1310
					|| FileUtil.getFileSize(documentPath) == 0) {
1310
				FileOutputStream fos = new FileOutputStream(documentPath);
1311
				fos = new FileOutputStream(documentPath);
1311 1312
				di.toXml(fos, null, null, true);
1313
				fos.close();
1314
				fos = null;
1312 1315
			}
1313 1316

  
1314 1317
			// read the file from disk and send it to outputstream
......
1352 1355
							+ me.getMessage());
1353 1356
			// e.printStackTrace(System.out);
1354 1357
			errorMsg = me.getMessage();
1358
		} finally {
1359
            if (fos != null) {
1360
                try {
1361
                    fos.close();
1362
                } catch (IOException ioe) {
1363
                    // Do nothing
1364
                }
1365
            }
1355 1366
		}
1356 1367
		
1357 1368
		// report any errors if we got here

Also available in: Unified diff