diff --git a/java/src/main/java/io/nayuki/qrcodegen/MakeBytesToSegment.java b/java/src/main/java/io/nayuki/qrcodegen/MakeBytesToSegment.java new file mode 100644 index 0000000..807d574 --- /dev/null +++ b/java/src/main/java/io/nayuki/qrcodegen/MakeBytesToSegment.java @@ -0,0 +1,36 @@ +import java.nio.charset.StandardCharsets; +import java.util.Objects; + +public class MakeBytesToSegment implements MakeSegment { + + /** + * 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 ({@code + * s.getBytes(StandardCharsets.UTF_8)}) and encoded as a byte mode segment.

+ * @param data the binary data (not {@code null}) + * @return a segment (not {@code null}) containing the data + * @throws NullPointerException if the array is {@code null} + */ + public QrSegment excute(String text) { + byte[] data = text.getBytes(StandardCharsets.UTF_8)); + + Objects.requireNonNull(data); + BitBuffer bitBuffer = new BitBuffer(); + for (byte bits : data) + changeByteToSegment(bitBuffer, bits); + return new QrSegment(QrSegment.Mode.BYTE, data.length, bitBuffer); + } + + public QrSegment excuteForBytedata(byte[] data) { + Objects.requireNonNull(data); + BitBuffer bitBuffer = new BitBuffer(); + for (byte bits : data) + changeByteToSegment(bitBuffer, bits); + return new QrSegment(QrSegment.Mode.BYTE, data.length, bitBuffer); + } + + public static void changeByteToSegment(BitBuffer bitBuffer, byte bits) { + bitBuffer.appendBits(bits & 0xFF, 8); + } +} diff --git a/java/src/main/java/io/nayuki/qrcodegen/QrSegment.java b/java/src/main/java/io/nayuki/qrcodegen/QrSegment.java index 92c8746..67cce84 100644 --- a/java/src/main/java/io/nayuki/qrcodegen/QrSegment.java +++ b/java/src/main/java/io/nayuki/qrcodegen/QrSegment.java @@ -49,28 +49,6 @@ public final class QrSegment { /*---- Static factory functions (mid level) ----*/ - /** - * 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 ({@code - * s.getBytes(StandardCharsets.UTF_8)}) and encoded as a byte mode segment.

- * @param data the binary data (not {@code null}) - * @return a segment (not {@code null}) containing the data - * @throws NullPointerException if the array is {@code null} - */ - public static QrSegment makeBytes(byte[] data) { - Objects.requireNonNull(data); - BitBuffer bitBuffer = new BitBuffer(); - for (byte one_byte : data) - changeByteToSegment(bitBuffer, one_byte); - return new QrSegment(QrSegment.Mode.BYTE, data.length, bitBuffer); - } - - public static void changeByteToSegment(BitBuffer bitBuffer, byte one_byte) { - bitBuffer.appendBits(one_byte & 0xFF, 8); - } - - /** * Returns a segment representing the specified string of decimal digits encoded in numeric mode. * @param digits the text (not {@code null}), with only digits from 0 to 9 allowed