-
Notifications
You must be signed in to change notification settings - Fork 33
/
IfsWriteStream.java
42 lines (33 loc) · 1.19 KB
/
IfsWriteStream.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package nodejt400;
import java.sql.Connection;
import com.ibm.as400.access.AS400;
import com.ibm.as400.access.AS400JDBCConnectionHandle;
import com.ibm.as400.access.IFSFile;
import com.ibm.as400.access.IFSFileOutputStream;
public class IfsWriteStream {
private ConnectionProvider connectionProvider;
private final Connection connection;
private final IFSFileOutputStream fos;
public IfsWriteStream(ConnectionProvider connectionProvider, String folderPath, String fileName, boolean append)
throws Exception {
this.connectionProvider = connectionProvider;
connection = connectionProvider.getConnection();
AS400JDBCConnectionHandle handle = (AS400JDBCConnectionHandle) connection;
AS400 as400 = handle.getSystem();
IFSFile folder = new IFSFile(as400,folderPath);
if (!folder.exists()) {
folder.mkdirs();
}
IFSFile file = new IFSFile(as400, folder, fileName);
fos = new IFSFileOutputStream(file, IFSFileOutputStream.SHARE_ALL, append);
}
public void write(byte[] data) throws Exception {
fos.write(data);
fos.flush();
}
public void flush() throws Exception {
fos.flush();
fos.close();
this.connectionProvider.returnConnection(this.connection);
}
}