title: cordova 3.0 FileWriter THREAD WARNING: exec() call to File.write blocked the main thread...should use CordovaInterface.getThreadPool()
body: <p>I'm using the FileWriter and it works fine except for these messages in the logcat when I write largish files of various sizes upto about 3MB.</p>
  
  <p>I had a look at the FileUtils.java source and the write function doesn't use the getThreadPool() interface (the reader does).</p>
  
  <p>As a test I thought I'd adapt the filewriter to use the runnable interface and was able to get the code to compile and execute - unfortunately the logcat messages still show up...</p>
  
  <p>The blocking times I get are anything between 25ms and 1200ms so far. I haven't run any serious comparison tests to determine if this change makes any real difference - I was just looking for the absence of logcat messages.</p>
  
  <p>Would these changes as below make any real difference?</p>
  
  <p>Are these message something I should worry about? </p>
  
  <p>My java is pretty basic - but here are the changes I made - following the reader implementation.</p>
  
  <pre><code>else if (action.equals("write")) {
      this.write(args.getString(0), args.getString(1), args.getInt(2), args.getBoolean(3), callbackContext);
  }
  /* this is the original code
  else if (action.equals("write")) {
      long fileSize = this.write(args.getString(0), args.getString(1), args.getInt(2), args.getBoolean(3));
      callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, fileSize));
  </code></pre>
  
  <p>}
    */</p>
  
  <p>And in the write function as below...</p>
  
  <pre><code>public void write(String filename, final String data, final int offset, final boolean isBinary, final CallbackContext callbackContext) throws FileNotFoundException, IOException, NoModificationAllowedException {
  if (filename.startsWith("content://")) {
      throw new NoModificationAllowedException("Couldn't write to file given its content URI");
  }
  
  final String fname = FileHelper.getRealPath(filename, cordova);
  
  this.cordova.getThreadPool().execute(new Runnable() {
      public void run() {
          Log.d(LOG_TAG, "Starting write");
          try {
              boolean append = false;
              byte[] rawData;
              if (isBinary) {
                  rawData = Base64.decode(data, Base64.DEFAULT);
              } else {
                  rawData = data.getBytes();
              }
              ByteArrayInputStream in = new ByteArrayInputStream(rawData);
              FileOutputStream out = new FileOutputStream(fname, append);
              byte buff[] = new byte[rawData.length];
              in.read(buff, 0, buff.length);
              out.write(buff, 0, rawData.length);
              out.flush();
              out.close();
              Log.d(LOG_TAG, "Ending write");
              callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, rawData.length));
          } catch (IOException e) {
              Log.d(LOG_TAG, e.getLocalizedMessage());
              callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, NOT_READABLE_ERR));
          }
      }
  });
  </code></pre>
  
  <p>}</p>