// Copyright 2011 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.hughes.util;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.RandomAccessFile;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public final class FileUtil {
  public static String readLine(final RandomAccessFile file, final long startPos) throws IOException {
    file.seek(startPos);
    return file.readLine();
  }
  
  public static List<String> readLines(final File file) throws IOException {
    final List<String> result = new ArrayList<String>();
    final BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
    String line;
    while ((line = in.readLine()) != null) {
      result.add(line);
    }
    in.close();
    return result;
  }
  
  public static String readToString(final File file) throws IOException {
    final BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
    StringBuilder result = new StringBuilder();
    String line;
    while ((line = in.readLine()) != null) {
      result.append(line).append("\n");
    }
    in.close();
    return result.toString();
  }
  
  public static void writeStringToUTF8File(final String string, final File file) {
      throw new IllegalStateException();
  }

  public static void printString(final File file, final String s) throws IOException {
      final PrintStream out = new PrintStream(new FileOutputStream(file));
      out.print(s);
      out.close();
    }

}

@@ -1520,32 +1520,47 @@
 tream(file)));%0D%0A
+    try %7B%0D%0A    
     String line;
@@ -1553,32 +1553,36 @@
   String line;%0D%0A
+    
     while ((line
@@ -1609,32 +1609,36 @@
  null) %7B%0D%0A      
+  
+  
 result.add(line)
@@ -1636,31 +1636,56 @@
 add(line);%0D%0A
+    
     %7D%0D%0A
+    %7D finally %7B%0D%0A    
     in.close
@@ -1681,32 +1681,39 @@
    in.close();%0D%0A
+    %7D%0D%0A
     return resul
@@ -1946,24 +1946,39 @@
 Builder();%0D%0A
+    try %7B%0D%0A    
     String l
@@ -1979,24 +1979,28 @@
 ring line;%0D%0A
+    
     while ((
@@ -2035,24 +2035,28 @@
 l) %7B%0D%0A      
+  
+  
 result.appen
@@ -2074,31 +2074,56 @@
 end(%22%5Cn%22);%0D%0A
+    
     %7D%0D%0A
+    %7D finally %7B%0D%0A    
     in.close
@@ -2123,24 +2123,31 @@
 n.close();%0D%0A
+    %7D%0D%0A
     return r

Fix potential resource leaks.