📄 fileserviceimp.java
字号:
package com.hb.base.services.common.imp;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.hb.base.services.common.IFileService;
import com.hb.base.util.Constant;
import com.hb.base.util.FacesContextUtil;
import com.hb.core.util.StringUtil;
/**
* 2008/03/26
*
* @author 何 貝
*
* 名字后面多加了一个s主要是不想被Spring加入事务管理
*/
@Component("fileServices")
@Scope("prototype")
public class FileServiceImp implements IFileService {
public boolean delEmpPhoto_Service(String employeeID) {
// 相片
File _file = new File(FacesContextUtil.getRealPath() + Constant.PHOTO_PATH + employeeID
+ Constant.PHOTO_FILE_SUFFIX);
if (_file.exists()) {
_file.delete();
return true;
}
return false;
}
public String getPhotoFilePath_Service(String employeeID) {
// 相片
File _file = new File(FacesContextUtil.getRealPath() + Constant.PHOTO_PATH + employeeID
+ Constant.PHOTO_FILE_SUFFIX);
if (_file.exists()) {
return Constant.PHOTO_PATH + employeeID + Constant.PHOTO_FILE_SUFFIX;
} else {
return null;
}
}
public boolean savePhotoFile_Service(String employeeID, InputStream fileData) throws IOException {
String filePath = FacesContextUtil.getRealPath() + Constant.PHOTO_PATH + employeeID
+ Constant.PHOTO_FILE_SUFFIX;
return saveFile_Service(filePath, fileData);
}
public boolean saveFile_Service(String filePath, InputStream fileData) throws IOException {
if (!StringUtil.isEmpty(filePath) && fileData != null) {
final int bufferSize = 1000;
File file = new File(filePath);
FileOutputStream fout = new FileOutputStream(file);
byte[] buffer = new byte[bufferSize];
int readCount = 0;
while ((readCount = fileData.read(buffer)) != -1) {
if (readCount < bufferSize) {
fout.write(buffer, 0, readCount);
} else {
fout.write(buffer);
}
}
fout.close();
fileData.close();
return true;
} else {
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -