Skip to content
Reference > Classes

Binary

Definition

Binary var = .... ;

Extends

Extended By

None

Description

Binary stream of bytes

Method Summary

Owner Name Return Type Description
Binary constructor(text) Binary Creates a UTF binary representation of a string. If the string is null, creates an empty Binary.
Binary constructor(text, charset) Binary Creates a UTF binary representation of a string with the supplied charset (e.g, UTF-8). If string is null, creates an empty Binary
Object getClassName() String Returns the string name of this object's class type.
Binary getLength() Integer Returns number of bytes in this Binary object.
Binary toBase64() String Returns the base64 encoding of this Binary object.
Object toJson() String Returns a string of a json representation of this object.
Binary toText() String Tries to return the text representation of the supplied Binary object using the default Java charset (UTF-8).
Binary toText(charset) String Tries to return the text version of the binary using the provided Java charset.

Method Definitions


constructor(text)

Binary binary = new Binary(String text)

Description

Creates a UTF binary representation of a string. If the string is null, creates an empty Binary.

Parameter Definition

Name Type Description
text String  string value to convert to binary

Example 1

1
2
3
Binary b = new Binary("abc 123");

// b; = 7 bytes

constructor(text,charset)

Binary binary = new Binary(String text, String charset)

Description

Creates a UTF binary representation of a string with the supplied charset (e.g, UTF-8). If string is null, creates an empty Binary

Parameter Definition

Name Type Description
text String  string value to convert to binary
charset String  charset to encode with

Example 1

1
2
3
Binary b = new Binary("abc 123","UTF-8");

// b; = 7 bytes

getClassName()

String Object::getClassName()

Description

Returns the string name of this object's class type.

Example 2

1
2
3
4
Binary b = new Binary("abc 123");
b.getClassName();

// b.getClassName() = Binary

getLength()

Integer Binary::getLength()

Description

Returns number of bytes in this Binary object.

Example 1

1
2
3
4
Binary b = new Binary("abc 123");
b.getLength();

// b.getLength(); = 7

toBase64()

String Binary::toBase64()

Description

Returns the base64 encoding of this Binary object.

Example 1

1
2
3
4
Binary b = new Binary("abc 123");
b.toBase64();

// b.toBase64(); = YWJjIDEyMw==

toJson()

String Object::toJson()

Description

Returns a string of a json representation of this object.

Example 2

1
2
3
4
Binary b = new Binary("abc 123");
b.toJson();

// b.toJson() = "7 bytes"

toText()

String Binary::toText()

Description

Tries to return the text representation of the supplied Binary object using the default Java charset (UTF-8).

Example 1

1
2
3
4
Binary b = new Binary("abc 123");
b.toText();

// b.toText(); = abc 123

Example 2

1
2
3
4
Binary b = new Binary("abc 123", "UTF-16");
b.toText();

// b.toText(); = ��abc 123

Here the return value renders incorrectly since UTF-8 cannot parse UTF-16 correctly.


toText(charset)

String Binary::toText(String charset)

Description

Tries to return the text version of the binary using the provided Java charset.

Parameter Definition

Name Type Description
charset String  charset to decode binary with

Example 1

1
2
3
4
Binary b = new Binary("abc 123");
b.toText("UTF-16");

// b.toText("UTF-16"); = 慢挠ㄲ�

Here the return value renders incorrectly since UTF-16 cannot parse UTF-8 correctly.

Example 2

1
2
3
4
Binary b = new Binary("abc 123", "UTF-16");
b.toText("UTF-16");

// b.toText("UTF-16"); = abc 123