@@ -0,0 +1,3358 @@
+/*%0A * BRLTTY - A background process providing access to the console screen (when in%0A *          text mode) for a blind person using a refreshable braille display.%0A *%0A * Copyright (C) 1995-2020 by The BRLTTY Developers.%0A *%0A * BRLTTY comes with ABSOLUTELY NO WARRANTY.%0A *%0A * This is free software, placed under the terms of the%0A * GNU Lesser General Public License, as published by the Free Software%0A * Foundation; either version 2.1 of the License, or (at your option) any%0A * later version. Please see the file LICENSE-LGPL for details.%0A *%0A * Web Page: http://brltty.app/%0A *%0A * This software is maintained by Dave Mielke %3Cdave@mielke.cc%3E.%0A */%0A%0Apackage org.a11y.brltty.android;%0A%0Aimport android.util.Log;%0Aimport android.os.AsyncTask;%0A%0Aimport java.net.URL;%0Aimport java.io.File;%0A%0Aimport java.net.URLConnection;%0Aimport java.net.HttpURLConnection;%0A%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.io.OutputStream;%0Aimport java.io.FileOutputStream;%0A%0Apublic class FileDownloader %7B%0A  private final static String LOG_TAG = FileDownloader.class.getName();%0A%0A  protected final String sourceURL;%0A  protected final File targetFile;%0A%0A  public FileDownloader (String url, File file) %7B%0A    sourceURL = url;%0A    targetFile = file;%0A  %7D%0A%0A  private static void copy (InputStream input, OutputStream output) throws IOException %7B%0A    byte%5B%5D buffer = new byte%5B0X1000%5D;%0A    int length;%0A%0A    while ((length = input.read(buffer)) != -1) %7B%0A      output.write(buffer, 0, length);%0A    %7D%0A  %7D%0A%0A  protected void onDownloadStarted () %7B%0A  %7D%0A%0A  protected void onDownloadFinished () %7B%0A  %7D%0A%0A  protected void onDownloadFailed (String message) %7B%0A  %7D%0A%0A  public final void startDownload () %7B%0A    new AsyncTask%3CObject, Object, String%3E() %7B%0A      @Override%0A      protected void onPreExecute () %7B%0A        onDownloadStarted();%0A      %7D%0A%0A      @Override%0A      protected String doInBackground (Object... arguments) %7B%0A        try %7B%0A          URL url = new URL(sourceURL);%0A          HttpURLConnection connection = (HttpURLConnection)url.openConnection();%0A          connection.setRequestMethod(%22GET%22);%0A          connection.connect();%0A%0A          try %7B%0A            InputStream input = connection.getInputStream();%0A%0A            try %7B%0A              File file = targetFile;%0A              file.delete();%0A%0A              try %7B%0A                OutputStream output = new FileOutputStream(file);%0A%0A                try %7B%0A                  copy(input, output);%0A                  output.flush();%0A                  file = null;%0A                %7D finally %7B%0A                  output.close();%0A                  output = null;%0A                %7D%0A              %7D finally %7B%0A                if (file != null) file.delete();%0A              %7D%0A            %7D finally %7B%0A              input.close();%0A              input = null;%0A            %7D%0A          %7D finally %7B%0A            connection.disconnect();%0A            connection = null;%0A          %7D%0A        %7D catch (IOException exception) %7B%0A          String message = exception.getMessage();%0A          Log.w(LOG_TAG, String.format(%22file download failed: %25s: %25s%22, sourceURL, message));%0A          return message;%0A        %7D%0A%0A        return null;%0A      %7D%0A%0A      @Override%0A      protected void onPostExecute (String message) %7B%0A        if (message == null) %7B%0A          onDownloadFinished();%0A        %7D else %7B%0A          onDownloadFailed(message);%0A        %7D%0A      %7D%0A    %7D.execute();%0A  %7D%0A%7D%0A

Add the FileDownloader object. (dm)