Skip to content

Latest commit

 

History

History
105 lines (77 loc) · 1.88 KB

bytes.md

File metadata and controls

105 lines (77 loc) · 1.88 KB

byte manipulating utilities

Bytes

Converts byte array to stream

  byte[] data = ...
  InputStream is = Bytes.asStream(data);

Converts stream to byte array

  InputStream is = ...
  byte[] data = Bytes.fromStream(is);

Transfer byte array to stream

  byte[] data = ...
  OutputStream os = ...
  Bytes.toStream(data, os);

Transfer stream to stream

  InputStream is = ...
  OutputStream os = ...
  int size = Bytes.transfer(is, os);

Base64

Simple base64 encoder

  byte[] data = ...
  String text = Base64.encode(data);
  byte[] newdata = Base64.decode(text);

Any64

Simple bytes to text encoder baset on Base64 but uses different charset. It produce encoded text with only characters from given charset (no '=' padding)

  byte[] charset = new char[] {'a', 'b', ..... 64 unique chars};
  byte[] data = ...
  Any64 encoder = Any64.instance(charset);
  String text = encoder.encode(data);
  byte[] newdata = encoder.decode(text);

If you are satisfied with Base64 charset and you want to replace only plus and slash characters. (Usually only those characters are problematic.)

  byte[] data = ...
  Any64 encoder = Any64.instance('?', '!');
  String text = encoder.encode(data);
  byte[] newdata = encoder.decode(text);

Hex

Simple Hex encoder

  byte[] data = ...
  String text = Hex.encode(data);
  byte[] newdata = Hex.decode(text);

Unicode

Simple unicode encoder

  String data = ...
  String text = Unicode.escape(data, false);
  String newdata = Unicode.unescape(text);

Html

Simple html escaping encoder

  String data = ...
  String text = Html.escapeSimple(data);
  String newdata = Html.unescape(text);

HtmlEraser

Remove html tags from given text. (From "

foo

" generate "foo")

  String html = ...
  String text = HtmlEraser.of(html).erase();