IFS write This is the end of the coding example.
IfsWrite.JS
var jt400 = require("node-jt400");
var express = require("express");
var iconv = require('iconv-lite');
var app = express();
var pool = jt400.pool({ host: '192.168.X.XXX', user: 'MYUSER', password: 'MYPASS' });
var server = app.listen(8888, function () {
console.log("curl http://localhost:" + server.address().port + '/~');
});
app.get("/ifsWrite", function (req, res, next) {
var sqlReadableStream = pool.createReadStream("select * from member");
var ifs = pool.ifs();
var writer = ifs.createWriteStream("/myIfsFolder/node-write.txt", { append: true });
var buffer = "";
sqlReadableStream.on("data", function (chunk) {
buffer += chunk;
});
sqlReadableStream.on('end', function () {
writer.write(iconv.encode(buffer, "UTF-8"));
writer.end();
res.send(iconv.encode(buffer, "UTF-8"));
});
});
I wrote the SQL result to IFS.
I returned the characters correctly to the console, but the characters were garbled in the IFS file.
The source to be modified is \ java \ src \ nodejt400 \ IfsWriteStream.java. On line 29 is the following code.
IfsWriteStream.java
fos = new IFSFileOutputStream(file, IFSFileOutputStream.SHARE_ALL, append);
Specify the code page. (This time UTF-8)
IfsWriteStream.java
fos = new IFSFileOutputStream(file, IFSFileOutputStream.SHARE_ALL, append, 1208);
If the build is successful, replace jt400wrap.jar and try again.
It would be nice if it could be parameterized, but I don't have that much knowledge yet ...
The poster does not take any responsibility for the source modification. Please do so at your own risk.
Added on December 28, 2017 I put the pre-built jt400wrap.jar in here.
Recommended Posts