Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
{Android] Eliminate need for even using a byte array when copying ass…
…ets over.
  • Loading branch information
lioncash committed Oct 9, 2013
1 parent 414ed6e commit 0dd3298
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions Source/Android/src/org/dolphinemu/dolphinemu/DolphinEmulator.java
Expand Up @@ -11,10 +11,12 @@
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;

import org.dolphinemu.dolphinemu.gamelist.GameListActivity;
import org.dolphinemu.dolphinemu.settings.UserPreferences;

import java.io.*;
import java.nio.channels.FileChannel;

/**
* The main activity of this emulator front-end.
Expand All @@ -23,34 +25,29 @@ public final class DolphinEmulator extends Activity
{
private void CopyAsset(String asset, String output)
{
InputStream in = null;
OutputStream out = null;

try
{
in = getAssets().open(asset);
out = new FileOutputStream(output);
copyFile(in, out);
in.close();
out.close();
// Get input file channel.
FileInputStream inStream = getAssets().openFd(asset).createInputStream();
FileChannel in = inStream.getChannel();

// 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)
{
Log.e("DolphinEmulator", "Failed to copy asset file: " + asset, e);
}
}

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
public void onCreate(Bundle savedInstanceState)
{
Expand Down

0 comments on commit 0dd3298

Please sign in to comment.