
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
A node implement of "java.io.InputObjectStream.readObject()" and "java.io.OutputObjectStream.writeObject()".
$ npm install java.io --save
var fs = require('fs');
var io = require('java.io');
var InputObjectStream = io.InputObjectStream;
var OutputObjectStream = io.OutputObjectStream;
// Read object and return whole info
var buf = fs.readFileSync('./test/fixtures/out/int/1024.bin');
var in = new InputObjectStream(buf, true);
var obj = in.readObject();
// Read object but return value only
var buf2 = fs.readFileSync('./test/fixtures/out/int/1024.bin');
var in2 = new InputObjectStream(buf);
var obj2 = in.readObject();
obj
should be:
{
'$' : {
value : 1024
},
'$class' : {
name : 'java.lang.Integer',
serialVersionUID : '1360826667806852920',
flags : 2,
fields : [{
type : 'I',
name : 'value'
}],
superClass : {
name : 'java.lang.Number',
serialVersionUID : '-8742448824652078965',
flags : 2,
fields : [],
superClass : null
}
}
}
obj2
should be:
1024
if you only care about the first object from input stream, you could write the code briefly:
var buf3 = fs.readFileSync('./test/fixtures/out/map/boolean.bin');
var obj3 = InputObjectStream.readObject(buf);
then obj3
should be:
{ 'true': true, 'false': false }
var outputObjectStream = new OutputObjectStream();
// 1. Passed in argument must contains the whole info
// 2. Every time calling the writeObject function
// will return the buf had written in
var buf = outputObjectStream.writeObject(obj);
A brief style is also OK:
OutputObjectStream.writeObject(obj);
A convenient way to convert ordinary JavaScript object to object of standard format with whole info.
var outputObjectStream = new OutputObjectStream();
var normalizedObj = OutputObjectStream.normalize(true);
var buf = outputObjectStream.writeObject(normalizedObj);
normalize(null)
normalize('string')
normalize(true)
normalize(1) // quals to normalize(1, 'int')
normalize(-123456, long)
normalize([ true, false, false, false ], 'boolean')
normalize( {'true': true, 'false': false}, 'boolean')
If a class has writeObject/readObject methods, you need to implement the corresponding methods, and add them via addObject() before read or write the object.
var io = require('java.io');
io.addObject({{className}}, {{class}});
Builtin classes:
{
// if a object has it's own readObject/writeObject method
// save it's special value here
'_$': ...,
// value of object
'$': ...,
// class description
'$class': {
name: 'className',
serialVersionUID: 'SVUID',
flags: flags,
fields:
[ { type: 'F', name: 'primitiveProperty' },
{ type: 'L', name: 'objProperty', classname: 'Ljava/lang/String;' }],
superClass: parentClassDescriptionOrNull
}
}
[B
to new Buffer([1, 2, 3])
not [1, 2, 3]
#10FAQs
Object Serialization Stream Protocol javascript implement
We found that java.io demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.