Skip to content

nolequen/idea-externalizable-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IntelliJ IDEA externalizable code generation plugin

JetBrains Plugins Codebeat

Despite that manual implementation of the Externalizable interface gives you complete control in reading and writing objects during Java serialization, it also requires attentiveness and additional work in support.

However if used correctly it can help to improve serialization process performance.

The plugin allows to generate externalizable code for Java classes. Easy and safe.

Installation

You may install the plugin following official guide or download it from JetBrains Plugin Repository.

Usage

After installation you can find Externalizable action in the Generate menu (Alt + Ins, by default).

For example our class is:

public class Example {
  private int intValue;
  private Integer boxedInteger;
  private Object object;

  /*...*/
}

The plugin will generate following code:

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

public class Example implements Externalizable {
  private int intValue;
  private Integer boxedInteger;
  private Object object;

  public Example() {
  }

  @Override
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    intValue = in.readInt();
    if (in.readBoolean()) {
      boxedInteger = in.readInt();
    }
    if (in.readBoolean()) {
      object = in.readObject();
    }
  }

  @Override
  public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(intValue);
    if (boxedInteger == null) {
      out.writeBoolean(false);
    } else {
      out.writeBoolean(true);
      out.writeInt(boxedInteger);
    }
    if (object == null) {
      out.writeBoolean(false);
    } else {
      out.writeBoolean(true);
      out.writeObject(object);
    }
  }
}

Benchmarks

...to be described