Class QrSegment
The mid-level way to create a segment is to take the payload data and call a static factory function such
as makeNumeric(CharSequence). The low-level way to create a segment is to custom-make the
bit buffer and call the constructor with appropriate
values.
This segment class imposes no length restrictions, but QR Codes have restrictions. Even in the most
favorable conditions, a QR Code can only hold 7089 characters of data. Any segment longer than this is
meaningless for the purpose of generating QR Codes. This class can represent kanji mode segments, but
provides no help in encoding them - see
invalid reference
QrSegmentAdvanced
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDescribes how a segment's data bits are interpreted. -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal QrSegment.ModeThe mode indicator of this segment.final intThe length of this segment's unencoded data. -
Constructor Summary
ConstructorsConstructorDescriptionQrSegment(QrSegment.Mode md, int numCh, BitBuffer data) Constructs a QR Code segment with the specified attributes and data. -
Method Summary
Modifier and TypeMethodDescriptiongetData()Returns the data bits of this segment.static booleanisAlphanumeric(CharSequence text) Tests whether the specified string can be encoded as a segment in alphanumeric mode.static booleanisNumeric(CharSequence text) Tests whether the specified string can be encoded as a segment in numeric mode.static QrSegmentmakeAlphanumeric(CharSequence text) Returns a segment representing the specified text string encoded in alphanumeric mode.static QrSegmentmakeBytes(byte[] data) Returns a segment representing the specified binary data encoded in byte mode.static QrSegmentmakeEci(int assignVal) Returns a segment representing an Extended Channel Interpretation (ECI) designator with the specified assignment value.static QrSegmentmakeNumeric(CharSequence digits) Returns a segment representing the specified string of decimal digits encoded in numeric mode.makeSegments(CharSequence text) Returns a list of zero or more segments to represent the specified Unicode text string.
-
Field Details
-
mode
The mode indicator of this segment. Notnull. -
numChars
public final int numCharsThe length of this segment's unencoded data. Measured in characters for numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode. Always zero or positive. Not the same as the data's bit length.
-
-
Constructor Details
-
QrSegment
Constructs a QR Code segment with the specified attributes and data. The character count (numCh) must agree with the mode and the bit buffer length, but the constraint isn't checked. The specified bit buffer is cloned and stored.- Parameters:
md- the mode (notnull)numCh- the data length in characters or bytes, which is non-negativedata- the data bits (notnull)- Throws:
NullPointerException- if the mode or data isnullIllegalArgumentException- if the character count is negative
-
-
Method Details
-
makeBytes
Returns a segment representing the specified binary data encoded in byte mode. All input byte arrays are acceptable.Any text string can be converted to UTF-8 bytes (
s.getBytes(StandardCharsets.UTF_8)) and encoded as a byte mode segment.- Parameters:
data- the binary data (notnull)- Returns:
- a segment (not
null) containing the data - Throws:
NullPointerException- if the array isnull
-
makeNumeric
Returns a segment representing the specified string of decimal digits encoded in numeric mode.- Parameters:
digits- the text (notnull), with only digits from 0 to 9 allowed- Returns:
- a segment (not
null) containing the text - Throws:
NullPointerException- if the string isnullIllegalArgumentException- if the string contains non-digit characters
-
makeAlphanumeric
Returns a segment representing the specified text string encoded in alphanumeric mode. The characters allowed are: 0 to 9, A to Z (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.- Parameters:
value- the text (notnull), with only certain characters allowed- Returns:
- a segment (not
null) containing the text - Throws:
NullPointerException- if the string isnullIllegalArgumentException- if the string contains non-encodable characters
-
makeSegments
Returns a list of zero or more segments to represent the specified Unicode text string. The result may use various segment modes and switch modes to optimize the length of the bit stream.- Parameters:
value- the text to be encoded, which can be any Unicode string- Returns:
- a new mutable list (not
null) of segments (notnull) containing the text - Throws:
NullPointerException- if the text isnull
-
makeEci
Returns a segment representing an Extended Channel Interpretation (ECI) designator with the specified assignment value.- Parameters:
assignVal- the ECI assignment number (see the AIM ECI specification)- Returns:
- a segment (not
null) containing the data - Throws:
IllegalArgumentException- if the value is outside the range [0, 106)
-
isNumeric
Tests whether the specified string can be encoded as a segment in numeric mode. A string is encodable iff each character is in the range 0 to 9.- Parameters:
value- the string to test for encodability (notnull)- Returns:
trueiff each character is in the range 0 to 9.- Throws:
NullPointerException- if the string isnull- See Also:
-
isAlphanumeric
Tests whether the specified string can be encoded as a segment in alphanumeric mode. A string is encodable iff each character is in the following set: 0 to 9, A to Z (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.- Parameters:
value- the string to test for encodability (notnull)- Returns:
trueiff each character is in the alphanumeric mode character set- Throws:
NullPointerException- if the string isnull- See Also:
-
getData
Returns the data bits of this segment.- Returns:
- a new copy of the data bits (not
null)
-