From a2b9823bbf9e0d5b64c8454be39b992932a259c8 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 12 Nov 2019 18:47:17 -0500 Subject: [PATCH] Added comments and summaries to CopyAssets.java --- .../smapiandroidinstaller/CopyAssets.java | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/MartyrPher/smapiandroidinstaller/CopyAssets.java b/app/src/main/java/com/MartyrPher/smapiandroidinstaller/CopyAssets.java index 6e54455..cf6932a 100644 --- a/app/src/main/java/com/MartyrPher/smapiandroidinstaller/CopyAssets.java +++ b/app/src/main/java/com/MartyrPher/smapiandroidinstaller/CopyAssets.java @@ -11,32 +11,49 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +/** + * Allows assets from the apk to be copied to a local folder to be worked with + */ public class CopyAssets { + //TAG for debugging purposes private final static String TAG = "CopyAssets"; + //MainActivity context private final Context context; + /** + * Constructor that sets the context + * @param appContext = The activities context + */ public CopyAssets(Context appContext) { this.context = appContext; } - //Copies the needed files from the APK to a local directory so they can be used + /** + * Copies the needed files from the APK to a local directory so they can be used + * @param asset = The asset to copy + * @param dir = The directory to copy the asset to + */ public void copyAssets(String asset, String dir) { AssetManager assetManager = context.getAssets(); String[] files = null; File dest = new File(Environment.getExternalStorageDirectory() + dir); - if(!dest.exists()) - { + + //Check is the directory exists + if(!dest.exists()) { dest.mkdir();//directory is created; } + + //Try to get the list of assets try { files = assetManager.list(asset); } catch (IOException e) { Log.e(TAG, "Failed to get asset file list.", e); } - Log.e(TAG, "File Length: " + files.length); + + //Open the asset and copy it if (files != null) for (String filename : files) { InputStream in = null; OutputStream out = null; @@ -67,6 +84,12 @@ public class CopyAssets { } } + /** + * Short method that copies the files using an InputStream and OutputStream + * @param in = The input stream + * @param out = The output stream + * @throws IOException if one of the streams fail + */ private void copyFile(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[1024]; int read;