Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 332543 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/core/internal/localstore/Bucket.java (-1 / +4 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.core.internal.localstore;
11
package org.eclipse.core.internal.localstore;
12
12
13
import org.eclipse.core.internal.utils.FileUtil;
14
13
import java.io.*;
15
import java.io.*;
14
import java.util.*;
16
import java.util.*;
15
import org.eclipse.core.internal.resources.ResourceException;
17
import org.eclipse.core.internal.resources.ResourceException;
Lines 350-357 Link Here
350
					writeEntryKey(destination, entry.getKey());
352
					writeEntryKey(destination, entry.getKey());
351
					writeEntryValue(destination, entry.getValue());
353
					writeEntryValue(destination, entry.getValue());
352
				}
354
				}
353
			} finally {
354
				destination.close();
355
				destination.close();
356
			} finally {
357
				FileUtil.safeClose(destination);
355
			}
358
			}
356
			needSaving = false;
359
			needSaving = false;
357
		} catch (IOException ioe) {
360
		} catch (IOException ioe) {
(-)src/org/eclipse/core/internal/localstore/BucketTree.java (-11 / +4 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.core.internal.localstore;
11
package org.eclipse.core.internal.localstore;
12
12
13
import org.eclipse.core.internal.utils.FileUtil;
14
13
import java.io.*;
15
import java.io.*;
14
import org.eclipse.core.internal.localstore.Bucket.Visitor;
16
import org.eclipse.core.internal.localstore.Bucket.Visitor;
15
import org.eclipse.core.internal.resources.ResourceException;
17
import org.eclipse.core.internal.resources.ResourceException;
Lines 139-162 Link Here
139
		if (!versionFile.getParentFile().exists())
141
		if (!versionFile.getParentFile().exists())
140
			versionFile.getParentFile().mkdirs();
142
			versionFile.getParentFile().mkdirs();
141
		FileOutputStream stream = null;
143
		FileOutputStream stream = null;
142
		boolean failed = false;
143
		try {
144
		try {
144
			stream = new FileOutputStream(versionFile);
145
			stream = new FileOutputStream(versionFile);
145
			stream.write(current.getVersion());
146
			stream.write(current.getVersion());
147
			stream.close();
146
		} catch (IOException e) {
148
		} catch (IOException e) {
147
			failed = true;
148
			String message = NLS.bind(Messages.resources_writeWorkspaceMeta, versionFile.getAbsolutePath()); 
149
			String message = NLS.bind(Messages.resources_writeWorkspaceMeta, versionFile.getAbsolutePath()); 
149
			throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, null, message, e);
150
			throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, null, message, e);
150
		} finally {
151
		} finally {
151
			try {
152
			FileUtil.safeClose(stream);
152
				if (stream != null)
153
					stream.close();
154
			} catch (IOException e) {
155
				if (!failed) {
156
					String message = NLS.bind(Messages.resources_writeWorkspaceMeta, versionFile.getAbsolutePath());
157
					throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, null, message, e);
158
				}
159
			}
160
		}
153
		}
161
	}
154
	}
162
155
(-)src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java (-7 / +2 lines)
Lines 1091-1107 Link Here
1091
		try {
1091
		try {
1092
			out = fileStore.openOutputStream(EFS.NONE, null);
1092
			out = fileStore.openOutputStream(EFS.NONE, null);
1093
			new ModelObjectWriter().write(desc, out);
1093
			new ModelObjectWriter().write(desc, out);
1094
			out.close();
1094
		} catch (IOException e) {
1095
		} catch (IOException e) {
1095
			String msg = NLS.bind(Messages.resources_writeMeta, target.getFullPath());
1096
			String msg = NLS.bind(Messages.resources_writeMeta, target.getFullPath());
1096
			throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, target.getFullPath(), msg, e);
1097
			throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, target.getFullPath(), msg, e);
1097
		} finally {
1098
		} finally {
1098
			if (out != null) {
1099
			FileUtil.safeClose(out);
1099
				try {
1100
					out.close();
1101
				} catch (IOException e) {
1102
					// ignore failure to close stream
1103
				}
1104
			}
1105
		}
1100
		}
1106
		//for backwards compatibility, ensure the old .prj file is deleted
1101
		//for backwards compatibility, ensure the old .prj file is deleted
1107
		getWorkspace().getMetaArea().clearOldDescription(target);
1102
		getWorkspace().getMetaArea().clearOldDescription(target);
(-)src/org/eclipse/core/internal/localstore/SafeChunkyOutputStream.java (-1 / +4 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.core.internal.localstore;
11
package org.eclipse.core.internal.localstore;
12
12
13
import org.eclipse.core.internal.utils.FileUtil;
14
13
import java.io.*;
15
import java.io.*;
14
16
15
/**
17
/**
Lines 63-71 Link Here
63
	public void succeed() throws IOException {
65
	public void succeed() throws IOException {
64
		try {
66
		try {
65
			endChunk();
67
			endChunk();
68
			close();
66
		} finally {
69
		} finally {
67
			isOpen = false;
70
			isOpen = false;
68
			close();
71
			FileUtil.safeClose(this);
69
		}
72
		}
70
	}
73
	}
71
74
(-)src/org/eclipse/core/internal/localstore/SafeFileOutputStream.java (+1 lines)
Lines 86-91 Link Here
86
			source = new BufferedInputStream(new FileInputStream(sourceFile));
86
			source = new BufferedInputStream(new FileInputStream(sourceFile));
87
			destination = new BufferedOutputStream(new FileOutputStream(destinationFile));
87
			destination = new BufferedOutputStream(new FileOutputStream(destinationFile));
88
			transferStreams(source, destination);
88
			transferStreams(source, destination);
89
			destination.close();
89
		} finally {
90
		} finally {
90
			FileUtil.safeClose(source);
91
			FileUtil.safeClose(source);
91
			FileUtil.safeClose(destination);
92
			FileUtil.safeClose(destination);
(-)src/org/eclipse/core/internal/resources/FileState.java (-10 / +4 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.core.internal.resources;
11
package org.eclipse.core.internal.resources;
12
12
13
import org.eclipse.core.internal.utils.FileUtil;
14
13
import java.io.*;
15
import java.io.*;
14
import org.eclipse.core.internal.localstore.IHistoryStore;
16
import org.eclipse.core.internal.localstore.IHistoryStore;
15
import org.eclipse.core.internal.utils.Messages;
17
import org.eclipse.core.internal.utils.Messages;
Lines 53-75 Link Here
53
		// tries to obtain a description for the file contents
55
		// tries to obtain a description for the file contents
54
		IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
56
		IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
55
		InputStream contents = new BufferedInputStream(getContents());
57
		InputStream contents = new BufferedInputStream(getContents());
56
		boolean failed = false;
57
		try {
58
		try {
58
			IContentDescription description = contentTypeManager.getDescriptionFor(contents, getName(), new QualifiedName[] {IContentDescription.CHARSET});
59
			IContentDescription description = contentTypeManager.getDescriptionFor(contents, getName(), new QualifiedName[] {IContentDescription.CHARSET});
60
			contents.close();
59
			return description == null ? null : description.getCharset();
61
			return description == null ? null : description.getCharset();
60
		} catch (IOException e) {
62
		} catch (IOException e) {
61
			failed = true;
62
			String message = NLS.bind(Messages.history_errorContentDescription, getFullPath());		
63
			String message = NLS.bind(Messages.history_errorContentDescription, getFullPath());		
63
			throw new ResourceException(IResourceStatus.FAILED_DESCRIBING_CONTENTS, getFullPath(), message, e);
64
			throw new ResourceException(IResourceStatus.FAILED_DESCRIBING_CONTENTS, getFullPath(), message, e);
64
		} finally {
65
		} finally {
65
			try {
66
			FileUtil.safeClose(contents);
66
				contents.close();
67
			} catch (IOException e) {
68
				if (!failed) {
69
					String message = NLS.bind(Messages.history_errorContentDescription, getFullPath());		
70
					throw new ResourceException(IResourceStatus.FAILED_DESCRIBING_CONTENTS, getFullPath(), message, e);
71
				}
72
			}
73
		}
67
		}
74
	}
68
	}
75
69
(-)src/org/eclipse/core/internal/resources/LocalMetaArea.java (-1 / +4 lines)
Lines 12-17 Link Here
12
 *******************************************************************************/
12
 *******************************************************************************/
13
package org.eclipse.core.internal.resources;
13
package org.eclipse.core.internal.resources;
14
14
15
import org.eclipse.core.internal.utils.FileUtil;
16
15
import java.io.*;
17
import java.io.*;
16
import java.net.URI;
18
import java.net.URI;
17
import java.util.HashMap;
19
import java.util.HashMap;
Lines 480-487 Link Here
480
					}
482
					}
481
				}
483
				}
482
				output.succeed();
484
				output.succeed();
483
			} finally {
484
				dataOut.close();
485
				dataOut.close();
486
			} finally {
487
				FileUtil.safeClose(dataOut);
485
			}
488
			}
486
		} catch (IOException e) {
489
		} catch (IOException e) {
487
			String message = NLS.bind(Messages.resources_exSaveProjectLocation, target.getName());
490
			String message = NLS.bind(Messages.resources_exSaveProjectLocation, target.getName());
(-)src/org/eclipse/core/internal/resources/ModelObjectWriter.java (-3 / +5 lines)
Lines 155-163 Link Here
155
		try {
155
		try {
156
			file = new SafeFileOutputStream(location.toOSString(), tempPath);
156
			file = new SafeFileOutputStream(location.toOSString(), tempPath);
157
			write(object, file);
157
			write(object, file);
158
			file.close();
158
		} finally {
159
		} finally {
159
			if (file != null)
160
			FileUtil.safeClose(file);
160
				file.close();
161
		}
161
		}
162
	}
162
	}
163
163
Lines 170-177 Link Here
170
			write(object, writer);
170
			write(object, writer);
171
			writer.flush();
171
			writer.flush();
172
			writer.close();
172
			writer.close();
173
			if (writer.checkError())
174
				throw new IOException();
173
		} finally {
175
		} finally {
174
			output.close();
176
			FileUtil.safeClose(output);
175
		}
177
		}
176
	}
178
	}
177
179
(-)src/org/eclipse/core/internal/resources/ProjectDescriptionReader.java (-2 / +3 lines)
Lines 12-17 Link Here
12
 *******************************************************************************/
12
 *******************************************************************************/
13
package org.eclipse.core.internal.resources;
13
package org.eclipse.core.internal.resources;
14
14
15
import org.eclipse.core.internal.utils.FileUtil;
16
15
import java.io.*;
17
import java.io.*;
16
import java.net.URI;
18
import java.net.URI;
17
import java.net.URISyntaxException;
19
import java.net.URISyntaxException;
Lines 946-953 Link Here
946
			file = new BufferedInputStream(new FileInputStream(location.toFile()));
948
			file = new BufferedInputStream(new FileInputStream(location.toFile()));
947
			return read(new InputSource(file));
949
			return read(new InputSource(file));
948
		} finally {
950
		} finally {
949
			if (file != null)
951
			FileUtil.safeClose(file);
950
				file.close();
951
		}
952
		}
952
	}
953
	}
953
954
(-)src/org/eclipse/core/internal/resources/ProjectPreferences.java (-5 / +2 lines)
Lines 594-609 Link Here
594
			ByteArrayOutputStream output = new ByteArrayOutputStream();
594
			ByteArrayOutputStream output = new ByteArrayOutputStream();
595
			try {
595
			try {
596
				table.store(output, null);
596
				table.store(output, null);
597
				output.close();
597
			} catch (IOException e) {
598
			} catch (IOException e) {
598
				String message = NLS.bind(Messages.preferences_saveProblems, absolutePath());
599
				String message = NLS.bind(Messages.preferences_saveProblems, absolutePath());
599
				log(new Status(IStatus.ERROR, Platform.PI_RUNTIME, IStatus.ERROR, message, e));
600
				log(new Status(IStatus.ERROR, Platform.PI_RUNTIME, IStatus.ERROR, message, e));
600
				throw new BackingStoreException(message);
601
				throw new BackingStoreException(message);
601
			} finally {
602
			} finally {
602
				try {
603
				FileUtil.safeClose(output);
603
					output.close();
604
				} catch (IOException e) {
605
					// ignore
606
				}
607
			}
604
			}
608
			final InputStream input = new BufferedInputStream(new ByteArrayInputStream(output.toByteArray()));
605
			final InputStream input = new BufferedInputStream(new ByteArrayInputStream(output.toByteArray()));
609
			IWorkspaceRunnable operation = new IWorkspaceRunnable() {
606
			IWorkspaceRunnable operation = new IWorkspaceRunnable() {
(-)src/org/eclipse/core/internal/resources/SafeFileTable.java (-1 / +4 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.core.internal.resources;
11
package org.eclipse.core.internal.resources;
12
12
13
import org.eclipse.core.internal.utils.FileUtil;
14
13
import java.io.*;
15
import java.io.*;
14
import java.util.Properties;
16
import java.util.Properties;
15
import java.util.Set;
17
import java.util.Set;
Lines 80-87 Link Here
80
			FileOutputStream output = new FileOutputStream(target);
82
			FileOutputStream output = new FileOutputStream(target);
81
			try {
83
			try {
82
				table.store(output, "safe table"); //$NON-NLS-1$
84
				table.store(output, "safe table"); //$NON-NLS-1$
83
			} finally {
84
				output.close();
85
				output.close();
86
			} finally {
87
				FileUtil.safeClose(output);
85
			}
88
			}
86
		} catch (IOException e) {
89
		} catch (IOException e) {
87
			String message = Messages.resources_exSafeSave;
90
			String message = Messages.resources_exSafeSave;
(-)src/org/eclipse/core/internal/resources/SaveManager.java (-18 / +22 lines)
Lines 1201-1208 Link Here
1201
			try {
1201
			try {
1202
				masterTable.store(output, "master table"); //$NON-NLS-1$
1202
				masterTable.store(output, "master table"); //$NON-NLS-1$
1203
				output.succeed();
1203
				output.succeed();
1204
			} finally {
1205
				output.close();
1204
				output.close();
1205
			} finally {
1206
				FileUtil.safeClose(output);
1206
			}
1207
			}
1207
		} catch (IOException e) {
1208
		} catch (IOException e) {
1208
			throw new ResourceException(IResourceStatus.INTERNAL_ERROR, null, NLS.bind(Messages.resources_exSaveMaster, location.toOSString()), e);
1209
			throw new ResourceException(IResourceStatus.INTERNAL_ERROR, null, NLS.bind(Messages.resources_exSaveMaster, location.toOSString()), e);
Lines 1278-1285 Link Here
1278
			try {
1279
			try {
1279
				output.writeInt(ICoreConstants.WORKSPACE_TREE_VERSION_2);
1280
				output.writeInt(ICoreConstants.WORKSPACE_TREE_VERSION_2);
1280
				writeTree(project, output, monitor);
1281
				writeTree(project, output, monitor);
1281
			} finally {
1282
				output.close();
1282
				output.close();
1283
			} finally {
1284
				FileUtil.safeClose(output);
1283
			}
1285
			}
1284
			OutputStream snapOut = store.openOutputStream(EFS.NONE, monitor);
1286
			OutputStream snapOut = store.openOutputStream(EFS.NONE, monitor);
1285
			out = new ZipOutputStream(snapOut);
1287
			out = new ZipOutputStream(snapOut);
Lines 1295-1308 Link Here
1295
				}
1297
				}
1296
				out.closeEntry();
1298
				out.closeEntry();
1297
			} finally {
1299
			} finally {
1298
				in.close();
1300
				FileUtil.safeClose(in);
1299
			}
1301
			}
1302
			out.close();
1300
		} catch (IOException e) {
1303
		} catch (IOException e) {
1301
			throw new ResourceException(IResourceStatus.FAILED_WRITE_LOCAL, snapshotPath, Messages.resources_copyProblem, e);
1304
			throw new ResourceException(IResourceStatus.FAILED_WRITE_LOCAL, snapshotPath, Messages.resources_copyProblem, e);
1302
		} finally {
1305
		} finally {
1303
			if (out!=null) {
1306
			FileUtil.safeClose(out);
1304
				try { out.close(); } catch (IOException e) { /*ignore*/ }
1305
			}
1306
			if (tmpTree!=null) tmpTree.delete();
1307
			if (tmpTree!=null) tmpTree.delete();
1307
		}
1308
		}
1308
	}
1309
	}
Lines 1322-1329 Link Here
1322
			try {
1323
			try {
1323
				output.writeInt(ICoreConstants.WORKSPACE_TREE_VERSION_2);
1324
				output.writeInt(ICoreConstants.WORKSPACE_TREE_VERSION_2);
1324
				writeTree(computeStatesToSave(contexts, workspace.getElementTree()), output, monitor);
1325
				writeTree(computeStatesToSave(contexts, workspace.getElementTree()), output, monitor);
1325
			} finally {
1326
				output.close();
1326
				output.close();
1327
			} finally {
1328
				FileUtil.safeClose(output);
1327
			}
1329
			}
1328
		} catch (Exception e) {
1330
		} catch (Exception e) {
1329
			String msg = NLS.bind(Messages.resources_writeWorkspaceMeta, treeLocation);
1331
			String msg = NLS.bind(Messages.resources_writeWorkspaceMeta, treeLocation);
Lines 1549-1560 Link Here
1549
			if (root.getType() != IResource.ROOT)
1551
			if (root.getType() != IResource.ROOT)
1550
				o2 = new DataOutputStream(new SafeFileOutputStream(syncInfoLocation.toOSString(), syncInfoTempLocation.toOSString()));
1552
				o2 = new DataOutputStream(new SafeFileOutputStream(syncInfoLocation.toOSString(), syncInfoTempLocation.toOSString()));
1551
		} catch (IOException e) {
1553
		} catch (IOException e) {
1552
			if (o1 != null)
1554
			FileUtil.safeClose(o1);
1553
				try {
1554
					o1.close();
1555
				} catch (IOException e2) {
1556
					// ignore
1557
				}
1558
			message = NLS.bind(Messages.resources_writeMeta, root.getFullPath());
1555
			message = NLS.bind(Messages.resources_writeMeta, root.getFullPath());
1559
			throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, root.getFullPath(), message, e);
1556
			throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, root.getFullPath(), message, e);
1560
		}
1557
		}
Lines 1610-1617 Link Here
1610
			removeGarbage(markersOutput, markersLocation, markersTempLocation);
1607
			removeGarbage(markersOutput, markersLocation, markersTempLocation);
1611
			// if we have the workspace root the output stream will be null and we
1608
			// if we have the workspace root the output stream will be null and we
1612
			// don't have to perform cleanup code
1609
			// don't have to perform cleanup code
1613
			if (syncInfoOutput != null)
1610
			if (syncInfoOutput != null) {
1614
				removeGarbage(syncInfoOutput, syncInfoLocation, syncInfoTempLocation);
1611
				removeGarbage(syncInfoOutput, syncInfoLocation, syncInfoTempLocation);
1612
				syncInfoOutput.close();
1613
			}
1614
			markersOutput.close();
1615
		} catch (IOException e) {
1615
		} catch (IOException e) {
1616
			message = NLS.bind(Messages.resources_writeMeta, root.getFullPath());
1616
			message = NLS.bind(Messages.resources_writeMeta, root.getFullPath());
1617
			throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, root.getFullPath(), message, e);
1617
			throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, root.getFullPath(), message, e);
Lines 1719-1726 Link Here
1719
				System.out.println("Snap SyncInfo for " + root.getFullPath() + ": " + snapTimes[1] + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1719
				System.out.println("Snap SyncInfo for " + root.getFullPath() + ": " + snapTimes[1] + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1720
			if (markerFileSize != markersOutput.size())
1720
			if (markerFileSize != markersOutput.size())
1721
				safeMarkerStream.succeed();
1721
				safeMarkerStream.succeed();
1722
			if (safeSyncInfoStream != null && syncInfoFileSize != syncInfoOutput.size())
1722
			if (safeSyncInfoStream != null && syncInfoFileSize != syncInfoOutput.size()) {
1723
				safeSyncInfoStream.succeed();
1723
				safeSyncInfoStream.succeed();
1724
				syncInfoOutput.close();
1725
			}
1726
			markersOutput.close();
1724
		} catch (IOException e) {
1727
		} catch (IOException e) {
1725
			message = NLS.bind(Messages.resources_writeMeta, root.getFullPath());
1728
			message = NLS.bind(Messages.resources_writeMeta, root.getFullPath());
1726
			throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, root.getFullPath(), message, e);
1729
			throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, root.getFullPath(), message, e);
Lines 1969-1977 Link Here
1969
					output.writeUTF((String) it.next());
1972
					output.writeUTF((String) it.next());
1970
				for (Iterator it = additionalConfigNames.iterator(); it.hasNext();)
1973
				for (Iterator it = additionalConfigNames.iterator(); it.hasNext();)
1971
					output.writeUTF((String) it.next());
1974
					output.writeUTF((String) it.next());
1975
				output.close();
1972
			} finally {
1976
			} finally {
1973
				if (output != null)
1977
				FileUtil.safeClose(output);
1974
					output.close();
1975
				if (!wasImmutable)
1978
				if (!wasImmutable)
1976
					workspace.newWorkingTree();
1979
					workspace.newWorkingTree();
1977
			}
1980
			}
Lines 1990-1997 Link Here
1990
				DataOutputStream output = new DataOutputStream(safe);
1993
				DataOutputStream output = new DataOutputStream(safe);
1991
				output.writeInt(ICoreConstants.WORKSPACE_TREE_VERSION_2);
1994
				output.writeInt(ICoreConstants.WORKSPACE_TREE_VERSION_2);
1992
				writeTree(project, output, null);
1995
				writeTree(project, output, null);
1993
			} finally {
1994
				safe.close();
1996
				safe.close();
1997
			} finally {
1998
				FileUtil.safeClose(safe);
1995
			}
1999
			}
1996
		} catch (IOException e) {
2000
		} catch (IOException e) {
1997
			String msg = NLS.bind(Messages.resources_writeMeta, project.getFullPath());
2001
			String msg = NLS.bind(Messages.resources_writeMeta, project.getFullPath());
(-)src/org/eclipse/core/internal/utils/FileUtil.java (-19 / +22 lines)
Lines 175-199 Link Here
175
	 * Closes a stream and ignores any resulting exception. This is useful
175
	 * Closes a stream and ignores any resulting exception. This is useful
176
	 * when doing stream cleanup in a finally block where secondary exceptions
176
	 * when doing stream cleanup in a finally block where secondary exceptions
177
	 * are not worth logging.
177
	 * are not worth logging.
178
	 *
179
	 *<p>
180
	 * <strong>WARNING:</strong>
181
	 * If the API contract requires notifying clients of I/O problems, then you <strong>must</strong>
182
	 * explicitly close() output streams outside of safeClose().
183
	 * Some OutputStreams will defer an IOException from write() to close().  So
184
	 * while the writes may 'succeed', ignoring the IOExcpetion will result in silent
185
	 * data loss.
186
	 * </p>
187
	 * <p>
188
	 * This method should only be used as a fail-safe to ensure resources are not
189
	 * leaked.
190
	 * </p>
191
	 * See also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=332543
178
	 */
192
	 */
179
	public static void safeClose(InputStream in) {
193
	public static void safeClose(Closeable stream) {
180
		try {
181
			if (in != null)
182
				in.close();
183
		} catch (IOException e) {
184
			//ignore
185
		}
186
	}
187
188
	/**
189
	 * Closes a stream and ignores any resulting exception. This is useful
190
	 * when doing stream cleanup in a finally block where secondary exceptions
191
	 * are not worth logging.
192
	 */
193
	public static void safeClose(OutputStream out) {
194
		try {
194
		try {
195
			if (out != null)
195
			if (stream != null)
196
				out.close();
196
				stream.close();
197
		} catch (IOException e) {
197
		} catch (IOException e) {
198
			//ignore
198
			//ignore
199
		}
199
		}
Lines 233-241 Link Here
233
						String msg = NLS.bind(Messages.localstore_failedReadDuringWrite, path);
233
						String msg = NLS.bind(Messages.localstore_failedReadDuringWrite, path);
234
						throw new ResourceException(IResourceStatus.FAILED_READ_LOCAL, new Path(path), msg, e);
234
						throw new ResourceException(IResourceStatus.FAILED_READ_LOCAL, new Path(path), msg, e);
235
					}
235
					}
236
					if (bytesRead == -1)
237
						break;
238
					try {
236
					try {
237
						if (bytesRead == -1) {
238
							// Bug 332543 - ensure we don't ignore failures on close()
239
							destination.close();
240
							break;
241
						}
239
						destination.write(buffer, 0, bytesRead);
242
						destination.write(buffer, 0, bytesRead);
240
					} catch (IOException e) {
243
					} catch (IOException e) {
241
						String msg = NLS.bind(Messages.localstore_couldNotWrite, path);
244
						String msg = NLS.bind(Messages.localstore_couldNotWrite, path);

Return to bug 332543