<commit_before>@file:JvmName("Utils")
@file:JvmMultifileClass

package pyxis.uzuki.live.richutilskt.utils

import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.net.Uri
import android.util.Log
import java.io.File
import java.io.FileNotFoundException
import java.io.FileOutputStream
import java.io.IOException
import java.util.*

/**
 * Save Bitmap to file
 *
 * @param[bitmap] to save
 * @return path of file
 */
fun Context.saveBitmapToFile(bitmap: Bitmap): String? {
    try {
        val file = saveBitmapToFile(this, bitmap)
        return file?.absolutePath
    } catch (e: Exception) {
    }

    return ""
}

private fun saveBitmapToFile(context: Context, bitmap: Bitmap): File? {
    try {
        val photo = getOutputMediaFile(context)
        val out = FileOutputStream(photo)
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out)
        out.close()

        return photo
    } catch (exception: FileNotFoundException) {
        Log.e("FileNotFoundException", exception.message)
    } catch (exception: IOException) {
        Log.e("IOException", exception.message)
    }

    return null
}<commit_msg>Improve RBitmap<commit_after>@file:JvmName("Utils")
@file:JvmMultifileClass

package pyxis.uzuki.live.richutilskt.utils

import android.content.Context
import android.content.Intent
import android.graphics.*
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.net.Uri
import android.util.Log
import java.io.File
import java.io.FileNotFoundException
import java.io.FileOutputStream
import java.io.IOException
import java.util.*
import android.text.TextUtils


/**
 * Save Bitmap to file
 *
 * @param[bitmap] to save
 * @return path of file
 */
fun Context.saveBitmapToFile(bitmap: Bitmap): String? {
    try {
        val file = saveBitmapToFile(this, bitmap)
        return file?.absolutePath
    } catch (e: Exception) {
    }

    return ""
}

/**
 * get bitmap from filePath
 * @return Bitmap object
 */
fun getBitmap(filePath: String): Bitmap? {
    if (TextUtils.isEmpty(filePath)) return null
    return BitmapFactory.decodeFile(filePath)
}

/**
 * Make bitmap corner
 * @return Bitmap object
 */
fun toRoundCorner(original: Bitmap?, radius: Float): Bitmap? {
    if (original == null)
        return null
    val width = original.width
    val height = original.height
    val bitmap = Bitmap.createBitmap(width, height, original.config)
    val paint = Paint()
    val canvas = Canvas(bitmap)
    val rect = Rect(0, 0, width, height)

    paint.isAntiAlias = true
    canvas.drawRoundRect(RectF(rect), radius, radius, paint)
    paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN)
    canvas.drawBitmap(original, rect, rect, paint)

    original.recycle()
    return bitmap
}

private fun saveBitmapToFile(context: Context, bitmap: Bitmap): File? {
    try {
        val photo = getOutputMediaFile(context)
        val out = FileOutputStream(photo)
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out)
        out.close()

        return photo
    } catch (exception: FileNotFoundException) {
        Log.e("FileNotFoundException", exception.message)
    } catch (exception: IOException) {
        Log.e("IOException", exception.message)
    }

    return null
}
{'fraction_non_alphanumeric': 0.10360884749708964, 'fraction_numerical': 0.002328288707799767, 'mean_word_length': 3.638326585695007, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2654199', 'n_tokens_mistral': 1020, 'n_tokens_neox': 999, 'n_words': 249}