// Copies the input to the output in the most efficient manner possible.
  // Closes both streams.
  public void copyResource(OpenForReadResult input, OutputStream outputStream) throws IOException {
    assertBackgroundThread();
    try {
      InputStream inputStream = input.inputStream;
      if (inputStream instanceof FileInputStream && outputStream instanceof FileOutputStream) {
        FileChannel inChannel = ((FileInputStream) input.inputStream).getChannel();
        FileChannel outChannel = ((FileOutputStream) outputStream).getChannel();
        long offset = 0;
        long length = input.length;
        if (input.assetFd != null) {
          offset = input.assetFd.getStartOffset();
        }
        outChannel.transferFrom(inChannel, offset, length);
      } else {
        final int BUFFER_SIZE = 8192;
        byte[] buffer = new byte[BUFFER_SIZE];

        for (; ; ) {
          int bytesRead = inputStream.read(buffer, 0, BUFFER_SIZE);

          if (bytesRead <= 0) {
            break;
          }
          outputStream.write(buffer, 0, bytesRead);
        }
      }
    } finally {
      input.inputStream.close();
      if (outputStream != null) {
        outputStream.close();
      }
    }
  }
 /**
  * Returns a File that points to the resource, or null if the resource is not on the local
  * filesystem.
  */
 public File mapUriToFile(Uri uri) {
   assertBackgroundThread();
   switch (getUriType(uri)) {
     case URI_TYPE_FILE:
       return new File(uri.getPath());
     case URI_TYPE_CONTENT:
       {
         Cursor cursor = contentResolver.query(uri, LOCAL_FILE_PROJECTION, null, null, null);
         if (cursor != null) {
           try {
             int columnIndex = cursor.getColumnIndex(LOCAL_FILE_PROJECTION[0]);
             if (columnIndex != -1 && cursor.getCount() > 0) {
               cursor.moveToFirst();
               String realPath = cursor.getString(columnIndex);
               if (realPath != null) {
                 return new File(realPath);
               }
             }
           } finally {
             cursor.close();
           }
         }
       }
   }
   return null;
 }
 /**
  * Opens a stream to the givne URI, also providing the MIME type & length.
  *
  * @return Never returns null.
  * @throws Throws an InvalidArgumentException for relative URIs. Relative URIs should be resolved
  *     before being passed into this function.
  * @throws Throws an IOException if the URI cannot be opened.
  * @throws Throws an IllegalStateException if called on a foreground thread and skipThreadCheck is
  *     false.
  */
 public OpenForReadResult openForRead(Uri uri, boolean skipThreadCheck) throws IOException {
   if (!skipThreadCheck) {
     assertBackgroundThread();
   }
   switch (getUriType(uri)) {
     case URI_TYPE_FILE:
       {
         FileInputStream inputStream = new FileInputStream(uri.getPath());
         String mimeType = FileHelper.getMimeTypeForExtension(uri.getPath());
         long length = inputStream.getChannel().size();
         return new OpenForReadResult(uri, inputStream, mimeType, length, null);
       }
     case URI_TYPE_ASSET:
       {
         String assetPath = uri.getPath().substring(15);
         AssetFileDescriptor assetFd = null;
         InputStream inputStream;
         long length = -1;
         try {
           assetFd = assetManager.openFd(assetPath);
           inputStream = assetFd.createInputStream();
           length = assetFd.getLength();
         } catch (FileNotFoundException e) {
           // Will occur if the file is compressed.
           inputStream = assetManager.open(assetPath);
         }
         String mimeType = FileHelper.getMimeTypeForExtension(assetPath);
         return new OpenForReadResult(uri, inputStream, mimeType, length, assetFd);
       }
     case URI_TYPE_CONTENT:
     case URI_TYPE_RESOURCE:
       {
         String mimeType = contentResolver.getType(uri);
         AssetFileDescriptor assetFd = contentResolver.openAssetFileDescriptor(uri, "r");
         InputStream inputStream = assetFd.createInputStream();
         long length = assetFd.getLength();
         return new OpenForReadResult(uri, inputStream, mimeType, length, assetFd);
       }
     case URI_TYPE_DATA:
       {
         OpenForReadResult ret = readDataUri(uri);
         if (ret == null) {
           break;
         }
         return ret;
       }
     case URI_TYPE_HTTP:
     case URI_TYPE_HTTPS:
       {
         HttpURLConnection conn = httpClient.open(new URL(uri.toString()));
         conn.setDoInput(true);
         String mimeType = conn.getHeaderField("Content-Type");
         int length = conn.getContentLength();
         InputStream inputStream = conn.getInputStream();
         return new OpenForReadResult(uri, inputStream, mimeType, length, null);
       }
   }
   throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + uri);
 }
 public OutputStream openOutputStream(Uri paramUri, boolean paramBoolean) throws IOException {
   assertBackgroundThread();
   switch (getUriType(paramUri)) {
     case 1:
     default:
       throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + paramUri);
     case 0:
       paramUri = new File(paramUri.getPath());
       localObject = paramUri.getParentFile();
       if (localObject != null) {
         ((File) localObject).mkdirs();
       }
       return new FileOutputStream(paramUri, paramBoolean);
   }
   ContentResolver localContentResolver = contentResolver;
   if (paramBoolean) {}
   for (Object localObject = "wa"; ; localObject = "w") {
     return localContentResolver
         .openAssetFileDescriptor(paramUri, (String) localObject)
         .createOutputStream();
   }
 }
 /**
  * Opens a stream to the given URI.
  *
  * @return Never returns null.
  * @throws Throws an InvalidArgumentException for relative URIs. Relative URIs should be resolved
  *     before being passed into this function.
  * @throws Throws an IOException if the URI cannot be opened.
  */
 public OutputStream openOutputStream(Uri uri, boolean append) throws IOException {
   assertBackgroundThread();
   switch (getUriType(uri)) {
     case URI_TYPE_FILE:
       {
         File localFile = new File(uri.getPath());
         File parent = localFile.getParentFile();
         if (parent != null) {
           parent.mkdirs();
         }
         return new FileOutputStream(localFile, append);
       }
     case URI_TYPE_CONTENT:
     case URI_TYPE_RESOURCE:
       {
         AssetFileDescriptor assetFd =
             contentResolver.openAssetFileDescriptor(uri, append ? "wa" : "w");
         return assetFd.createOutputStream();
       }
   }
   throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + uri);
 }
 public File mapUriToFile(Uri paramUri) {
   assertBackgroundThread();
   switch (getUriType(paramUri)) {
   }
   do {
     return null;
     return new File(paramUri.getPath());
     paramUri = contentResolver.query(paramUri, LOCAL_FILE_PROJECTION, null, null, null);
   } while (paramUri == null);
   try {
     int i = paramUri.getColumnIndex(LOCAL_FILE_PROJECTION[0]);
     if ((i != -1) && (paramUri.getCount() > 0)) {
       paramUri.moveToFirst();
       Object localObject1 = paramUri.getString(i);
       if (localObject1 != null) {
         localObject1 = new File((String) localObject1);
         return (File) localObject1;
       }
     }
     return null;
   } finally {
     paramUri.close();
   }
 }
 public OpenForReadResult openForRead(Uri paramUri, boolean paramBoolean) throws IOException {
   if (!paramBoolean) {
     assertBackgroundThread();
   }
   switch (getUriType(paramUri)) {
     default:
     case 0:
     case 1:
     case 2:
     case 3:
     case 4:
       do {
         throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + paramUri);
         localObject1 = new FileInputStream(paramUri.getPath());
         return new OpenForReadResult(
             paramUri,
             (InputStream) localObject1,
             getMimeTypeFromPath(paramUri.getPath()),
             ((FileInputStream) localObject1).getChannel().size(),
             null);
         String str = paramUri.getPath().substring(15);
         localObject1 = null;
         long l1 = -1L;
         try {
           localObject2 = assetManager.openFd(str);
           localObject1 = localObject2;
           FileInputStream localFileInputStream =
               ((AssetFileDescriptor) localObject2).createInputStream();
           localObject1 = localObject2;
           long l2 = ((AssetFileDescriptor) localObject2).getLength();
           l1 = l2;
           localObject1 = localObject2;
           localObject2 = localFileInputStream;
         } catch (FileNotFoundException localFileNotFoundException) {
           for (; ; ) {
             Object localObject2;
             localObject3 = assetManager.open(str);
           }
         }
         return new OpenForReadResult(
             paramUri,
             (InputStream) localObject2,
             getMimeTypeFromPath(str),
             l1,
             (AssetFileDescriptor) localObject1);
         localObject1 = contentResolver.getType(paramUri);
         localObject3 = contentResolver.openAssetFileDescriptor(paramUri, "r");
         return new OpenForReadResult(
             paramUri,
             ((AssetFileDescriptor) localObject3).createInputStream(),
             (String) localObject1,
             ((AssetFileDescriptor) localObject3).getLength(),
             (AssetFileDescriptor) localObject3);
         localObject1 = readDataUri(paramUri);
       } while (localObject1 == null);
       return (OpenForReadResult) localObject1;
   }
   Object localObject1 = httpClient.open(new URL(paramUri.toString()));
   ((HttpURLConnection) localObject1).setDoInput(true);
   Object localObject3 = ((HttpURLConnection) localObject1).getHeaderField("Content-Type");
   int i = ((HttpURLConnection) localObject1).getContentLength();
   return new OpenForReadResult(
       paramUri,
       ((HttpURLConnection) localObject1).getInputStream(),
       (String) localObject3,
       i,
       null);
 }
 public HttpURLConnection createHttpConnection(Uri paramUri) throws IOException {
   assertBackgroundThread();
   return httpClient.open(new URL(paramUri.toString()));
 }