1. Move method, rename

2. bitBufferToCodewords in QrCode
3.Feature envy. It calls only BitBuffer method. Moved it to BitBuffer
and renamed it.
pull/90/head
gerzees 5 years ago
parent 4ddf3a02c7
commit 889fc7d9d5

@ -128,9 +128,18 @@ public final class BitBuffer implements Cloneable {
// Pad with alternating bytes until data capacity is reached // Pad with alternating bytes until data capacity is reached
void addPad(int dataCapacityBits) { public void addPad(int dataCapacityBits) {
for (int padByte = 0xEC; bitLength() < dataCapacityBits; padByte ^= 0xEC ^ 0x11) for (int padByte = 0xEC; bitLength() < dataCapacityBits; padByte ^= 0xEC ^ 0x11)
appendBits(padByte, 8); appendBits(padByte, 8);
} }
// Pack bits into bytes in big endian
public byte[] toCodewords() {
byte[] dataCodewords = new byte[bitLength() / 8];
for (int i = 0; i < bitLength(); i++)
dataCodewords[i >>> 3] |= getBit(i) << (7 - (i & 7));
return dataCodewords;
}
} }

@ -175,7 +175,7 @@ public final class QrCode {
bitBuffer.addPad(dataCapacityBits); bitBuffer.addPad(dataCapacityBits);
byte[] dataCodewords = bitBufferToCodewords(bitBuffer); byte[] dataCodewords = bitBuffer.toCodewords();
// Create the QR Code object // Create the QR Code object
return new QrCode(version, errorCorrectionLevel, dataCodewords, mask); return new QrCode(version, errorCorrectionLevel, dataCodewords, mask);
@ -183,15 +183,7 @@ public final class QrCode {
/*---- Private helper methods for encodeSegments ----*/ /*---- Private helper methods for encodeSegments ----*/
// Pack bits into bytes in big endian
private static byte[] bitBufferToCodewords(BitBuffer bitBuffer) {
byte[] dataCodewords = new byte[bitBuffer.bitLength() / 8];
for (int i = 0; i < bitBuffer.bitLength(); i++)
dataCodewords[i >>> 3] |= bitBuffer.getBit(i) << (7 - (i & 7));
return dataCodewords;
}
// Add terminator and pad up to a byte if applicable // Add terminator and pad up to a byte if applicable
private static void addTerminator(BitBuffer bitBuffer, int dataCapacityBits) { private static void addTerminator(BitBuffer bitBuffer, int dataCapacityBits) {
bitBuffer.appendBits(0, Math.min(4, dataCapacityBits - bitBuffer.bitLength())); bitBuffer.appendBits(0, Math.min(4, dataCapacityBits - bitBuffer.bitLength()));

Loading…
Cancel
Save