This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-imaging.git
commit 728592d42cd4d1df607c925618a601e6ee2320b9 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Tue May 16 10:19:06 2023 -0400 new ByteArrayInputStream does not need to operate on a copy of the byte array - Javadoc - One less magic number - Move static out of loop - Remove useless paren - Fix broken @see tag --- .../commons/imaging/formats/png/chunks/PngChunk.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/apache/commons/imaging/formats/png/chunks/PngChunk.java b/src/main/java/org/apache/commons/imaging/formats/png/chunks/PngChunk.java index 512c31f3..5fc95e2e 100644 --- a/src/main/java/org/apache/commons/imaging/formats/png/chunks/PngChunk.java +++ b/src/main/java/org/apache/commons/imaging/formats/png/chunks/PngChunk.java @@ -25,9 +25,10 @@ import org.apache.commons.imaging.common.BinaryFileParser; * A PNG image is composed of several chunks. This is the base class for the chunks, * used by the parser. * - * @see <a href="https://en.wikipedia.org/wiki/Portable_Network_Graphics#%22Chunks%22_within_the_file>Portable_Network_Graphics</a> + * @see <a href="https://en.wikipedia.org/wiki/Portable_Network_Graphics#%22Chunks%22_within_the_file">Portable_Network_Graphics</a> */ public class PngChunk extends BinaryFileParser { + public final int length; public final int chunkType; public final int crc; @@ -56,11 +57,11 @@ public class PngChunk extends BinaryFileParser { propertyBits = new boolean[4]; int shift = 24; - for (int i = 0; i < 4; i++) { + final int theMask = 1 << 5; + for (int i = 0; i < propertyBits.length; i++) { final int theByte = 0xff & (chunkType >> shift); shift -= 8; - final int theMask = 1 << 5; - propertyBits[i] = ((theByte & theMask) > 0); + propertyBits[i] = (theByte & theMask) > 0; } ancillary = propertyBits[0]; @@ -70,7 +71,8 @@ public class PngChunk extends BinaryFileParser { } /** - * Return a copy of the chunk bytes. + * Gets a copy of the chunk bytes. + * * @return the chunk bytes */ public byte[] getBytes() { @@ -78,14 +80,14 @@ public class PngChunk extends BinaryFileParser { } /** - * Create and return a {@link ByteArrayInputStream} for the chunk bytes. + * Gets a new {@link ByteArrayInputStream} for the chunk bytes. * * <p>The caller is responsible for closing the resource.</p> * * @return a ByteArrayInputStream for the chunk bytes */ protected ByteArrayInputStream getDataStream() { - return new ByteArrayInputStream(getBytes()); + return new ByteArrayInputStream(bytes); } /**