{Android] Eliminate need for even using a byte array when copying assets over.

This commit is contained in:
Lioncash 2013-10-09 12:35:12 -04:00
parent 414ed6ef63
commit 0dd32986b8
1 changed files with 16 additions and 19 deletions

View File

@ -11,10 +11,12 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.util.Log; import android.util.Log;
import org.dolphinemu.dolphinemu.gamelist.GameListActivity; import org.dolphinemu.dolphinemu.gamelist.GameListActivity;
import org.dolphinemu.dolphinemu.settings.UserPreferences; import org.dolphinemu.dolphinemu.settings.UserPreferences;
import java.io.*; import java.io.*;
import java.nio.channels.FileChannel;
/** /**
* The main activity of this emulator front-end. * The main activity of this emulator front-end.
@ -23,16 +25,22 @@ public final class DolphinEmulator extends Activity
{ {
private void CopyAsset(String asset, String output) private void CopyAsset(String asset, String output)
{ {
InputStream in = null;
OutputStream out = null;
try try
{ {
in = getAssets().open(asset); // Get input file channel.
out = new FileOutputStream(output); FileInputStream inStream = getAssets().openFd(asset).createInputStream();
copyFile(in, out); FileChannel in = inStream.getChannel();
in.close();
out.close(); // Get output file channel.
FileOutputStream outStream = new FileOutputStream(output);
FileChannel out = outStream.getChannel();
// Copy over
in.transferTo(0, in.size(), out);
// Clean-up
inStream.close();
outStream.close();
} }
catch (IOException e) catch (IOException e)
{ {
@ -40,17 +48,6 @@ public final class DolphinEmulator extends Activity
} }
} }
private void copyFile(InputStream in, OutputStream out) throws IOException
{
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1)
{
out.write(buffer, 0, read);
}
}
@Override @Override
public void onCreate(Bundle savedInstanceState) public void onCreate(Bundle savedInstanceState)
{ {