npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

java.io

v2.4.0

Published

Object Serialization Stream Protocol javascript implement

Downloads

996

Readme

java.io

NPM version build status codecov David

A node implement of "java.io.InputObjectStream.readObject()" and "java.io.OutputObjectStream.writeObject()".

Protocol

Install

$ npm install java.io --save

Usage

1. readObject()

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 }

2. writeObject(obj)

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);

3. OutputObjectStream.normalize(obj, type)

A convenient way to convert ordinary JavaScript object to object of standard format with whole info.

  • params
    • obj: accept all primitive value or primitive array and map
    • type: string | boolean | int | short | long | char | byte | float | double |
  • return: normalized object
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')

4. addObject()

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:

Data structure

{
  // 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
  }
}

Some more examples

Incompatible between 1.x and 2.x

  • decode java [B to new Buffer([1, 2, 3]) not [1, 2, 3] #10

License

MIT