From 6ca83c0d2f10b4b589aeb6814522d7b99f774bbb Mon Sep 17 00:00:00 2001 From: amosshi Date: Thu, 7 Nov 2019 23:37:27 -0800 Subject: [PATCH] #4 Spotbugs --- .../commonlib/core/BytesTool.java | 77 +++++++++++-------- .../core/FileComponenPlaceHolder.java | 5 +- FormatCLASS/pom.xml | 6 -- .../format/classfile/Opcode.java | 18 ++--- .../classfile/attribute/AttributeCode.java | 2 +- .../attribute/AttributeUnrecognized.java | 2 +- .../freeinternals/format/jpeg/FileData.java | 3 +- .../org/freeinternals/format/jpeg/Marker.java | 12 +-- .../freeinternals/format/jpeg/MarkerCode.java | 24 +++--- .../format/jpeg/Marker_APP13.java | 14 ++-- .../freeinternals/format/jpeg/Marker_DRI.java | 2 +- .../format/jpeg/Marker_SOFnn.java | 2 +- .../freeinternals/format/jpeg/Marker_SOS.java | 2 +- .../format/jpeg/icc/ICCProfile.java | 2 +- .../format/jpeg/icc/TagData.java | 5 +- .../format/jpeg/icc/dateTimeNumber.java | 2 + .../format/jpeg/icc/s15Fixed16Number.java | 4 +- .../format/jpeg/ps/IRB_8BIM.java | 5 +- .../freeinternals/format/jpeg/tiff/IFD.java | 3 +- .../format/jpeg/tiff/IFDGroup.java | 3 +- .../jpeg/tiff/IFD_829A_ExposureTime.java | 4 +- .../format/jpeg/tiff/IFD_829D_FNumber.java | 4 +- .../format/jpeg/tiff/IFD_8769_Exif.java | 17 ++-- .../jpeg/tiff/IFD_8822_ExposureProgram.java | 2 +- .../format/jpeg/tiff/IFD_8825_GPS.java | 3 +- .../jpeg/tiff/IFD_A005_Interoperability.java | 3 +- .../format/jpeg/tiff/IFD_A302_CFAPattern.java | 6 +- .../jpeg/tiff/IFD_A401_CustomRendered.java | 4 +- .../jpeg/tiff/IFD_A402_ExposureMode.java | 4 +- .../jpeg/tiff/IFD_A403_WhiteBalance.java | 4 +- .../jpeg/tiff/IFD_A404_DigitalZoomRatio.java | 4 +- .../tiff/IFD_A405_FocalLengthIn35mmFilm.java | 4 +- .../jpeg/tiff/IFD_A406_SceneCaptureType.java | 4 +- .../jpeg/tiff/IFD_A407_GainControl.java | 4 +- .../format/jpeg/tiff/IFD_A408_Contrast.java | 4 +- .../format/jpeg/tiff/IFD_A409_Saturation.java | 4 +- .../format/jpeg/tiff/IFD_A40A_Sharpness.java | 4 +- .../tiff/IFD_A40C_SubjectDistanceRange.java | 4 +- .../format/jpeg/tiff/IFD_LONG_Pointer.java | 4 +- .../format/jpeg/tiff/IFD_RATIONAL.java | 2 +- .../format/jpeg/tiff/IFD_SHORT.java | 3 + .../format/jpeg/tiff/IFD_SRATIONAL.java | 2 +- .../freeinternals/format/jpeg/tiff/TIFF.java | 2 +- .../freeinternals/format/jpeg/xmp/XMP.java | 5 ++ .../format/pdf/CrossReferenceTable.java | 13 ++-- .../format/pdf/IndirectObject.java | 6 +- .../freeinternals/format/pdf/StartXRef.java | 2 +- .../format/pdf/basicobj/Analysis.java | 2 +- .../format/pdf/basicobj/Array.java | 2 +- .../format/pdf/basicobj/Boolean.java | 4 +- .../format/pdf/basicobj/Dictionary.java | 2 +- .../format/pdf/basicobj/Null.java | 2 +- .../format/pdf/basicobj/Stream.java | 24 +++--- .../format/zip/CentralDirectoryStructure.java | 56 +++++++++++--- .../zip/EndOfCentralDirectoryRecord.java | 13 +++- .../format/zip/LocalFileHeader.java | 39 ++++++++-- .../org/freeinternals/format/zip/ZIPFile.java | 17 ++-- .../zip/ui/biv/GenerateTreeNode_CDE.java | 2 +- .../zip/ui/biv/GenerateTreeNode_CDS.java | 2 +- .../zip/ui/biv/GenerateTreeNode_LFH.java | 2 +- pom.xml | 9 +++ 61 files changed, 299 insertions(+), 192 deletions(-) diff --git a/CommonLib/src/main/java/org/freeinternals/commonlib/core/BytesTool.java b/CommonLib/src/main/java/org/freeinternals/commonlib/core/BytesTool.java index d7ea8a8..47ac793 100644 --- a/CommonLib/src/main/java/org/freeinternals/commonlib/core/BytesTool.java +++ b/CommonLib/src/main/java/org/freeinternals/commonlib/core/BytesTool.java @@ -6,6 +6,7 @@ */ package org.freeinternals.commonlib.core; +import java.io.DataInput; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -24,6 +25,37 @@ */ public final class BytesTool { + /** + * Get a string for the {@code hex} view of byte array {@code data}. + * + * @param data Byte array + * @return A string representing the {@code hex} version of {@code data} + */ + public static String getByteDataHexView(final byte[] data) { + if (data == null) { + return ""; + } + if (data.length < 1) { + return ""; + } + + final StringBuilder sb = new StringBuilder(data.length * 5); + final int length = data.length; + int i; + int lineBreakCounter = 0; + for (i = 0; i < length; i++) { + sb.append(String.format(" %02X", data[i])); + lineBreakCounter++; + if (lineBreakCounter == 16) { + sb.append('\n'); + lineBreakCounter = 0; + } + } + sb.append('\n'); + + return sb.toString(); + } + public static boolean isByteArrayEmpty(final byte[] buff, final int startPos, final int length) { boolean result = false; @@ -108,37 +140,6 @@ public static boolean isByteArraySame(final byte[] bin1, final byte[] bin2, fina return same; } - /** - * Get a string for the {@code hex} view of byte array {@code data}. - * - * @param data Byte array - * @return A string representing the {@code hex} version of {@code data} - */ - public static String getByteDataHexView(final byte[] data) { - if (data == null) { - return ""; - } - if (data.length < 1) { - return ""; - } - - final StringBuilder sb = new StringBuilder(data.length * 5); - final int length = data.length; - int i; - int lineBreakCounter = 0; - for (i = 0; i < length; i++) { - sb.append(String.format(" %02X", data[i])); - lineBreakCounter++; - if (lineBreakCounter == 16) { - sb.append('\n'); - lineBreakCounter = 0; - } - } - sb.append('\n'); - - return sb.toString(); - } - /** * Returns byte array from the {@code file} * @@ -208,4 +209,18 @@ public static byte[] readZipEntryAsBytes(final ZipFile zipFile, final ZipEntry z } } + public static void skip(final InputStream is, final long skip) throws IOException { + long skippedBytes = is.skip(skip); + if (skippedBytes != skip) { + throw new IOException(String.format("Failed to skip %d bytes, actual bytes skipped %d", skip, skippedBytes)); + } + } + + public static void skipBytes(final DataInput di, final int skip) throws IOException { + long skippedBytes = di.skipBytes(skip); + if (skippedBytes != skip) { + throw new IOException(String.format("Failed to skip %d bytes, actual bytes skipped %d", skip, skippedBytes)); + } + } + } diff --git a/CommonLib/src/main/java/org/freeinternals/commonlib/core/FileComponenPlaceHolder.java b/CommonLib/src/main/java/org/freeinternals/commonlib/core/FileComponenPlaceHolder.java index f5c15f7..79983f4 100644 --- a/CommonLib/src/main/java/org/freeinternals/commonlib/core/FileComponenPlaceHolder.java +++ b/CommonLib/src/main/java/org/freeinternals/commonlib/core/FileComponenPlaceHolder.java @@ -25,10 +25,7 @@ public FileComponenPlaceHolder(final PosDataInputStream posDataInputStream, int if (length > 0) { this.length = length; - int skippedBytes = posDataInputStream.skipBytes(length); - if (skippedBytes != length) { - throw new IOException(String.format("Failed to skip %d bytes, actual bytes skipped %d", length, skippedBytes)); - } + BytesTool.skipBytes(posDataInputStream, length); } else { this.length = 0; } diff --git a/FormatCLASS/pom.xml b/FormatCLASS/pom.xml index 03a3f89..6af12a2 100644 --- a/FormatCLASS/pom.xml +++ b/FormatCLASS/pom.xml @@ -20,12 +20,6 @@ 1.0 compile - - com.github.spotbugs - spotbugs-annotations - 3.1.12 - jar - diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/Opcode.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/Opcode.java index e07fe07..949b0eb 100755 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/Opcode.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/Opcode.java @@ -12,6 +12,7 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; +import org.freeinternals.commonlib.core.BytesTool; import org.freeinternals.commonlib.core.PosByteArrayInputStream; import org.freeinternals.commonlib.core.PosDataInputStream; @@ -1624,10 +1625,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi InstructionParsed parsed = new InstructionParsed(curPos, this.code); parsed.cpIndex = pdis.readUnsignedShort(); int nArgs = pdis.readUnsignedByte(); - int skippedBytes = pdis.skipBytes(1); - if (skippedBytes != 1) { - throw new IOException(String.format("Failed to skip %d bytes, actual bytes skipped %d", 1, skippedBytes)); - } + BytesTool.skipBytes(pdis, 1); parsed.opCodeText = String.format("%s interface=%d, nargs=%d", this.name(), parsed.cpIndex, nArgs); return parsed; @@ -1641,10 +1639,9 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi protected InstructionParsed parse(final int curPos, final PosDataInputStream pdis) throws IOException { InstructionParsed parsed = new InstructionParsed(curPos, this.code); parsed.cpIndex = pdis.readUnsignedShort(); - int skippedBytes = pdis.skipBytes(2); // Skip 2 zero bytes - if (skippedBytes != 2) { - throw new IOException(String.format("Failed to skip %d bytes, actual bytes skipped %d", 2, skippedBytes)); - } + + // Skip 2 zero bytes + BytesTool.skipBytes(pdis, 2); parsed.opCodeText = this.name(); return parsed; } @@ -2003,10 +2000,7 @@ private void skipPad(final PosDataInputStream pdis) throws IOException { int skip = pdis.getPos() % 4; skip = (skip > 0) ? 4 - skip : skip; if (skip > 0) { - int skippedBytes = pdis.skipBytes(skip); - if (skippedBytes != skip) { - throw new IOException(String.format("Failed to skip %d bytes, actual bytes skipped %d", skip, skippedBytes)); - } + BytesTool.skipBytes(pdis, skip); } } diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeCode.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeCode.java index 7d6eb9d..89c2eb0 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeCode.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeCode.java @@ -78,7 +78,7 @@ public class AttributeCode extends AttributeInfo { this.code = new byte[this.code_length.value]; int readBytes = posDataInputStream.read(this.code); if (readBytes != this.code_length.value) { - throw new IOException(String.format("Failed to skip %d bytes, actual bytes skipped %d", this.code_length.value, readBytes)); + throw new IOException(String.format("Failed to read %d bytes, actual bytes read %d", this.code_length.value, readBytes)); } this.exception_table_length = new u2(posDataInputStream); diff --git a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeUnrecognized.java b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeUnrecognized.java index 3adeb40..12b3603 100644 --- a/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeUnrecognized.java +++ b/FormatCLASS/src/main/java/org/freeinternals/format/classfile/attribute/AttributeUnrecognized.java @@ -46,7 +46,7 @@ public class AttributeUnrecognized extends AttributeInfo { this.rawData = new byte[this.attribute_length.value]; int readBytes = posDataInputStream.read(this.rawData); if (readBytes != this.attribute_length.value) { - throw new IOException(String.format("Failed to skip %d bytes, actual bytes skipped %d", this.attribute_length.value, readBytes)); + throw new IOException(String.format("Failed to read %d bytes, actual bytes red %d", this.attribute_length.value, readBytes)); } } diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/FileData.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/FileData.java index e12db4f..d917122 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/FileData.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/FileData.java @@ -8,6 +8,7 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; +import org.freeinternals.commonlib.core.BytesTool; import org.freeinternals.commonlib.core.FileComponent; import org.freeinternals.commonlib.core.PosDataInputStream; import org.freeinternals.commonlib.ui.GenerateTreeNode; @@ -27,7 +28,7 @@ public class FileData extends FileComponent implements GenerateTreeNode { this.isCompressedData = isCompressedData; if (length > 0) { - pDis.skip(length); + BytesTool.skip(pDis, length); } } diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/Marker.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/Marker.java index b1813aa..70542b9 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/Marker.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/Marker.java @@ -8,6 +8,7 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; +import org.freeinternals.commonlib.core.BytesTool; import org.freeinternals.commonlib.core.FileComponent; import org.freeinternals.commonlib.core.PosDataInputStream; import org.freeinternals.commonlib.ui.GenerateTreeNode; @@ -46,7 +47,8 @@ public class Marker extends FileComponent implements GenerateTreeNode { if (MarkerCode.isLengthAvailable(markerCode)) { this.marker_length = pDIS.readUnsignedShort(); super.length = this.marker_length + 2; - pDIS.skip(this.marker_length - 2); + long skip = this.marker_length - 2; + BytesTool.skip(pDIS, skip); } else { this.marker_length = 0; super.length = MarkerCode.MARKER_CODE_BYTES_COUNT; @@ -56,13 +58,13 @@ public class Marker extends FileComponent implements GenerateTreeNode { protected void parse(final PosDataInputStream pDisMarker) throws IOException, FileFormatException { } - protected void parseInitSkip(final PosDataInputStream pDisMarker) throws IOException{ + protected void parseInitSkip(final PosDataInputStream pDisMarker) throws IOException { // Skip the marker code and length field - pDisMarker.skip(MarkerCode.MARKER_CODE_BYTES_COUNT); - pDisMarker.skip(MarkerCode.MARKER_LENGTH_BYTES_COUNT); + long skip = MarkerCode.MARKER_CODE_BYTES_COUNT + MarkerCode.MARKER_LENGTH_BYTES_COUNT; + BytesTool.skip(pDisMarker, skip); } - protected String parseIdentifier(final PosDataInputStream pDisMarker) throws IOException{ + protected String parseIdentifier(final PosDataInputStream pDisMarker) throws IOException { // Parse the Identifier, an '\000' ended ASCII string final StringBuffer sb = new StringBuffer(IDENTIFIER_LENGTH_MAX); diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/MarkerCode.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/MarkerCode.java index aac22ef..4a4e053 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/MarkerCode.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/MarkerCode.java @@ -14,10 +14,10 @@ public class MarkerCode { public static final int MARKER_CODE_BYTES_COUNT = 2; public static final int MARKER_LENGTH_BYTES_COUNT = 2; - public static final int min = 0xFF00; + public static final int MIN = 0xFF00; public static final int TEMP = 0xFF01; // Standalone, For temporary private use in arithmetic coding - public static final int RES_min = 0xFF02; // Reserved - public static final int RES_max = 0xFFBF; // Reserved + public static final int RES_MIN = 0xFF02; // Reserved + public static final int RES_MAX = 0xFFBF; // Reserved public static final int SOF00 = 0xFFC0; // Specified public static final int SOF01 = 0xFFC1; // Specified public static final int SOF02 = 0xFFC2; // Specified @@ -81,7 +81,7 @@ public class MarkerCode { public static final int JPG12 = 0xFFFC; // Reserved for JPEG extensions public static final int JPG13 = 0xFFFD; // Reserved for JPEG extensions public static final int COM = 0xFFFE; // Specified - public static final int max = 0xFFFF; + public static final int MAX = 0xFFFF; /** * The marker code value is in valid value space or not. @@ -90,7 +90,7 @@ public class MarkerCode { * @return true when in valid value space, else false */ public static boolean isValid(int code) { - return (code > min && code != max); + return (code > MIN && code != MAX); } /** @@ -175,7 +175,7 @@ public static String getMarkerName(int markerCode) { if (markerCode == MarkerCode.TEMP) { name = "TEMP"; - } else if (markerCode >= MarkerCode.RES_min && markerCode <= MarkerCode.RES_max) { + } else if (markerCode >= MarkerCode.RES_MIN && markerCode <= MarkerCode.RES_MAX) { name = "RES"; } else if (markerCode >= MarkerCode.SOF00 && markerCode <= MarkerCode.COM) { switch (markerCode) { @@ -368,6 +368,9 @@ public static String getMarkerName(int markerCode) { case MarkerCode.COM: name = "COM"; break; + default: + name = "Un-recognized"; + break; } } @@ -377,11 +380,11 @@ public static String getMarkerName(int markerCode) { public static String getMarkerDescription(int markerCode) { String desc = "Error"; - if (markerCode == MarkerCode.min) { + if (markerCode == MarkerCode.MIN) { desc = "MIN"; } else if (markerCode == MarkerCode.TEMP) { desc = "[Reserved markers] For temporary private use in arithmetic coding"; - } else if (markerCode >= MarkerCode.RES_min && markerCode <= MarkerCode.RES_max) { + } else if (markerCode >= MarkerCode.RES_MIN && markerCode <= MarkerCode.RES_MAX) { desc = "[Reserved markers] Reserved"; } else if (markerCode >= MarkerCode.SOF00 && markerCode <= MarkerCode.COM) { switch (markerCode) { @@ -574,8 +577,11 @@ public static String getMarkerDescription(int markerCode) { case MarkerCode.COM: desc = "[Other markers] Comment"; break; + default: + desc = "Un-recognized markder: " + markerCode; + break; } - } else if (markerCode == MarkerCode.max) { + } else if (markerCode == MarkerCode.MAX) { desc = "MAX"; } diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/Marker_APP13.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/Marker_APP13.java index 67d0592..e2e89e4 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/Marker_APP13.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/Marker_APP13.java @@ -15,13 +15,13 @@ import org.freeinternals.format.jpeg.ps.PhotoshopImageResource; /** + * An APP13 marker designates a Photoshop Image Resource (PSIR) that contains IPTC metadata. * * @author Amos Shi */ -// an APP13 marker designates a Photoshop Image Resource (PSIR) that contains IPTC metadata public class Marker_APP13 extends Marker { - public static final String identifier_Photoshop = "Photoshop"; + public static final String IDENTIFIER_PHOTOSHOP = "Photoshop"; private String identifier; private PhotoshopImageResource psir; @@ -33,7 +33,7 @@ public class Marker_APP13 extends Marker { protected void parse(final PosDataInputStream pDisMarker) throws IOException, FileFormatException { super.parseInitSkip(pDisMarker); this.identifier = super.parseIdentifier(pDisMarker); - if (this.identifier.contains(Marker_APP13.identifier_Photoshop)) { + if (this.identifier.contains(Marker_APP13.IDENTIFIER_PHOTOSHOP)) { final int lengthPhir = this.marker_length - 2 - this.identifier.length() - 1; final byte[] bytesPhir = new byte[lengthPhir]; System.arraycopy(pDisMarker.getBuf(), 2 + 2 + this.identifier.length() + 1, bytesPhir, 0, lengthPhir); @@ -69,17 +69,15 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode) { this.identifier.length() + 1, String.format("identifier: %s", this.identifier)))); - if (this.identifier.contains(Marker_APP13.identifier_Photoshop)) { + if (this.identifier.contains(Marker_APP13.IDENTIFIER_PHOTOSHOP)) { comp = new JTreeNodeFileComponent( this.psir.getStartPos(), this.psir.getLength(), "Photoshop Image Resource Block"); markerNode.add(identifierNode = new DefaultMutableTreeNode(comp)); - if (this.psir != null) { - this.psir.generateTreeNode(identifierNode); - } + this.psir.generateTreeNode(identifierNode); } else { - markerNode.add(identifierNode = new DefaultMutableTreeNode(new JTreeNodeFileComponent( + markerNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( lastPos = lastPos + this.identifier.length() + 1, this.startPos + this.length - lastPos, this.identifier))); diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/Marker_DRI.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/Marker_DRI.java index 9b0639b..6aa82b1 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/Marker_DRI.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/Marker_DRI.java @@ -56,7 +56,7 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode) { // Ri comp = new JTreeNodeFileComponent( - lastPos = lastPos + 2, + lastPos + 2, 2, String.format("Ri: %d", this.Ri)); comp.setDescription("Restart interval – Specifies the number of MCU in the restart interval."); diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/Marker_SOFnn.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/Marker_SOFnn.java index 43b6b35..b0d58e7 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/Marker_SOFnn.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/Marker_SOFnn.java @@ -18,7 +18,7 @@ */ public class Marker_SOFnn extends Marker { - private class Component { + private static class Component { /** Component Identifier */ @SuppressWarnings("PackageVisibleField") diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/Marker_SOS.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/Marker_SOS.java index eae4ca3..e2a70a0 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/Marker_SOS.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/Marker_SOS.java @@ -18,7 +18,7 @@ */ public class Marker_SOS extends Marker { - private class Parameter { + private static class Parameter { /** Scan component selector */ @SuppressWarnings("PackageVisibleField") diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/icc/ICCProfile.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/icc/ICCProfile.java index f74860a..9760473 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/icc/ICCProfile.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/icc/ICCProfile.java @@ -104,7 +104,7 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode) { } @SuppressWarnings("PackageVisibleInnerClass") - private class RefItem { + private static class RefItem { int i; Tag tag; diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/icc/TagData.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/icc/TagData.java index dcedbe8..261b679 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/icc/TagData.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/icc/TagData.java @@ -8,6 +8,7 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; +import org.freeinternals.commonlib.core.BytesTool; import org.freeinternals.commonlib.core.FileComponent; import org.freeinternals.commonlib.core.PosDataInputStream; import org.freeinternals.commonlib.ui.GenerateTreeNode; @@ -31,7 +32,9 @@ public TagData(final PosDataInputStream input) throws IOException { super.length = input.getBuf().length; this.tagType = input.readInt(); - input.skip(4); // Reserved + + // Reserved bytes + BytesTool.skip(input, 4); } public String getTagType() { diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/icc/dateTimeNumber.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/icc/dateTimeNumber.java index b8a32cc..a8779ee 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/icc/dateTimeNumber.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/icc/dateTimeNumber.java @@ -6,6 +6,7 @@ */ package org.freeinternals.format.jpeg.icc; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; import org.freeinternals.commonlib.core.PosDataInputStream; @@ -15,6 +16,7 @@ * * @author Amos Shi */ +@SuppressFBWarnings(value = "NM_CLASS_NAMING_CONVENTION", justification = "Use the type name from ICC Specification") public class dateTimeNumber { public final int year; diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/icc/s15Fixed16Number.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/icc/s15Fixed16Number.java index bd6414c..f408a71 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/icc/s15Fixed16Number.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/icc/s15Fixed16Number.java @@ -6,6 +6,7 @@ */ package org.freeinternals.format.jpeg.icc; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; import org.freeinternals.commonlib.core.PosDataInputStream; @@ -13,6 +14,7 @@ * * @author Amos Shi */ +@SuppressFBWarnings(value = "NM_CLASS_NAMING_CONVENTION", justification = "Use the type name from ICC Specification") public class s15Fixed16Number { public final byte[] rawData; @@ -42,7 +44,7 @@ public s15Fixed16Number(final PosDataInputStream input) throws IOException { } @Override - public String toString(){ + public String toString() { return String.format("%.4f", this.value); } } diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/ps/IRB_8BIM.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/ps/IRB_8BIM.java index 4153af1..b291219 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/ps/IRB_8BIM.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/ps/IRB_8BIM.java @@ -8,6 +8,7 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; +import org.freeinternals.commonlib.core.BytesTool; import org.freeinternals.commonlib.core.FileComponent; import org.freeinternals.commonlib.core.PosDataInputStream; import org.freeinternals.commonlib.ui.JTreeNodeFileComponent; @@ -47,7 +48,7 @@ public class IRB_8BIM extends FileComponent { // skip for name this.data_skip1byte = ((this.size & 1) != 0); if (this.data_skip1byte) { - input.skip(1); + BytesTool.skip(input, 1); } // data @@ -63,7 +64,7 @@ public class IRB_8BIM extends FileComponent { // skip for name this.name_skip1byte = ((this.size & 1) != 0); // true for odd value; false for even if (this.name_skip1byte) { - input.skip(1); + BytesTool.skip(input, 1); } // total length diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD.java index 4877bdc..e8e739f 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD.java @@ -8,6 +8,7 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; +import org.freeinternals.commonlib.core.BytesTool; import org.freeinternals.commonlib.core.FileComponent; import org.freeinternals.commonlib.core.PosByteArrayInputStream; import org.freeinternals.commonlib.core.PosDataInputStream; @@ -101,7 +102,7 @@ protected final PosDataInputStream getTiffOffsetReader() throws IOException { throw new ArrayIndexOutOfBoundsException("TIFF IFD: the data ending offset is bigger than tiff buffer length"); } - reader.skip(this.ifd_value_offset); + BytesTool.skip(reader, this.ifd_value_offset); return reader; } diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFDGroup.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFDGroup.java index d4d16d3..d453c65 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFDGroup.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFDGroup.java @@ -8,6 +8,7 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; +import org.freeinternals.commonlib.core.BytesTool; import org.freeinternals.commonlib.core.PosByteArrayInputStream; import org.freeinternals.commonlib.core.PosDataInputStream; import org.freeinternals.commonlib.ui.JTreeNodeFileComponent; @@ -39,7 +40,7 @@ class IFDGroup { final PosDataInputStream pDisTiff = new PosDataInputStream( new PosByteArrayInputStream(byteArrayTiff), tiffHeader.getStartPos()); - pDisTiff.skip(offset); + BytesTool.skip(pDisTiff, offset); this.ifd_number = IFDParse.readUnsignedShort(pDisTiff, tiffHeader.byte_order); if (this.ifd_number > 0) { // IFD count could be zero this.ifd = new IFD[this.ifd_number]; diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_829A_ExposureTime.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_829A_ExposureTime.java index 5e594f7..7bd84f3 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_829A_ExposureTime.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_829A_ExposureTime.java @@ -14,12 +14,12 @@ /** * * @author Amos Shi - * @see IFD_8769_Exif#Category_G + * @see IFD_8769_Exif#CATEGORY_G */ public class IFD_829A_ExposureTime extends IFD_RATIONAL_COUNT1 { private final static String IFD_Description = IFDMessage.getString(IFDMessage.KEY_IFD_829A_Description) - + IFD_8769_Exif.Category_G; + + IFD_8769_Exif.CATEGORY_G; public IFD_829A_ExposureTime(final PosDataInputStream pDIS, int byteOrder, int tag, int startPosTiff, byte[] byteArrayTiff) throws IOException, FileFormatException { diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_829D_FNumber.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_829D_FNumber.java index 7370be9..3fa4aa6 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_829D_FNumber.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_829D_FNumber.java @@ -14,12 +14,12 @@ /** * * @author Amos Shi - * @see IFD_8769_Exif#Category_G + * @see IFD_8769_Exif#CATEGORY_G */ public class IFD_829D_FNumber extends IFD_RATIONAL_COUNT1 { private final static String IFD_Description = IFDMessage.getString(IFDMessage.KEY_IFD_829D_Description) - + IFD_8769_Exif.Category_G; + + IFD_8769_Exif.CATEGORY_G; public IFD_829D_FNumber(final PosDataInputStream pDIS, int byteOrder, int tag, int startPosTiff, byte[] byteArrayTiff) throws IOException, FileFormatException { diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_8769_Exif.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_8769_Exif.java index dd14c65..ff863e5 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_8769_Exif.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_8769_Exif.java @@ -8,6 +8,7 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; +import org.freeinternals.commonlib.core.BytesTool; import org.freeinternals.commonlib.core.PosByteArrayInputStream; import org.freeinternals.commonlib.core.PosDataInputStream; import org.freeinternals.commonlib.ui.JTreeNodeFileComponent; @@ -20,13 +21,13 @@ */ public class IFD_8769_Exif extends IFD_LONG_Pointer { - public static final String Category_A = IFDMessage.getString(IFDMessage.KEY_IFD_8769_Exif_Category_A); - public static final String Category_B = IFDMessage.getString(IFDMessage.KEY_IFD_8769_Exif_Category_B); - public static final String Category_C = IFDMessage.getString(IFDMessage.KEY_IFD_8769_Exif_Category_C); - public static final String Category_D = IFDMessage.getString(IFDMessage.KEY_IFD_8769_Exif_Category_D); - public static final String Category_E = IFDMessage.getString(IFDMessage.KEY_IFD_8769_Exif_Category_E); - public static final String Category_F = IFDMessage.getString(IFDMessage.KEY_IFD_8769_Exif_Category_F); - public static final String Category_G = IFDMessage.getString(IFDMessage.KEY_IFD_8769_Exif_Category_G); + public static final String CATEGORY_A = IFDMessage.getString(IFDMessage.KEY_IFD_8769_Exif_Category_A); + public static final String CATEGORY_B = IFDMessage.getString(IFDMessage.KEY_IFD_8769_Exif_Category_B); + public static final String CATEGORY_C = IFDMessage.getString(IFDMessage.KEY_IFD_8769_Exif_Category_C); + public static final String CATEGORY_D = IFDMessage.getString(IFDMessage.KEY_IFD_8769_Exif_Category_D); + public static final String CATEGORY_E = IFDMessage.getString(IFDMessage.KEY_IFD_8769_Exif_Category_E); + public static final String CATEGORY_F = IFDMessage.getString(IFDMessage.KEY_IFD_8769_Exif_Category_F); + public static final String CATEGORY_G = IFDMessage.getString(IFDMessage.KEY_IFD_8769_Exif_Category_G); public IFD_8769_Exif(final PosDataInputStream pDIS, int byteOrder, int tag, int startPosTiff, byte[] byteArrayTiff) throws IOException, FileFormatException { @@ -37,7 +38,7 @@ public IFD_8769_Exif(final PosDataInputStream pDIS, int byteOrder, int tag, int final PosDataInputStream reader = new PosDataInputStream( new PosByteArrayInputStream(this.tiff_ByteArray), super.tiff_StartPos); - reader.skip(this.getExifOffset() + 2); + BytesTool.skip(reader, this.getExifOffset() + 2); if (this.ifd_number > 0) { for (int i = 0; i < this.ifd_number; i++) { this.ifd_sub[i] = IFDParse.parse(reader, byteOrder, startPosTiff, byteArrayTiff); diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_8822_ExposureProgram.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_8822_ExposureProgram.java index ae329f3..e2a5944 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_8822_ExposureProgram.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_8822_ExposureProgram.java @@ -18,7 +18,7 @@ public class IFD_8822_ExposureProgram extends IFD_SHORT_COUNT1 { private final static String IFD_Description = IFDMessage.getString(IFDMessage.KEY_IFD_8822_Description) - + IFD_8769_Exif.Category_G; + + IFD_8769_Exif.CATEGORY_G; public IFD_8822_ExposureProgram(final PosDataInputStream pDIS, int byteOrder, int tag, int startPosTiff, byte[] byteArrayTiff) throws IOException, FileFormatException { diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_8825_GPS.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_8825_GPS.java index 9910c48..c1f1e64 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_8825_GPS.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_8825_GPS.java @@ -8,6 +8,7 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; +import org.freeinternals.commonlib.core.BytesTool; import org.freeinternals.commonlib.core.PosByteArrayInputStream; import org.freeinternals.commonlib.core.PosDataInputStream; import org.freeinternals.commonlib.ui.JTreeNodeFileComponent; @@ -31,7 +32,7 @@ public IFD_8825_GPS(final PosDataInputStream pDIS, int byteOrder, int tag, int s new PosByteArrayInputStream(this.tiff_ByteArray), super.tiff_StartPos ); - reader.skip(this.getGPSOffset() + 2); + BytesTool.skip(reader, this.getGPSOffset() + 2); if (this.ifd_number > 0) { for (int i = 0; i < this.ifd_number; i++) { this.ifd_sub[i] = IFDParse.parseGPS(reader, byteOrder, startPosTiff, byteArrayTiff); diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A005_Interoperability.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A005_Interoperability.java index d99f7a8..bb43c07 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A005_Interoperability.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A005_Interoperability.java @@ -8,6 +8,7 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; +import org.freeinternals.commonlib.core.BytesTool; import org.freeinternals.commonlib.core.PosByteArrayInputStream; import org.freeinternals.commonlib.core.PosDataInputStream; import org.freeinternals.commonlib.ui.JTreeNodeFileComponent; @@ -30,7 +31,7 @@ public IFD_A005_Interoperability(final PosDataInputStream pDIS, int byteOrder, i final PosDataInputStream reader = new PosDataInputStream( new PosByteArrayInputStream(this.tiff_ByteArray), super.tiff_StartPos); - reader.skip(this.getInteroperabilityOffset() + 2); + BytesTool.skip(reader, this.getInteroperabilityOffset() + 2); if (this.ifd_number > 0) { for (int i = 0; i < this.ifd_number; i++) { this.ifd_sub[i] = IFDParse.parseIntero(reader, byteOrder, startPosTiff, byteArrayTiff); diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A302_CFAPattern.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A302_CFAPattern.java index 04e3b22..2aa28e6 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A302_CFAPattern.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A302_CFAPattern.java @@ -17,11 +17,11 @@ /** * * @author Amos Shi - * @see IFD_8769_Exif#Category_G + * @see IFD_8769_Exif#CATEGORY_G */ public class IFD_A302_CFAPattern extends IFD_UNDEFINED { - public static final String[] FilterColor = {"RED", "GREEN", "BLUE", "CYAN", "MAGENTA", "YELLOW", "WHITE"}; + static final String[] FILTER_COLORS = {"RED", "GREEN", "BLUE", "CYAN", "MAGENTA", "YELLOW", "WHITE"}; /** Horizontal repeat pixel unit. */ public final int n; /** Vertical repeat pixel unit. */ @@ -86,7 +86,7 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode) { node.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( super.tiff_StartPos + super.ifd_value_offset + 4 + i, 1, - String.format("CFA value: %d - %s", cfa, FilterColor[cfa])))); + String.format("CFA value: %d - %s", cfa, FILTER_COLORS[cfa])))); } } } diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A401_CustomRendered.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A401_CustomRendered.java index 31ed800..d1efc37 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A401_CustomRendered.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A401_CustomRendered.java @@ -14,7 +14,7 @@ /** * * @author Amos Shi - * @see IFD_8769_Exif#Category_G + * @see IFD_8769_Exif#CATEGORY_G */ public class IFD_A401_CustomRendered extends IFD_SHORT_COUNT1 { @@ -28,6 +28,6 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode) { super.generateTreeNode_SHORT( parentNode, IFDMessage.getString(IFDMessage.KEY_IFD_A401_Description) - + IFD_8769_Exif.Category_G); + + IFD_8769_Exif.CATEGORY_G); } } diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A402_ExposureMode.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A402_ExposureMode.java index a7bc2ee..5abcdbe 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A402_ExposureMode.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A402_ExposureMode.java @@ -14,7 +14,7 @@ /** * * @author Amos Shi - * @see IFD_8769_Exif#Category_G + * @see IFD_8769_Exif#CATEGORY_G */ public class IFD_A402_ExposureMode extends IFD_SHORT_COUNT1 { @@ -28,6 +28,6 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode) { super.generateTreeNode_SHORT( parentNode, IFDMessage.getString(IFDMessage.KEY_IFD_A402_Description) - + IFD_8769_Exif.Category_G); + + IFD_8769_Exif.CATEGORY_G); } } diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A403_WhiteBalance.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A403_WhiteBalance.java index 2e7735f..32fb195 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A403_WhiteBalance.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A403_WhiteBalance.java @@ -14,7 +14,7 @@ /** * * @author Amos Shi - * @see IFD_8769_Exif#Category_G + * @see IFD_8769_Exif#CATEGORY_G */ public class IFD_A403_WhiteBalance extends IFD_SHORT_COUNT1 { @@ -28,6 +28,6 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode) { super.generateTreeNode_SHORT( parentNode, IFDMessage.getString(IFDMessage.KEY_IFD_A403_Description) - + IFD_8769_Exif.Category_G); + + IFD_8769_Exif.CATEGORY_G); } } diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A404_DigitalZoomRatio.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A404_DigitalZoomRatio.java index 0f12386..7032485 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A404_DigitalZoomRatio.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A404_DigitalZoomRatio.java @@ -14,7 +14,7 @@ /** * * @author Amos Shi - * @see IFD_8769_Exif#Category_G + * @see IFD_8769_Exif#CATEGORY_G */ public class IFD_A404_DigitalZoomRatio extends IFD_RATIONAL_COUNT1 { @@ -28,6 +28,6 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode) { super.generateTreeNode_RATIONAL( parentNode, IFDMessage.getString(IFDMessage.KEY_IFD_A404_Description) - + IFD_8769_Exif.Category_G); + + IFD_8769_Exif.CATEGORY_G); } } diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A405_FocalLengthIn35mmFilm.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A405_FocalLengthIn35mmFilm.java index 193d878..773cd4e 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A405_FocalLengthIn35mmFilm.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A405_FocalLengthIn35mmFilm.java @@ -14,7 +14,7 @@ /** * * @author Amos Shi - * @see IFD_8769_Exif#Category_G + * @see IFD_8769_Exif#CATEGORY_G * @see IFD_920A_FocalLength */ public class IFD_A405_FocalLengthIn35mmFilm extends IFD_SHORT_COUNT1 { @@ -29,6 +29,6 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode) { super.generateTreeNode_SHORT( parentNode, IFDMessage.getString(IFDMessage.KEY_IFD_A405_Description) - + IFD_8769_Exif.Category_G); + + IFD_8769_Exif.CATEGORY_G); } } diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A406_SceneCaptureType.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A406_SceneCaptureType.java index 0044caa..31ac21a 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A406_SceneCaptureType.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A406_SceneCaptureType.java @@ -14,7 +14,7 @@ /** * * @author Amos Shi - * @see IFD_8769_Exif#Category_G + * @see IFD_8769_Exif#CATEGORY_G * @see IFD_A301_SceneType */ public class IFD_A406_SceneCaptureType extends IFD_SHORT_COUNT1 { @@ -29,6 +29,6 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode) { super.generateTreeNode_SHORT( parentNode, IFDMessage.getString(IFDMessage.KEY_IFD_A406_Description) - + IFD_8769_Exif.Category_G); + + IFD_8769_Exif.CATEGORY_G); } } diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A407_GainControl.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A407_GainControl.java index 5380157..c66bace 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A407_GainControl.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A407_GainControl.java @@ -14,7 +14,7 @@ /** * * @author Amos Shi - * @see IFD_8769_Exif#Category_G + * @see IFD_8769_Exif#CATEGORY_G */ public class IFD_A407_GainControl extends IFD_SHORT_COUNT1 { @@ -28,6 +28,6 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode) { super.generateTreeNode_SHORT( parentNode, IFDMessage.getString(IFDMessage.KEY_IFD_A407_Description) - + IFD_8769_Exif.Category_G); + + IFD_8769_Exif.CATEGORY_G); } } diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A408_Contrast.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A408_Contrast.java index 6138600..6c29855 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A408_Contrast.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A408_Contrast.java @@ -14,7 +14,7 @@ /** * * @author Amos Shi - * @see IFD_8769_Exif#Category_G + * @see IFD_8769_Exif#CATEGORY_G */ public class IFD_A408_Contrast extends IFD_SHORT_COUNT1 { @@ -28,6 +28,6 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode) { super.generateTreeNode_SHORT( parentNode, IFDMessage.getString(IFDMessage.KEY_IFD_A408_Description) - + IFD_8769_Exif.Category_G); + + IFD_8769_Exif.CATEGORY_G); } } diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A409_Saturation.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A409_Saturation.java index 508950e..bff7207 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A409_Saturation.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A409_Saturation.java @@ -14,7 +14,7 @@ /** * * @author Amos Shi - * @see IFD_8769_Exif#Category_G + * @see IFD_8769_Exif#CATEGORY_G */ public class IFD_A409_Saturation extends IFD_SHORT_COUNT1 { @@ -28,6 +28,6 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode) { super.generateTreeNode_SHORT( parentNode, IFDMessage.getString(IFDMessage.KEY_IFD_A409_Description) - + IFD_8769_Exif.Category_G); + + IFD_8769_Exif.CATEGORY_G); } } diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A40A_Sharpness.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A40A_Sharpness.java index 503b44e..ade58ea 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A40A_Sharpness.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A40A_Sharpness.java @@ -14,7 +14,7 @@ /** * * @author Amos Shi - * @see IFD_8769_Exif#Category_G + * @see IFD_8769_Exif#CATEGORY_G */ public class IFD_A40A_Sharpness extends IFD_SHORT_COUNT1 { @@ -28,6 +28,6 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode) { super.generateTreeNode_SHORT( parentNode, IFDMessage.getString(IFDMessage.KEY_IFD_A40A_Description) - + IFD_8769_Exif.Category_G); + + IFD_8769_Exif.CATEGORY_G); } } diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A40C_SubjectDistanceRange.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A40C_SubjectDistanceRange.java index db3652f..ea8348f 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A40C_SubjectDistanceRange.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_A40C_SubjectDistanceRange.java @@ -14,7 +14,7 @@ /** * * @author Amos Shi - * @see IFD_8769_Exif#Category_G + * @see IFD_8769_Exif#CATEGORY_G */ public class IFD_A40C_SubjectDistanceRange extends IFD_SHORT_COUNT1 { @@ -28,6 +28,6 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode) { super.generateTreeNode_SHORT( parentNode, IFDMessage.getString(IFDMessage.KEY_IFD_A40C_Description) - + IFD_8769_Exif.Category_G); + + IFD_8769_Exif.CATEGORY_G); } } diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_LONG_Pointer.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_LONG_Pointer.java index 42aa844..3637fab 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_LONG_Pointer.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_LONG_Pointer.java @@ -8,6 +8,7 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; +import org.freeinternals.commonlib.core.BytesTool; import org.freeinternals.commonlib.core.PosByteArrayInputStream; import org.freeinternals.commonlib.core.PosDataInputStream; import org.freeinternals.commonlib.ui.JTreeNodeFileComponent; @@ -29,11 +30,10 @@ public IFD_LONG_Pointer(final PosDataInputStream pDIS, int byteOrder, int tag, i super(pDIS, byteOrder, tag, startPosTiff, byteArrayTiff); // Sub IFD - final PosDataInputStream reader = new PosDataInputStream( new PosByteArrayInputStream(this.tiff_ByteArray), super.tiff_StartPos); - reader.skip(super.value[0]); + BytesTool.skip(reader, super.value[0]); this.ifd_number = super.readUnsignedShort(reader); if (this.ifd_number > 0) { this.ifd_sub = new IFD[this.ifd_number]; diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_RATIONAL.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_RATIONAL.java index 9668f0a..bfabbe3 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_RATIONAL.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_RATIONAL.java @@ -108,7 +108,7 @@ void generateTreeNode_RATIONAL(DefaultMutableTreeNode parentNode, String descrip } @SuppressWarnings("PublicInnerClass") - public class Rational { + public static class Rational { public final long numerator; public final long denominator; diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_SHORT.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_SHORT.java index aa3e5a3..32fc470 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_SHORT.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_SHORT.java @@ -90,6 +90,9 @@ void generateTreeNode_SHORT(DefaultMutableTreeNode parentNode, String descriptio comp.setDescription(description); parentNode.add(new DefaultMutableTreeNode(comp)); break; + default: + // Do nothing + break; } } else { comp = new JTreeNodeFileComponent( diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_SRATIONAL.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_SRATIONAL.java index 032e7d7..084fa99 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_SRATIONAL.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/IFD_SRATIONAL.java @@ -108,7 +108,7 @@ void generateTreeNode_SRATIONAL(DefaultMutableTreeNode parentNode, String descri } @SuppressWarnings("PublicInnerClass") - public class SRational { + public static class SRational { public final int numerator; public final int denominator; diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/TIFF.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/TIFF.java index 591168a..2bc5331 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/TIFF.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/tiff/TIFF.java @@ -150,7 +150,7 @@ private void loadRefItem(IFD[] ifds, ConcurrentSkipListMap sor } @SuppressWarnings("PackageVisibleInnerClass") - private class RefItem { + private static class RefItem { int offset; int length; diff --git a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/xmp/XMP.java b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/xmp/XMP.java index c1ae5e6..660a7b8 100644 --- a/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/xmp/XMP.java +++ b/FormatJPEG/src/main/java/org/freeinternals/format/jpeg/xmp/XMP.java @@ -6,6 +6,7 @@ */ package org.freeinternals.format.jpeg.xmp; +import java.util.logging.Logger; import org.freeinternals.commonlib.core.FileComponent; import org.freeinternals.commonlib.core.PosDataInputStream; import org.freeinternals.commonlib.core.FileFormatException; @@ -18,7 +19,9 @@ */ public class XMP extends FileComponent{ + private static final Logger LOG = Logger.getLogger(XMP.class.getName()); public final byte[] rawData; + private final String xmpmeta; //public final XMPMeta xmpMeta; public XMP(final PosDataInputStream input) throws FileFormatException { @@ -30,6 +33,8 @@ public XMP(final PosDataInputStream input) throws FileFormatException { for (byte b : this.rawData) { sb.append((char) b); } + this.xmpmeta = sb.toString(); + LOG.info(this.xmpmeta); // TODO - Analysis the data via XMPMeta diff --git a/FormatPDF/src/main/java/org/freeinternals/format/pdf/CrossReferenceTable.java b/FormatPDF/src/main/java/org/freeinternals/format/pdf/CrossReferenceTable.java index 09dfcdd..643a6c2 100644 --- a/FormatPDF/src/main/java/org/freeinternals/format/pdf/CrossReferenceTable.java +++ b/FormatPDF/src/main/java/org/freeinternals/format/pdf/CrossReferenceTable.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import javax.swing.tree.DefaultMutableTreeNode; +import org.freeinternals.commonlib.core.BytesTool; import org.freeinternals.commonlib.core.FileComponent; import org.freeinternals.commonlib.core.PosDataInputStream; import org.freeinternals.commonlib.core.PosDataInputStream.ASCIILine; @@ -107,8 +108,8 @@ public static class Subsection extends FileComponent implements GenerateTreeNode line)); } - this.FirstObjectNumber = Integer.valueOf(subsection_header[0]); - this.NumberOfEntries = Integer.valueOf(subsection_header[1]); + this.FirstObjectNumber = Integer.parseInt(subsection_header[0]); + this.NumberOfEntries = Integer.parseInt(subsection_header[1]); for (int i = 0; i < this.NumberOfEntries; i++) { this.Entries.add(new Entry(stream)); } @@ -155,10 +156,10 @@ public static class Entry extends FileComponent implements GenerateTreeNode { super.startPos = stream.getPos(); super.length = LENGTH; - this.Offset = Integer.valueOf(stream.readASCII(OFFSET_LENGTH)); - stream.skip(1); - this.GenerationNumber = Integer.valueOf(stream.readASCII(GENERATIONNUMBER_LENGTH)); - stream.skip(1); + this.Offset = Integer.parseInt(stream.readASCII(OFFSET_LENGTH)); + BytesTool.skip(stream, 1); + this.GenerationNumber = Integer.parseInt(stream.readASCII(GENERATIONNUMBER_LENGTH)); + BytesTool.skip(stream, 1); this.Type = (char) stream.readByte(); stream.skip(2); } diff --git a/FormatPDF/src/main/java/org/freeinternals/format/pdf/IndirectObject.java b/FormatPDF/src/main/java/org/freeinternals/format/pdf/IndirectObject.java index 01032d1..6e4044a 100644 --- a/FormatPDF/src/main/java/org/freeinternals/format/pdf/IndirectObject.java +++ b/FormatPDF/src/main/java/org/freeinternals/format/pdf/IndirectObject.java @@ -74,8 +74,8 @@ public class IndirectObject extends FileComponent implements GenerateTreeNode { IndirectObject(PosDataInputStream stream, ASCIILine line) throws IOException, FileFormatException { stream.backward(line.length()); super.startPos = stream.getPos(); - this.ObjectNumber = Integer.valueOf(stream.readASCIIUntil(PDFStatics.WhiteSpace.SP)); - this.GenerationNumber = Integer.valueOf(stream.readASCIIUntil(PDFStatics.WhiteSpace.SP)); + this.ObjectNumber = Integer.parseInt(stream.readASCIIUntil(PDFStatics.WhiteSpace.SP)); + this.GenerationNumber = Integer.parseInt(stream.readASCIIUntil(PDFStatics.WhiteSpace.SP)); this.NumberLen = stream.getPos() - super.startPos; stream.skip(SIGNATURE_START.length()); byte b1 = stream.readByte(); @@ -142,7 +142,7 @@ private void parseObject(PosDataInputStream root) throws IOException, FileFormat Analysis analysis = new Analysis(); while (stream.hasNext()) { - comp = analysis.ParseNextObject(stream, this.components); + comp = analysis.parseNextObject(stream, this.components); if (comp == null) { // To Ensure Continue Analysis byte next1 = stream.readByte(); diff --git a/FormatPDF/src/main/java/org/freeinternals/format/pdf/StartXRef.java b/FormatPDF/src/main/java/org/freeinternals/format/pdf/StartXRef.java index f506359..8559e49 100644 --- a/FormatPDF/src/main/java/org/freeinternals/format/pdf/StartXRef.java +++ b/FormatPDF/src/main/java/org/freeinternals/format/pdf/StartXRef.java @@ -37,7 +37,7 @@ public class StartXRef extends FileComponent implements GenerateTreeNode { super.startPos = stream.getPos() - line.length(); this.HeaderLine = line; this.OffsetLine = stream.readASCIILine(); - this.Offset = Integer.valueOf(this.OffsetLine.Line); + this.Offset = Integer.parseInt(this.OffsetLine.Line); super.length = stream.getPos() - super.startPos; } diff --git a/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Analysis.java b/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Analysis.java index 8a40bcc..290678f 100644 --- a/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Analysis.java +++ b/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Analysis.java @@ -15,7 +15,7 @@ */ public class Analysis { - public FileComponent ParseNextObject(PosDataInputStream stream, List components) throws IOException { + public FileComponent parseNextObject(PosDataInputStream stream, List components) throws IOException { FileComponent comp; byte next1 = stream.readByte(); byte next2; diff --git a/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Array.java b/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Array.java index 9ca97a4..670dc75 100644 --- a/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Array.java +++ b/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Array.java @@ -43,7 +43,7 @@ private void parse(PosDataInputStream stream) throws IOException { byte next1; while (stream.hasNext()) { - comp = analysis.ParseNextObject(stream, this.components); + comp = analysis.parseNextObject(stream, this.components); if (comp == null) { next1 = stream.readByte(); if (next1 == PDFStatics.DelimiterCharacter.RS) { diff --git a/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Boolean.java b/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Boolean.java index 240f298..897d060 100644 --- a/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Boolean.java +++ b/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Boolean.java @@ -16,8 +16,8 @@ */ public final class Boolean extends FileComponent implements GenerateTreeNode { - public static String VALUE_TRUE = "true"; - public static String VALUE_FALSE = "false"; + public static final String VALUE_TRUE = "true"; + public static final String VALUE_FALSE = "false"; /** * Name text in * Raw format. diff --git a/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Dictionary.java b/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Dictionary.java index 839f84b..a89749e 100644 --- a/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Dictionary.java +++ b/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Dictionary.java @@ -77,7 +77,7 @@ private void parse(PosDataInputStream stream) throws IOException { byte next2; boolean stop = false; while (stream.hasNext()) { - comp = analysis.ParseNextObject(stream, this.components); + comp = analysis.parseNextObject(stream, this.components); if (comp == null) { next1 = stream.readByte(); switch (next1) { diff --git a/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Null.java b/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Null.java index 75dc6ce..81d3781 100644 --- a/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Null.java +++ b/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Null.java @@ -16,7 +16,7 @@ */ public final class Null extends FileComponent implements GenerateTreeNode { - public static String VALUE = "null"; + public static final String VALUE = "null"; /** * Name text in * Raw format. diff --git a/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Stream.java b/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Stream.java index 24316d3..1e4726d 100644 --- a/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Stream.java +++ b/FormatPDF/src/main/java/org/freeinternals/format/pdf/basicobj/Stream.java @@ -24,12 +24,12 @@ public class Stream extends FileComponent implements GenerateTreeNode { /** * The signature length. */ - public final int SignatureLen; - public ASCIILine SignatureEnd = null; + public final int signatureLen; + public ASCIILine signatureEnd = null; public Stream(PosDataInputStream stream, PosDataInputStream.ASCIILine line) throws IOException, FileFormatException { - this.SignatureLen = SIGNATURE_START.length() + line.NewLineLength; - super.startPos = stream.getPos() - this.SignatureLen; + this.signatureLen = SIGNATURE_START.length() + line.NewLineLength; + super.startPos = stream.getPos() - this.signatureLen; this.parse(stream); this.length = stream.getPos() - super.startPos; } @@ -39,11 +39,11 @@ private void parse(PosDataInputStream stream) throws IOException, FileFormatExce while (stream.hasNext()) { line = stream.readASCIILine(); if (line.Line.endsWith(Stream.SIGNATURE_END)) { - this.SignatureEnd = line; + this.signatureEnd = line; } } - if (this.SignatureEnd == null) { + if (this.signatureEnd == null) { throw new FileFormatException(String.format( "The 'endstream' tag is not found for current object. Object Start Offset = %d, Current Offset = %d", super.startPos, @@ -65,7 +65,7 @@ public int getStreamStartPos() { * endstream.

*/ public int getStreamLength() { - return this.length - this.SignatureLen - 1 - this.SignatureEnd.length(); + return this.length - this.signatureLen - 1 - this.signatureEnd.length(); } public void generateTreeNode(DefaultMutableTreeNode parentNode) { @@ -85,9 +85,9 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode) { nodeStream.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( pos, - this.SignatureLen - SIGNATURE_START.length(), + this.signatureLen - SIGNATURE_START.length(), Texts.NewLine))); - pos += (this.SignatureLen - SIGNATURE_START.length()); + pos += (this.signatureLen - SIGNATURE_START.length()); nodeStream.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( pos, @@ -103,13 +103,13 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode) { nodeStream.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( pos, - this.SignatureEnd.Line.length(), + this.signatureEnd.Line.length(), Texts.Signature + SIGNATURE_END))); - pos += this.SignatureEnd.Line.length(); + pos += this.signatureEnd.Line.length(); nodeStream.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( pos, - this.SignatureEnd.NewLineLength, + this.signatureEnd.NewLineLength, Texts.NewLine))); parentNode.add(nodeStream); diff --git a/FormatZIP/src/main/java/org/freeinternals/format/zip/CentralDirectoryStructure.java b/FormatZIP/src/main/java/org/freeinternals/format/zip/CentralDirectoryStructure.java index 82b5cee..4e79a43 100644 --- a/FormatZIP/src/main/java/org/freeinternals/format/zip/CentralDirectoryStructure.java +++ b/FormatZIP/src/main/java/org/freeinternals/format/zip/CentralDirectoryStructure.java @@ -54,7 +54,7 @@ public class CentralDirectoryStructure extends FileComponent { * file comment (variable size) * */ - public class FileHeader { + public static class FileHeader { public final byte[] Signature = new byte[4]; public final int VersionMadeBy; @@ -114,45 +114,81 @@ public class FileHeader { public final byte[] FileComment; FileHeader(PosDataInputStream stream) throws IOException, FileFormatException { - stream.read(this.Signature); + int readBytes = stream.read(this.Signature); + if (readBytes != this.Signature.length) { + throw new IOException(String.format("Failed to read %d bytes, actual bytes read %d", this.Signature.length, readBytes)); + } if (BytesTool.isByteArraySame(this.Signature, ZIPFile.CENTRAL_FILE_HEADER) == false) { throw new FileFormatException("Signature does not match for 'central file header signature'."); } + this.VersionMadeBy = stream.readUnsignedShortInLittleEndian(); this.VersionNeededToExtract = stream.readUnsignedShortInLittleEndian(); - stream.read(this.GeneralPurposeBitFlag); + + readBytes = stream.read(this.GeneralPurposeBitFlag); + if (readBytes != this.GeneralPurposeBitFlag.length) { + throw new IOException(String.format("Failed to read %d bytes, actual bytes read %d", this.GeneralPurposeBitFlag.length, readBytes)); + } + this.CompressionMethod = stream.readUnsignedShortInLittleEndian(); this.LastModFileTime = stream.readUnsignedShortInLittleEndian(); this.LastModFileTimeValue = new MSDosTime(this.LastModFileTime); this.LastModFileDate = stream.readUnsignedShortInLittleEndian(); this.LastModFileDateValue = new MSDosDate(this.LastModFileDate); - stream.read(this.CRC32); + + readBytes = stream.read(this.CRC32); + if (readBytes != this.CRC32.length) { + throw new IOException(String.format("Failed to read %d bytes, actual bytes read %d", this.CRC32.length, readBytes)); + } + this.CompressedSize = stream.readUnsignedIntInLittleEndian(); this.UncompressedSize = stream.readUnsignedIntInLittleEndian(); this.FileNameLength = stream.readUnsignedShortInLittleEndian(); this.ExtraFieldLength = stream.readUnsignedShortInLittleEndian(); this.FileCommentLength = stream.readUnsignedShortInLittleEndian(); this.DiskNumberStart = stream.readUnsignedShortInLittleEndian(); - stream.read(this.InternalFileAttributes); - stream.read(this.ExternalFileAttributes); + + readBytes = stream.read(this.InternalFileAttributes); + if (readBytes != this.InternalFileAttributes.length) { + throw new IOException(String.format("Failed to read %d bytes, actual bytes read %d", this.InternalFileAttributes.length, readBytes)); + } + + readBytes = stream.read(this.ExternalFileAttributes); + if (readBytes != this.ExternalFileAttributes.length) { + throw new IOException(String.format("Failed to read %d bytes, actual bytes read %d", this.ExternalFileAttributes.length, readBytes)); + } + this.RelativeOffsetOfLocalHeader = stream.readUnsignedIntInLittleEndian(); + if (this.FileNameLength > 0) { this.FileName = new byte[this.FileNameLength]; - stream.read(this.FileName); + readBytes = stream.read(this.FileName); + if (readBytes != this.FileName.length) { + throw new IOException(String.format("Failed to read %d bytes, actual bytes read %d", this.FileName.length, readBytes)); + } + this.FileNameValue = new String(this.FileName, Charset.forName("UTF-8")); // Not working for WinRAR zip Chinese file name } else { this.FileName = null; - this.FileNameValue = ""; // We are not using NULL to make smaller dump + this.FileNameValue = ""; // We are not using NULL to avoid Exception } + if (this.ExtraFieldLength > 0) { this.ExtraField = new byte[this.ExtraFieldLength]; - stream.read(this.ExtraField); + readBytes = stream.read(this.ExtraField); + if (readBytes != this.ExtraField.length) { + throw new IOException(String.format("Failed to read %d bytes, actual bytes read %d", this.ExtraField.length, readBytes)); + } } else { this.ExtraField = null; } + if (this.FileCommentLength > 0) { this.FileComment = new byte[this.FileCommentLength]; - stream.read(this.FileComment); + readBytes = stream.read(this.FileComment); + if (readBytes != this.FileComment.length) { + throw new IOException(String.format("Failed to read %d bytes, actual bytes read %d", this.FileComment.length, readBytes)); + } } else { this.FileComment = null; } diff --git a/FormatZIP/src/main/java/org/freeinternals/format/zip/EndOfCentralDirectoryRecord.java b/FormatZIP/src/main/java/org/freeinternals/format/zip/EndOfCentralDirectoryRecord.java index 2c81a13..04cfec6 100644 --- a/FormatZIP/src/main/java/org/freeinternals/format/zip/EndOfCentralDirectoryRecord.java +++ b/FormatZIP/src/main/java/org/freeinternals/format/zip/EndOfCentralDirectoryRecord.java @@ -52,7 +52,12 @@ public class EndOfCentralDirectoryRecord extends FileComponent { EndOfCentralDirectoryRecord(PosDataInputStream stream) throws IOException, FileFormatException { this.startPos = stream.getPos(); - stream.read(this.Signature); + + int readBytes = stream.read(this.Signature); + if (readBytes != this.Signature.length) { + throw new IOException(String.format("Failed to read %d bytes, actual bytes read %d", this.Signature.length, readBytes)); + } + if (BytesTool.isByteArraySame(this.Signature, ZIPFile.CENTRAL_END) == false) { throw new FileFormatException("Signature does not match for 'end of central directory signature'."); } @@ -65,7 +70,11 @@ public class EndOfCentralDirectoryRecord extends FileComponent { this.ZipFileCommentLength = stream.readUnsignedShortInLittleEndian(); if (this.ZipFileCommentLength > 0) { this.ZipFileComment = new byte[this.ZipFileCommentLength]; - stream.read(this.ZipFileComment); + + readBytes = stream.read(this.ZipFileComment); + if (readBytes != this.ZipFileComment.length) { + throw new IOException(String.format("Failed to read %d bytes, actual bytes read %d", this.ZipFileComment.length, readBytes)); + } } else { this.ZipFileComment = null; } diff --git a/FormatZIP/src/main/java/org/freeinternals/format/zip/LocalFileHeader.java b/FormatZIP/src/main/java/org/freeinternals/format/zip/LocalFileHeader.java index a305de4..e404afc 100644 --- a/FormatZIP/src/main/java/org/freeinternals/format/zip/LocalFileHeader.java +++ b/FormatZIP/src/main/java/org/freeinternals/format/zip/LocalFileHeader.java @@ -49,7 +49,7 @@ public class LocalFileHeader extends FileComponent { public final int LastModFileTime; /** * Parsed value of {@link #LastModFileTime}. - * + * * @see #LastModFileTime */ public final MSDosTime LastModFileTimeValue; @@ -75,7 +75,7 @@ public class LocalFileHeader extends FileComponent { public final byte[] FileName; /** * Parsed value of {@link #FileName}. - * + * * @see #FileName */ public final String FileNameValue; @@ -84,26 +84,46 @@ public class LocalFileHeader extends FileComponent { LocalFileHeader(PosDataInputStream stream) throws IOException, FileFormatException { this.startPos = stream.getPos(); - stream.read(this.Signature); + + int readBytes = stream.read(this.Signature); + if (readBytes != this.Signature.length) { + throw new IOException(String.format("Failed to read %d bytes, actual bytes read %d", this.Signature.length, readBytes)); + } + if (BytesTool.isByteArraySame(this.Signature, ZIPFile.LOCAL_FILE_HEADER) == false) { throw new FileFormatException("Signature does not match for 'local file header signature'."); } + this.VersionNeededToExtract = stream.readUnsignedShortInLittleEndian(); - stream.read(this.GeneralPurposeBitFlag); + + readBytes = stream.read(this.GeneralPurposeBitFlag); + if (readBytes != this.GeneralPurposeBitFlag.length) { + throw new IOException(String.format("Failed to read %d bytes, actual bytes read %d", this.GeneralPurposeBitFlag.length, readBytes)); + } + this.CompressionMethod = stream.readUnsignedShortInLittleEndian(); this.LastModFileTime = stream.readUnsignedShortInLittleEndian(); this.LastModFileTimeValue = new MSDosTime(this.LastModFileTime); this.LastModFileDate = stream.readUnsignedShortInLittleEndian(); this.LastModFileDateValue = new MSDosDate(this.LastModFileDate); - stream.read(this.CRC32); + + readBytes = stream.read(this.CRC32); + if (readBytes != this.CRC32.length) { + throw new IOException(String.format("Failed to read %d bytes, actual bytes read %d", this.CRC32.length, readBytes)); + } + this.CompressedSize = stream.readUnsignedIntInLittleEndian(); this.UncompressedSize = stream.readUnsignedIntInLittleEndian(); this.FileNameLength = stream.readUnsignedShortInLittleEndian(); this.ExtraFieldLength = stream.readUnsignedShortInLittleEndian(); if (this.FileNameLength > 0) { this.FileName = new byte[this.FileNameLength]; - stream.read(this.FileName); - PosDataInputStream utf8 = new PosDataInputStream(new PosByteArrayInputStream(this.FileName)); + readBytes = stream.read(this.FileName); + if (readBytes != this.FileName.length) { + throw new IOException(String.format("Failed to read %d bytes, actual bytes read %d", this.FileName.length, readBytes)); + } + + // PosDataInputStream utf8 = new PosDataInputStream(new PosByteArrayInputStream(this.FileName)); // this.FileNameValue = utf8.readUTF(); // Failed: EOFException // this.FileNameValue = new String(this.FileName); // TODO - This logic is not working for Chinese charactor // this.FileNameValue = new String(this.FileName, Charset.forName("ISO-8859-1"));// Not working for WinRAR zip Chinese file name @@ -117,7 +137,10 @@ public class LocalFileHeader extends FileComponent { } if (this.ExtraFieldLength > 0) { this.ExtraField = new byte[this.ExtraFieldLength]; - stream.read(this.ExtraField); + readBytes = stream.read(this.ExtraField); + if (readBytes != this.ExtraField.length) { + throw new IOException(String.format("Failed to read %d bytes, actual bytes read %d", this.ExtraField.length, readBytes)); + } } else { this.ExtraField = null; } diff --git a/FormatZIP/src/main/java/org/freeinternals/format/zip/ZIPFile.java b/FormatZIP/src/main/java/org/freeinternals/format/zip/ZIPFile.java index 6791fe8..005bd56 100644 --- a/FormatZIP/src/main/java/org/freeinternals/format/zip/ZIPFile.java +++ b/FormatZIP/src/main/java/org/freeinternals/format/zip/ZIPFile.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.util.Iterator; import javax.swing.tree.DefaultMutableTreeNode; +import org.freeinternals.commonlib.core.BytesTool; import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.core.FileComponent; import org.freeinternals.commonlib.core.PosByteArrayInputStream; @@ -31,11 +32,11 @@ public class ZIPFile extends FileFormat { * Central file header signature of File header in Central directory * structure. */ - public static final byte[] CENTRAL_FILE_HEADER = {(byte) 0x50, (byte) 0x4B, (byte) 0x01, (byte) 0x02}; + static final byte[] CENTRAL_FILE_HEADER = {(byte) 0x50, (byte) 0x4B, (byte) 0x01, (byte) 0x02}; /** * Local file header signature in Local file header. */ - public static final byte[] LOCAL_FILE_HEADER = {(byte) 0x50, (byte) 0x4B, (byte) 0x03, (byte) 0x04}; + static final byte[] LOCAL_FILE_HEADER = {(byte) 0x50, (byte) 0x4B, (byte) 0x03, (byte) 0x04}; /** * Header signature of Digital signature in Central directory structure. */ @@ -43,7 +44,7 @@ public class ZIPFile extends FileFormat { /** * End of central dir signature in End of central directory record. */ - public static final byte[] CENTRAL_END = {(byte) 0x50, (byte) 0x4B, (byte) 0x05, (byte) 0x06}; + static final byte[] CENTRAL_END = {(byte) 0x50, (byte) 0x4B, (byte) 0x05, (byte) 0x06}; /** * Signature in Zip64 end of central directory record. */ @@ -90,7 +91,7 @@ private void parse() throws IOException, FileFormatException { return; } stream.reset(); - stream.skip(this.cde.CentralDirectoryOffset); + BytesTool.skip(stream, this.cde.CentralDirectoryOffset); this.cds = new CentralDirectoryStructure[this.cde.EntryTotalNumber]; for (int i = 0; i < this.cds.length; i++) { this.cds[i] = new CentralDirectoryStructure(stream); @@ -100,7 +101,7 @@ private void parse() throws IOException, FileFormatException { this.lfh = new LocalFileHeader[this.cds.length]; for (int i = 0; i < this.cds.length; i++) { stream.reset(); - stream.skip(this.cds[i].header.RelativeOffsetOfLocalHeader); + BytesTool.skip(stream, this.cds[i].header.RelativeOffsetOfLocalHeader); this.lfh[i] = new LocalFileHeader(stream); } @@ -140,12 +141,12 @@ public void generateTreeNode(DefaultMutableTreeNode root) { // Generate the tree nodes if (value instanceof LocalFileHeader) { - GenerateTreeNode_LFH.LocalFileHeader((LocalFileHeader) value, root); + GenerateTreeNode_LFH.localFileHeader((LocalFileHeader) value, root); lastPos = (int) (lastPos + ((LocalFileHeader) value).getSizeWithFileData()); } else if (value instanceof CentralDirectoryStructure) { - GenerateTreeNode_CDS.CentralDirectoryStructure((CentralDirectoryStructure) value, root); + GenerateTreeNode_CDS.centralDirectoryStructure((CentralDirectoryStructure) value, root); } else if (value instanceof EndOfCentralDirectoryRecord) { - GenerateTreeNode_CDE.EndOfCentralDirectoryRecord((EndOfCentralDirectoryRecord) value, root); + GenerateTreeNode_CDE.endOfCentralDirectoryRecord((EndOfCentralDirectoryRecord) value, root); } else { root.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( lastPos, diff --git a/FormatZIP/src/main/java/org/freeinternals/format/zip/ui/biv/GenerateTreeNode_CDE.java b/FormatZIP/src/main/java/org/freeinternals/format/zip/ui/biv/GenerateTreeNode_CDE.java index a62f112..8b4f5bd 100644 --- a/FormatZIP/src/main/java/org/freeinternals/format/zip/ui/biv/GenerateTreeNode_CDE.java +++ b/FormatZIP/src/main/java/org/freeinternals/format/zip/ui/biv/GenerateTreeNode_CDE.java @@ -16,7 +16,7 @@ */ public class GenerateTreeNode_CDE { - public static void EndOfCentralDirectoryRecord( + public static void endOfCentralDirectoryRecord( EndOfCentralDirectoryRecord cde, DefaultMutableTreeNode parent) { diff --git a/FormatZIP/src/main/java/org/freeinternals/format/zip/ui/biv/GenerateTreeNode_CDS.java b/FormatZIP/src/main/java/org/freeinternals/format/zip/ui/biv/GenerateTreeNode_CDS.java index 6e5211a..ab507e0 100644 --- a/FormatZIP/src/main/java/org/freeinternals/format/zip/ui/biv/GenerateTreeNode_CDS.java +++ b/FormatZIP/src/main/java/org/freeinternals/format/zip/ui/biv/GenerateTreeNode_CDS.java @@ -16,7 +16,7 @@ */ public class GenerateTreeNode_CDS { - public static void CentralDirectoryStructure( + public static void centralDirectoryStructure( CentralDirectoryStructure cds, DefaultMutableTreeNode parent) { diff --git a/FormatZIP/src/main/java/org/freeinternals/format/zip/ui/biv/GenerateTreeNode_LFH.java b/FormatZIP/src/main/java/org/freeinternals/format/zip/ui/biv/GenerateTreeNode_LFH.java index 872f856..99da4b9 100644 --- a/FormatZIP/src/main/java/org/freeinternals/format/zip/ui/biv/GenerateTreeNode_LFH.java +++ b/FormatZIP/src/main/java/org/freeinternals/format/zip/ui/biv/GenerateTreeNode_LFH.java @@ -21,7 +21,7 @@ public class GenerateTreeNode_LFH { /** * Generate tree nodes for local file header, as well as file data. */ - public static void LocalFileHeader( + public static void localFileHeader( LocalFileHeader lfh, DefaultMutableTreeNode parent) { diff --git a/pom.xml b/pom.xml index 64344cb..101ff90 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,15 @@ UTF-8 + + + com.github.spotbugs + spotbugs-annotations + 3.1.12 + jar + + +