Removed the dependency of SampleDataPopulator on gwt-dev by "inlining" the dependency.
Checked that the SampleDataPopulator program can still read the file as before.

Will need to clean this up later. There is an issue for productizing the data populator.

Patch by: amitmanjhi
Review by: fabbott (TBR)

Review at http://gwt-code-reviews.appspot.com/652802


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@8319 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/bikeshed/scripts/dataPopulator b/bikeshed/scripts/dataPopulator
index c98fbfb..8d24cc8 100755
--- a/bikeshed/scripts/dataPopulator
+++ b/bikeshed/scripts/dataPopulator
@@ -22,7 +22,7 @@
 MAVEN_REPO=~/.m2/repository
 
 NEW_CLASSPATH=$MAVEN_REPO/org/json/json/20090211/json-20090211.jar
-for i in dev user servlet bikeshed
+for i in dev user servlet 
 do 
   NEW_CLASSPATH=$MAVEN_REPO/com/google/gwt/gwt-${i}/2.1.0.M1/gwt-${i}-2.1.0.M1.jar:$NEW_CLASSPATH
 done
diff --git a/user/src/com/google/gwt/requestfactory/server/SampleDataPopulator.java b/user/src/com/google/gwt/requestfactory/server/SampleDataPopulator.java
index c6709b0..7c988bb 100644
--- a/user/src/com/google/gwt/requestfactory/server/SampleDataPopulator.java
+++ b/user/src/com/google/gwt/requestfactory/server/SampleDataPopulator.java
@@ -15,7 +15,6 @@
  */
 package com.google.gwt.requestfactory.server;
 
-import com.google.gwt.dev.util.Util;
 import com.google.gwt.requestfactory.shared.RequestFactory;
 import com.google.gwt.requestfactory.shared.impl.RequestDataManager;
 import com.google.gwt.valuestore.shared.WriteOperation;
@@ -29,7 +28,9 @@
 import org.json.JSONObject;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 
 /**
  * <p>
@@ -108,9 +109,49 @@
     return jsonObject;
   }
 
-  private String readFileAsString(String filePathName) {
+  // ugly method, refactor later when cleaning up this class.
+  private byte[] readFileAsBytes(String filePathName) {
     File file = new File(filePathName);
-    return Util.readFileAsString(file);
+    FileInputStream fileInputStream = null;
+    byte bytes[] = null;
+    try {
+      fileInputStream = new FileInputStream(file);
+      int byteLength = (int) file.length();
+      bytes = new byte[byteLength];
+      int byteOffset = 0;
+      while (byteOffset < byteLength) {
+        int bytesReadCount = fileInputStream.read(bytes, byteOffset, byteLength
+            - byteOffset);
+        if (bytesReadCount == -1) {
+          return null;
+        }
+        byteOffset += bytesReadCount;
+      }
+    } catch (IOException e) {
+      // Ignored.
+    } finally {
+      try {
+        if (fileInputStream != null) {
+          fileInputStream.close();
+        }
+      } catch (IOException e) {
+        // ignored
+      }
+    }
+    return bytes;
+  }
+  
+  private String readFileAsString(String filePathName) {
+    byte bytes[] = readFileAsBytes(filePathName);
+    if (bytes != null) {
+      try {
+        return new String(bytes, "UTF-8");
+      } catch (UnsupportedEncodingException e) {
+        // Ignored.
+      }
+      return null;
+    }
+    return null;
   }
 
 }