translate the note of FileUtil into English

translate the note of FileUtil into English
pull/112/head
xufulong 5 years ago
parent 0761e47959
commit d236171c01
  1. 37
      app/src/main/java/com/frank/ffmpeg/util/BitmapUtil.java
  2. 39
      app/src/main/java/com/frank/ffmpeg/util/FileUtil.java

@ -13,7 +13,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
/**
* bitmap工具类文字转成图片
* bitmap tool
* Created by frank on 2018/1/24.
*/
@ -23,12 +23,13 @@ public class BitmapUtil {
private final static int TEXT_COLOR = Color.RED;
/**
* 文本转成Bitmap
* @param text 文本内容
* @param context 上下文
* @return 图片的bitmap
* convert text to bitmap
*
* @param text text
* @param context context
* @return bitmap of teh text
*/
private static Bitmap textToBitmap(String text , Context context) {
private static Bitmap textToBitmap(String text, Context context) {
float scale = context.getResources().getDisplayMetrics().scaledDensity;
TextView tv = new TextView(context);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
@ -47,18 +48,19 @@ public class BitmapUtil {
tv.buildDrawingCache();
Bitmap bitmap = tv.getDrawingCache();
int rate = bitmap.getHeight() / 20;
return Bitmap.createScaledBitmap(bitmap, bitmap.getWidth()/rate, 20, false);
return Bitmap.createScaledBitmap(bitmap, bitmap.getWidth() / rate, 20, false);
}
/**
* 文字生成图片
* convert text to picture
*
* @param filePath filePath
* @param text text
* @param context context
* @return 生成图片是否成功
* @param text text
* @param context context
* @return result of generating picture
*/
public static boolean textToPicture(String filePath, String text , Context context){
Bitmap bitmap = textToBitmap(text , context);
public static boolean textToPicture(String filePath, String text, Context context) {
Bitmap bitmap = textToBitmap(text, context);
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream(filePath);
@ -67,9 +69,9 @@ public class BitmapUtil {
} catch (IOException e) {
e.printStackTrace();
return false;
}finally {
} finally {
try {
if(outputStream != null){
if (outputStream != null) {
outputStream.close();
}
} catch (IOException e) {
@ -80,9 +82,10 @@ public class BitmapUtil {
}
/**
* 删除源文件
* delete file
*
* @param filePath filePath
* @return 删除是否成功
* @return result of deletion
*/
public static boolean deleteTextFile(String filePath) {
File file = new File(filePath);

@ -9,7 +9,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
/**
* 文件工具类
* file tool
* Created by frank on 2018/5/9.
*/
@ -37,18 +37,18 @@ public class FileUtil {
private final static String TYPE_MOV = "mov";
private final static String TYPE_MPG = "mpg";
public static boolean concatFile(String srcFilePath, String appendFilePath, String concatFilePath){
if(TextUtils.isEmpty(srcFilePath)
public static boolean concatFile(String srcFilePath, String appendFilePath, String concatFilePath) {
if (TextUtils.isEmpty(srcFilePath)
|| TextUtils.isEmpty(appendFilePath)
|| TextUtils.isEmpty(concatFilePath)){
|| TextUtils.isEmpty(concatFilePath)) {
return false;
}
File srcFile = new File(srcFilePath);
if(!srcFile.exists()){
if (!srcFile.exists()) {
return false;
}
File appendFile = new File(appendFilePath);
if(!appendFile.exists()){
if (!appendFile.exists()) {
return false;
}
FileOutputStream outputStream = null;
@ -59,25 +59,25 @@ public class FileUtil {
outputStream = new FileOutputStream(new File(concatFilePath));
byte[] data = new byte[1024];
int len;
while ((len = inputStream1.read(data)) > 0){
while ((len = inputStream1.read(data)) > 0) {
outputStream.write(data, 0, len);
}
outputStream.flush();
while ((len = inputStream2.read(data)) > 0){
while ((len = inputStream2.read(data)) > 0) {
outputStream.write(data, 0, len);
}
outputStream.flush();
} catch (IOException e){
} catch (IOException e) {
e.printStackTrace();
}finally {
} finally {
try {
if(inputStream1 != null){
if (inputStream1 != null) {
inputStream1.close();
}
if(inputStream2 != null){
if (inputStream2 != null) {
inputStream2.close();
}
if(outputStream != null){
if (outputStream != null) {
outputStream.close();
}
} catch (IOException e) {
@ -88,16 +88,17 @@ public class FileUtil {
}
/**
* 判断文件是否存在
* @param path 文件路径
* @return 文件是否存在
* check the file exist or not
*
* @param path the path of file
* @return result of exist or not
*/
public static boolean checkFileExist(String path){
public static boolean checkFileExist(String path) {
if (TextUtils.isEmpty(path)) {
return false;
}
File file = new File(path);
if(!file.exists()){
if (!file.exists()) {
Log.e("FileUtil", path + " is not exist!");
return false;
}
@ -178,7 +179,7 @@ public class FileUtil {
}
outputStream = new FileOutputStream(listFile);
StringBuilder fileBuilder = new StringBuilder();
for (String file:fileArray) {
for (String file : fileArray) {
fileBuilder
.append("file")
.append(" ")

Loading…
Cancel
Save