KandarpInCanada commented on code in PR #467:
URL: https://github.com/apache/commons-imaging/pull/467#discussion_r1861456868
##########
src/main/java/org/apache/commons/imaging/common/BigEndianBinaryOutputStream.java:
##########
@@ -22,29 +22,38 @@
final class BigEndianBinaryOutputStream extends BinaryOutputStream {
+ private static final int MASK_8_BITS = 0xff; // Magic number 0xff
explained
+ private static final int BYTE_SHIFT_8 = 8; // Magic number 8 explained
+ private static final int BYTE_SHIFT_16 = 16; // Magic number 16 explained
+ private static final int BYTE_SHIFT_24 = 24; // Magic number 24 explained
+
BigEndianBinaryOutputStream(final OutputStream os) {
super(os);
}
@Override
public void write2Bytes(final int value) throws IOException {
- write(0xff & value >> 8);
- write(0xff & value);
+ writeByteWithShift(value, BYTE_SHIFT_8); // Extracted and reused logic
+ writeByteWithShift(value, 0);
}
@Override
public void write3Bytes(final int value) throws IOException {
- write(0xff & value >> 16);
- write(0xff & value >> 8);
- write(0xff & value);
+ writeByteWithShift(value, BYTE_SHIFT_16);
+ writeByteWithShift(value, BYTE_SHIFT_8);
+ writeByteWithShift(value, 0);
}
@Override
public void write4Bytes(final int value) throws IOException {
- write(0xff & value >> 24);
- write(0xff & value >> 16);
- write(0xff & value >> 8);
- write(0xff & value);
+ writeByteWithShift(value, BYTE_SHIFT_24);
+ writeByteWithShift(value, BYTE_SHIFT_16);
+ writeByteWithShift(value, BYTE_SHIFT_8);
+ writeByteWithShift(value, 0);
}
-}
+ // Extracted method to remove duplication
+ private void writeByteWithShift(final int value, final int shift) throws
IOException {
+ write(MASK_8_BITS & (value >> shift));
+ }
+}
Review Comment:
Okay I will Remove this Blank Line
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]