Hedgeroid: Simplified some code
authorMedo <smaxein@googlemail.com>
Wed, 11 Jul 2012 01:51:28 +0200
changeset 7326 1fae07363938
parent 7324 fb6bfe8e30c8
child 7328 cd919a2ead4e
Hedgeroid: Simplified some code
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadAssets.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/SDLActivity.java
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadAssets.java	Wed Jul 11 01:40:35 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadAssets.java	Wed Jul 11 01:51:28 2012 +0200
@@ -2,10 +2,7 @@
 
 import java.io.File;
 import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
 
 import org.hedgewars.hedgeroid.MainActivity;
 import org.hedgewars.hedgeroid.R;
@@ -27,7 +24,7 @@
 	
 	private static void copyFileOrDir(AssetManager assetManager, File target, String assetPath) throws IOException {
 		try {
-			copyFile(assetManager, target, assetPath);
+			Utils.writeStreamToFile(assetManager.open(assetPath), target);
 		} catch(FileNotFoundException e) {
 			/*
 			 * I can't find a better way to figure out whether an asset entry is
@@ -43,24 +40,6 @@
 		}
 	}
 	
-	private static void copyFile(AssetManager assetManager, File target, String assetPath) throws IOException {
-		InputStream is = null;
-		OutputStream os = null;
-		byte[] buffer = new byte[8192];
-		try {
-			is = assetManager.open(assetPath);
-			os = new FileOutputStream(target);
-			int size;
-			while((size=is.read(buffer)) != -1) {
-				os.write(buffer, 0, size);
-			}
-			os.close(); // Important to close this non-quietly, in case of exceptions when flushing
-		} finally {
-			Utils.closeQuietly(is);
-			Utils.closeQuietly(os);
-		}
-	}
-	
 	@Override
 	protected Long doInBackground(Object... params) {
 		try {
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/SDLActivity.java	Wed Jul 11 01:40:35 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/SDLActivity.java	Wed Jul 11 01:51:28 2012 +0200
@@ -443,7 +443,6 @@
 			e.printStackTrace();
 		}
 		Log.v("SDL", "SDL thread terminated");
-		//Log.v("SDL", "SDL thread terminated");
 	}
 }