You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
2.5 KiB
102 lines
2.5 KiB
package com.eco.plugin.wink.xdfileencrypt.utils; |
|
|
|
import com.finebi.web.action.v5.api.BiApiAction; |
|
import com.fr.base.core.IgnoreBytesInputStream; |
|
|
|
import java.io.*; |
|
|
|
public class FileUtils { |
|
public static void writeBytesToFile(byte[] bFile, String fileDest) { |
|
FileOutputStream fileOuputStream = null; |
|
try { |
|
fileOuputStream = new FileOutputStream(fileDest); |
|
fileOuputStream.write(bFile); |
|
|
|
} catch (IOException e) { |
|
}finally { |
|
if(fileOuputStream != null){ |
|
try { |
|
fileOuputStream.flush(); |
|
fileOuputStream.close(); |
|
} catch (IOException e) { |
|
} |
|
|
|
} |
|
} |
|
|
|
} |
|
|
|
public static void inputstreamToFile(IgnoreBytesInputStream inputStream, String filePath){ |
|
BufferedOutputStream bos = null; |
|
BufferedInputStream bis = new BufferedInputStream(inputStream); |
|
try { |
|
bos = new BufferedOutputStream(new FileOutputStream(new File(filePath))); |
|
int bytesRead = 0; |
|
byte[] buffer = new byte[8192]; |
|
while ((bytesRead = bis.read(buffer, 0, 8192)) != -1) { |
|
bos.write(buffer, 0, bytesRead); |
|
} |
|
} catch (Exception e) { |
|
|
|
} finally { |
|
if (inputStream != null) { |
|
try { |
|
inputStream.close(); |
|
} catch (IOException e) { |
|
} |
|
inputStream = null; |
|
} |
|
if (bos != null) { |
|
try { |
|
bos.close(); |
|
} catch (IOException e) { |
|
} |
|
bos = null; |
|
} |
|
if (bis != null) { |
|
try { |
|
bis.close(); |
|
} catch (IOException e) { |
|
} |
|
bis = null; |
|
} |
|
} |
|
} |
|
|
|
public static byte[] readBytesFromFile(String filePath) { |
|
|
|
FileInputStream fileInputStream = null; |
|
|
|
byte[] bytesArray = null; |
|
|
|
try { |
|
File file = new File(filePath); |
|
|
|
bytesArray = new byte[(int) file.length()]; |
|
fileInputStream = new FileInputStream(file); |
|
|
|
fileInputStream.read(bytesArray); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} finally { |
|
|
|
if (fileInputStream != null) { |
|
|
|
try { |
|
fileInputStream.close(); |
|
|
|
} catch (IOException e) { |
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return bytesArray; |
|
|
|
} |
|
|
|
}
|
|
|