Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Unified Diff: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/utilities/io/FileUtilities.java

Issue 10459078: Issue 3341. Fix for file handle leak (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/utilities/io/FileUtilities.java
diff --git a/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/utilities/io/FileUtilities.java b/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/utilities/io/FileUtilities.java
index c6e67d9498343fe6d24fd03450cd5eb322d01469..1a491a8520a2529ffabae2588e61af2780cd1d4b 100644
--- a/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/utilities/io/FileUtilities.java
+++ b/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/utilities/io/FileUtilities.java
@@ -13,6 +13,8 @@
*/
package com.google.dart.tools.core.utilities.io;
+import com.google.common.io.CharStreams;
+
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
@@ -240,34 +242,25 @@ public class FileUtilities {
* @throws IOException if the file contents could not be read
*/
public static String getContents(File file) throws IOException {
- FileReader fileReader = null;
- try {
- fileReader = new FileReader(file);
- BufferedReader reader = new BufferedReader(fileReader);
- return getContents(reader);
- } finally {
- if (fileReader != null) {
- fileReader.close();
- }
- }
+ Reader fileReader = new FileReader(file);
+ BufferedReader reader = new BufferedReader(fileReader);
+ return getContents(reader);
}
/**
- * Return the contents of the given reader, interpreted as a string. The client is responsible for
- * closing the reader.
+ * Return the contents of the given reader, interpreted as a string. The {@link Reader} will be
+ * closed.
*
* @param reader the reader whose contents are to be returned
* @return the contents of the given reader, interpreted as a string
* @throws IOException if the reader could not be read
*/
public static String getContents(Reader reader) throws IOException {
- StringBuilder builder = new StringBuilder();
- int nextChar = reader.read();
- while (nextChar >= 0) {
- builder.append((char) nextChar);
- nextChar = reader.read();
+ try {
+ return CharStreams.toString(reader);
+ } finally {
+ reader.close();
}
- return builder.toString();
}
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698