I tried node-jt400 (IFS read)

IFS read Try to read the file (SJIS, UTF8, UTF16) created on IFS with the following Java code from Node.

IfsWrite.java


public class IfsWrite {

	public static void main(String[] args) {
			AS400 as400  = new AS400("192.168.X.XXX" ,"MYUSER" ,"MYPASS");
			final String BR = System.getProperty("line.separator");

			IFSFileOutputStream fileutf8;
			IFSFileOutputStream fileutf16;
			IFSFileOutputStream filesjis;
			try {
				String str1 = "Test string 1st line abc";
				String str2 = "Test string 2nd line";
				String str = str1 + BR + str2;

				byte[] utf8 = str.getBytes("UTF-8"); 
				byte[] utf16 = str.getBytes("UTF-16");
				byte[] sjis = str.getBytes(Charset.forName("Shift_JIS"));

				fileutf8 = new IFSFileOutputStream(as400, "/myIfsFolder/java-utf8.txt",IFSFileOutputStream.SHARE_ALL, true,1208);
				fileutf8.write(utf8);
				fileutf8.close();

				fileutf16 = new IFSFileOutputStream(as400, "/myIfsFolder/java-utf16.txt",IFSFileOutputStream.SHARE_ALL, true,1200);
				fileutf16.write(utf16);
				fileutf16.close();

				filesjis = new IFSFileOutputStream(as400, "/myIfsFolder/java-sjis.txt",IFSFileOutputStream.SHARE_ALL, true,932);
				filesjis.write(sjis);
				filesjis.close();

			} catch (AS400SecurityException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
	}
}

Since iconv-lite is used for character code conversion, please install it before executing.

npm install iconv-lite

IfsRaed.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("/ifsReadSjis", function (req, res, next) {
  const ifs = pool.ifs();
  let ifsReadableStream = ifs.createReadStream("/myIfsFolder/java-sjis.txt").pipe(iconv.decodeStream("Shift_JIS"));
  let buffer = "";
  ifsReadableStream.on("data", (chunk) => {
    buffer += chunk;
  });
  ifsReadableStream.on("end", function () {
    res.send(buffer);
  });
});

app.get("/ifsReadUtf8", function (req, res, next) {
  const ifs = pool.ifs();
  let ifsReadableStream = ifs.createReadStream("/myIfsFolder/java-utf8.txt").pipe(iconv.decodeStream("UTF-8"));
  let buffer = "";
  ifsReadableStream.on("data", (chunk) => {
    buffer += chunk;
  });
  ifsReadableStream.on("end", function () {
    res.send(buffer);
  });
});

app.get("/ifsReadUtf16", function (req, res, next) {
  const ifs = pool.ifs();
  let ifsReadableStream = ifs.createReadStream("/myIfsFolder/java-utf16.txt").pipe(iconv.decodeStream("UTF-16"));
  let buffer = "";
  ifsReadableStream.on("data", (chunk) => {
    buffer += chunk;
  });
  ifsReadableStream.on("end", function () {
    res.send(buffer);
  });
});

This is the execution result.

nodejt25.png

Recommended Posts

I tried node-jt400 (IFS read)
I tried node-jt400 (IFS write)
I tried node-jt400 (Programs)
I tried node-jt400 (execute)
I tried node-jt400 (Transactions)
I tried node-jt400 (Environment construction)
I tried node-jt400 (SQL Update)
I tried node-jt400 (SQL query)
I tried tomcat
I tried youtubeDataApi.
I tried refactoring ①
I tried FizzBuzz.
I tried JHipster 5.1
[I tried] Spring tutorial
I tried running Autoware
I tried using Gson
I tried using TestNG
I tried Spring Batch
I tried using Galasa
I tried to read and output CSV with Outsystems
I can read it! RxJava
I tried DI with Ruby
I tried using azure cloud-init
I tried Spring State machine
I tried Rails beginner [Chapter 1]
I tried the Docker tutorial!
I tried using Apache Wicket
I tried the VueJS tutorial!
I read module-info.java in java.base
I tried using Java REPL
I tried source code analysis
I tried the FizzBuzz problem
I tried putting XcodeGen + SwiftPM
I tried Rails beginner [Chapter 2]
I tried UPSERT with PostgreSQL.
I tried BIND with Docker
I tried to verify yum-cron
I tried Jets (ruby serverless)
I tried metaprogramming in Java
I tried using anakia + Jing now
I tried Angular tutorial + SpringBoot + PostgreSQL
I tried something called recursive search
I tried using Spring + Mybatis + DbUnit
I tried using JOOQ with Gradle
[K8s] I tried communication between pods!
I tried morphological analysis with MeCab
I tried a little digdag docker.run_options
I tried to summarize iOS 14 support
I read the source of Integer
I tried to interact with Java
I tried to explain the method
I tried putting Domino11 in CentOS7
I read the source of Long
I tried the Java framework "Quarkus"
[Rails] I tried deleting the application
I tried using Java8 Stream API
I tried Java's micro-benchmark tool JMH
I tried using JWT in Java
I tried GraphQL with Spring Boot
I tried to summarize Java learning (1)
I read the source of Short