Ejemplo n.º 1
0
  public static void copyFile(File sourceFile, File destinationFile) {

    try {
      FileInputStream fileInputStream = null;
      FileOutputStream fileOutputStream = null;

      // Inner try block is for streams and readers that needs closing.
      try {
        fileInputStream = new FileInputStream(sourceFile);
        fileOutputStream = new FileOutputStream(destinationFile);
        byte[] buffer = new byte[1024];
        int length = 0;

        while ((length = fileInputStream.read(buffer)) != -1) {
          fileOutputStream.write(buffer, 0, length);
        }
      } finally {

        if (fileInputStream != null) fileInputStream.close();

        if (fileOutputStream != null) fileOutputStream.close();
      }
    } catch (Throwable throwable) {
      App.e(FileUtilities.class, throwable);
    }
  }
Ejemplo n.º 2
0
  public static Bitmap getBitmapFromFile(File imageFile) {

    try {
      return BitmapFactory.decodeFile(imageFile.getPath());
    } catch (Exception exception) {
      App.e(FileUtilities.class, exception);
    }

    return null;
  }
Ejemplo n.º 3
0
  public static Bitmap getBitmapFromStream(InputStream inputStream) {

    try {
      return BitmapFactory.decodeStream(inputStream);
    } catch (Exception exception) {
      App.e(FileUtilities.class, exception);
    }

    return null;
  }
Ejemplo n.º 4
0
  public static Bitmap getBitmapFromResource(Context context, int drawable) {

    try {
      return BitmapFactory.decodeResource(context.getResources(), drawable);
    } catch (Exception exception) {
      App.e(FileUtilities.class, exception);
    }

    return null;
  }
Ejemplo n.º 5
0
  public static Drawable getDrawableFromResource(Context context, int drawable) {

    try {
      return context.getResources().getDrawable(drawable);
    } catch (Exception exception) {
      App.e(FileUtilities.class, exception);
    }

    return null;
  }