Java Question Function returns java.io.file

thedesolatesoul

Expert
Licensed User
Longtime User
Hi,
I have a (file download) function returning a type of Java.io.file.
Am I better off returning a HttpResponse to B4A rather than the file type.

B4X:
  public FileDownload getFileStream(String root, String dbPath, String etag) {
        try {
            HttpResponse response = mClient.getFileWithVersion(root, dbPath, etag);
            return new FileDownload(response);
        } catch (DropboxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

    public File getFile(String root, String dbPath, File localFile, String etag) {
        FileOutputStream fos = null;
        HttpEntity entity = null;
        String result = "";
        try  {
            FileDownload response = getFileStream(root, dbPath, etag);

            entity = response.entity;

            //            localFile = openNewLocalFile(root, dbPath);
            try {
                fos = new FileOutputStream(localFile);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }        

            entity.writeTo(fos);
        } catch (SocketException se) {
            System.out.println(se.toString());
        } catch (IOException ioe) {
            System.out.println(ioe.toString());
        } finally {
            System.out.println("Result: " + result);
            try {
                if (entity != null) entity.consumeContent();
            } catch (IOException ioe) {}
            try {
                if (fos != null) fos.close();
            } catch (IOException ioe) {}

        }

        return localFile;
    }
 
Top