📄 filesystemfilemgr.java
字号:
package org.jbpm.persistence.filemgr;
import java.io.*;
import org.apache.commons.logging.*;
import org.jbpm.*;
import org.jbpm.util.io.*;
import org.jbpm.persistence.*;
public class FileSystemFileMgr implements FileMgr {
private String filesDirectory = null;
public FileSystemFileMgr( String filesDirectory ) {
this.filesDirectory = filesDirectory;
if ( ! filesDirectory.endsWith( "/" ) ) {
this.filesDirectory = this.filesDirectory + "/";
}
}
public FileSystemFileMgr( JbpmConfiguration jbpmConfiguration ) {
this( jbpmConfiguration.getProperty( "jbpm.file.mgr.directory" ) );
}
public void storeBytes(Long definitionId, String fileName, byte[] bytes) {
try {
// create the full file name
String filePath = filesDirectory + definitionId + "/" + fileName;
// create the directory
File dir = new File( filePath ).getParentFile();
dir.mkdirs();
// save the file contents
FileOutputStream out = new FileOutputStream( filePath );
InputStream in = new ByteArrayInputStream( bytes );
IoUtil.transfer( in, out );
} catch (FileNotFoundException e) {
log.error( "can't store files on the filesystem", e );
throw new ConfigurationException( "can't store files on the filesystem in directory " + filesDirectory, e );
} catch (IOException e) {
log.error( "can't store files on the filesystem", e );
throw new ConfigurationException( "can't store files on the filesystem in directory " + filesDirectory, e );
}
}
public byte[] retrieveBytes(Long definitionId, String fileName) {
byte[] bytes = null;
try {
// get the file from the filesystem
ByteArrayOutputStream out = new ByteArrayOutputStream();
String filePath = filesDirectory + definitionId + "/" + fileName;
FileInputStream in = new FileInputStream( filePath );
IoUtil.transfer( in, out );
bytes = out.toByteArray();
} catch (FileNotFoundException e) {
throw new ConfigurationException( "can't read files on the filesystem in directory " + filesDirectory, e );
} catch (IOException e) {
throw new ConfigurationException( "can't read files on the filesystem in directory " + filesDirectory, e );
}
return bytes;
}
private static Log log = LogFactory.getLog(FileSystemFileMgr.class);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -