Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-4906

FB - Capture.java - method does not clean up stream

    XMLWordPrintableJSON

Details

    Description

      Resolve FindBugs reported issue in Capture.java:

      Before

      FileInputStream fis = new FileInputStream(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/Capture.jpg");                    
      OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
      byte[] buffer = new byte[4096];
      int len;
      while ((len = fis.read(buffer)) != -1) {
          os.write(buffer, 0, len);
      }
      os.flush();
      os.close();
      fis.close();
      

      After

      FileInputStream fis = new FileInputStream(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/Capture.jpg");
      try {
          OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
          try {
              byte[] buffer = new byte[4096];
              int len;
              while ((len = fis.read(buffer)) != -1) {
                  os.write(buffer, 0, len);
              }
              os.flush();
          } finally {
              os.close();
          }
      } finally {
          fis.close();
      }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              dinglemouse Peter
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: