dw.util
Class Bytes
Object
dw.util.Bytes
A simple immutable class representing an array of bytes, used for working with binary data in a scripting context.

It acts as a view to ArrayBuffer. The buffer can be accessed through asUint8Array(). Limitation: The size of the resulting byte representation is limited by the quota api.jsArrayBufferSize that is defining the max size for a ArrayBuffer.

Constants
MAX_BYTES  :  Number = 10240L
The maximum number of bytes that a Bytes object can represent == 10KB
Deprecated:
No longer used by the Bytes class.
Properties
length  :  Number  (Read Only)
The number of bytes represented by this object.
Constructor Summary
Bytes(arrayBufferOrView : Object)
Construct a Bytes object from the given ArrayBuffer or view.
Bytes(string : String)
Construct a Bytes object from the given string using the default encoding.
Bytes(string : String, encoding : String)
Construct a Bytes object from the given string using the given encoding.
Method Summary
asUint8Array() : Object
Returns a Uint8Array based on the ArrayBuffer used for this Bytes object.
byteAt(index : Number) : Number
Returns the value of the byte at position index as an integer.
bytesAt(index : Number, length : Number) : Bytes
Return a new Bytes object containing the subsequence of this object's bytes specified by the index and length parameters.
getLength() : Number
Returns the number of bytes represented by this object.
intAt(index : Number) : Number
Absolute get method for reading a signed integer value (32 bit) in network byte order(= big endian).
reverse() : Bytes
Return a new Bytes object which has the same bytes as this one in reverse order.
shortAt(index : Number) : Number
Absolute get method for reading a signed short value (16 bit) in network byte order(= big endian).
toString() : String
Constructs a new String by decoding this array of bytes using the default encoding.
toString(encoding : String) : String
Constructs a new String by decoding this array of bytes using the specified encoding.
Salesforce Commerce Cloud Courses
Salesforce B2C Commerce Developer - Certification Tests
Why risk failing the SFCC exam? Get 180 real questions, killer content, and everything you need to crush the Salesforce B2C Commerce Developer certification.

Becoming a Salesforce B2C Commerce Developer is your ticket to higher salaries, better job opportunities, and the credibility to stand out from the competition. But let's be honestβ€”passing the certification exam isn't easy. That's where we come in.
Salesforce Javascript Developer I - Certification Tests
Not just another prep courseβ€”this is your shortcut to passing. Master JavaScript for Salesforce and go from 'hoping to pass' to knowing you will. Ready to start?

This isn't just another prep courseβ€”it's your shortcut to mastering the skills and confidence you need to pass. With multiple practice tests covering every section and a final exam simulation designed to mirror the real thing, you'll feel like you've already aced it before test day.
Salesforce B2C Commerce Architect - Certification Tests
Think the Developer exam was hard? Welcome to the next level.

The Salesforce B2C Commerce Architect certification is a whole different gameβ€”complex solutions, elevated difficulty, and skills that set you apart in the eCommerce industry. That's why we're including 11 downloadable PDF guides, packed with best practices and strategies to help you prepare for the exam and build confidence in every topic.
Constructor Detail
Bytes
public Bytes(arrayBufferOrView : Object)
Construct a Bytes object from the given ArrayBuffer or view. The bytes object also acts as a view on the underlying ArrayBuffer. If a view is given that makes only a part of the storage array visible then this Bytes object will also make only the same part visible. The storage data is not copied.
API Versioned:
From version 21.2.
Parameters:
arrayBufferOrView - An ArrayBuffer or view to a buffer that is the storage.

Bytes
public Bytes(string : String)
Construct a Bytes object from the given string using the default encoding. Convenience for Bytes( string, "UTF-8" ).
Parameters:
string - The string to encode into a Bytes object, must not be null.
Throws:
IllegalArgumentException - If the encoded byte sequence exceeds the maximum number of bytes.

Bytes
public Bytes(string : String, encoding : String)
Construct a Bytes object from the given string using the given encoding. This method always replaces malformed input and unmappable character sequences with encoding defaults.
Parameters:
string - The string to encode into a Bytes object, must not be null.
encoding - The name of a supported encoding, or null in which case the default encoding (UTF-8) is used.
Throws:
IllegalArgumentException - If the named encoding is not supported or if the encoded byte sequence exceeds the maximum number of bytes.

Method Detail
asUint8Array
asUint8Array() : Object
Returns a Uint8Array based on the ArrayBuffer used for this Bytes object. Changes to the returned ArrayBuffer will be visible in the Bytes object.
API Versioned:
From version 21.2.
Returns:
A newly created Uint8Array based on the existing ArrayBuffer.

byteAt
byteAt(index : Number) : Number
Returns the value of the byte at position index as an integer. If index is out of range an exception is thrown. The byte is interpreted as signed and so the value returned will always be between -128 and +127.
Parameters:
index - The index of the byte.
Returns:
The byte value at the specified index.
Throws:
IndexOutOfBoundsException - If the index argument is negative or not less than the length of this byte array.

bytesAt
bytesAt(index : Number, length : Number) : Bytes
Return a new Bytes object containing the subsequence of this object's bytes specified by the index and length parameters. The returned object is a new view onto the same data, no data is copied.
Parameters:
index - The initial index for the new view, inclusive.
length - The number of bytes visible in the new view.
Returns:
a new Bytes object representing a subsequence of this Bytes object.
Throws:
ArrayIndexOutOfBoundsException - If index < 0 or index > getLength() or index + length > getLength()
IllegalArgumentException - If length < 0

getLength
getLength() : Number
Returns the number of bytes represented by this object.
Returns:
The number of bytes.

intAt
intAt(index : Number) : Number
Absolute get method for reading a signed integer value (32 bit) in network byte order(= big endian).
Parameters:
index - The byte index at which to read the number.
Returns:
The read number.
Throws:
IndexOutOfBoundsException - If index is negative or not smaller than the number of bytes minus three.

reverse
reverse() : Bytes
Return a new Bytes object which has the same bytes as this one in reverse order.
Returns:
a new Bytes object representing the reverse of this Bytes object.

shortAt
shortAt(index : Number) : Number
Absolute get method for reading a signed short value (16 bit) in network byte order(= big endian).
Parameters:
index - The byte index at which to read the number.
Returns:
The read number.
Throws:
IndexOutOfBoundsException - If index is negative or not smaller than the number of bytes minus one.

toString
toString() : String
Constructs a new String by decoding this array of bytes using the default encoding. Convenience for toString( "UTF-8" ). Limitation: The method is protected by the quota api.jsStringLength that prevents creation of too long strings.
Returns:
A String representing the decoded array of bytes.

toString
toString(encoding : String) : String
Constructs a new String by decoding this array of bytes using the specified encoding. Limitation: The method is protected by the quota api.jsStringLength that prevents creation of too long strings.
Parameters:
encoding - The name of a supported encoding.
Returns:
A String representing the decoded array of bytes.
Throws:
IllegalArgumentException - If the named encoding is not supported.

β™₯
Notifications pending to read