commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1294794 - in /commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats: png/PngConstants.java png/PngWriter.java psd/PsdConstants.java
Date Tue, 28 Feb 2012 19:16:15 GMT
Author: damjan
Date: Tue Feb 28 19:16:15 2012
New Revision: 1294794

URL: http://svn.apache.org/viewvc?rev=1294794&view=rev
Log:
Do not allow final arrays to be mutated.
This completes the changeset for SANSELAN-42
by getting rid of all public static final arrays
(at least, as found by FindBugs).

Jira issue key: SANSELAN-42


Modified:
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/png/PngConstants.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/png/PngWriter.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/psd/PsdConstants.java

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/png/PngConstants.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/png/PngConstants.java?rev=1294794&r1=1294793&r2=1294794&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/png/PngConstants.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/png/PngConstants.java
Tue Feb 28 19:16:15 2012
@@ -17,6 +17,7 @@
 package org.apache.commons.sanselan.formats.png;
 
 import org.apache.commons.sanselan.SanselanConstants;
+import org.apache.commons.sanselan.common.BinaryConstant;
 import org.apache.commons.sanselan.common.BinaryFileFunctions;
 
 public interface PngConstants extends SanselanConstants
@@ -24,28 +25,28 @@ public interface PngConstants extends Sa
 
     public static final int COMPRESSION_DEFLATE_INFLATE = 0;
 
-    public final static byte[] IHDR_CHUNK_TYPE = new byte[] { 73, 72, 68, 82 };
-    public final static byte[] PLTE_CHUNK_TYPE = new byte[] { 80, 76, 84, 69 };
-    public final static byte[] IEND_CHUNK_TYPE = new byte[] { 73, 69, 78, 68 };
-    public final static byte[] IDAT_CHUNK_TYPE = new byte[] { 73, 68, 65, 84 };
-    public final static byte[] iTXt_CHUNK_TYPE = new byte[] { //
+    public final static BinaryConstant IHDR_CHUNK_TYPE = new BinaryConstant(new byte[] {
73, 72, 68, 82 });
+    public final static BinaryConstant PLTE_CHUNK_TYPE = new BinaryConstant(new byte[] {
80, 76, 84, 69 });
+    public final static BinaryConstant IEND_CHUNK_TYPE = new BinaryConstant(new byte[] {
73, 69, 78, 68 });
+    public final static BinaryConstant IDAT_CHUNK_TYPE = new BinaryConstant(new byte[] {
73, 68, 65, 84 });
+    public final static BinaryConstant iTXt_CHUNK_TYPE = new BinaryConstant(new byte[] {
//
             105, //
             84, //
             88, //
             116, //
-    };
-    public final static byte[] tEXt_CHUNK_TYPE = new byte[] { //
+    });
+    public final static BinaryConstant tEXt_CHUNK_TYPE = new BinaryConstant(new byte[] {
//
             0x74, //
             0x45, //
             0x58, //
             0x74, //
-    };
-    public final static byte[] zTXt_CHUNK_TYPE = new byte[] { //
+    });
+    public final static BinaryConstant zTXt_CHUNK_TYPE = new BinaryConstant(new byte[] {
//
             0x7A, //
             0x54, //
             0x58, //
             0x74, //
-    };
+    });
 
     public final static int IEND = BinaryFileFunctions.charsToQuad('I', 'E', 'N',
             'D');
@@ -74,8 +75,8 @@ public interface PngConstants extends Sa
     public final static int iTXt = BinaryFileFunctions.charsToQuad('i', 'T', 'X',
             't');
 
-    public static final byte PNG_Signature[] = {
-        (byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, };
+    public static final BinaryConstant PNG_Signature = new BinaryConstant(new byte[]{
+        (byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, });
 
     public static final String PARAM_KEY_PNG_BIT_DEPTH = "PNG_BIT_DEPTH";
     public static final String PARAM_KEY_PNG_FORCE_INDEXED_COLOR = "PNG_FORCE_INDEXED_COLOR";

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/png/PngWriter.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/png/PngWriter.java?rev=1294794&r1=1294793&r2=1294794&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/png/PngWriter.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/png/PngWriter.java
Tue Feb 28 19:16:15 2012
@@ -144,7 +144,7 @@ public class PngWriter implements PngCon
 
         // Debug.debug("baos", baos.toByteArray());
 
-        writeChunk(os, IHDR_CHUNK_TYPE, baos.toByteArray());
+        writeChunk(os, IHDR_CHUNK_TYPE.toByteArray(), baos.toByteArray());
     }
 
     private void writeChunkiTXt(OutputStream os, PngText.iTXt text)
@@ -177,7 +177,7 @@ public class PngWriter implements PngCon
 
         baos.write(new ZLibUtils().deflate(text.text.getBytes("utf-8")));
 
-        writeChunk(os, iTXt_CHUNK_TYPE, baos.toByteArray());
+        writeChunk(os, iTXt_CHUNK_TYPE.toByteArray(), baos.toByteArray());
     }
 
     private void writeChunkzTXt(OutputStream os, PngText.zTXt text)
@@ -204,7 +204,7 @@ public class PngWriter implements PngCon
                 .write(new ZLibUtils().deflate(text.text
                         .getBytes("ISO-8859-1")));
 
-        writeChunk(os, zTXt_CHUNK_TYPE, baos.toByteArray());
+        writeChunk(os, zTXt_CHUNK_TYPE.toByteArray(), baos.toByteArray());
     }
 
     private void writeChunktEXt(OutputStream os, PngText.tEXt text)
@@ -226,7 +226,7 @@ public class PngWriter implements PngCon
         // text
         baos.write(text.text.getBytes("ISO-8859-1"));
 
-        writeChunk(os, tEXt_CHUNK_TYPE, baos.toByteArray());
+        writeChunk(os, tEXt_CHUNK_TYPE.toByteArray(), baos.toByteArray());
     }
 
     private void writeChunkXmpiTXt(OutputStream os, String xmpXml)
@@ -250,7 +250,7 @@ public class PngWriter implements PngCon
 
         baos.write(new ZLibUtils().deflate(xmpXml.getBytes("utf-8")));
 
-        writeChunk(os, iTXt_CHUNK_TYPE, baos.toByteArray());
+        writeChunk(os, iTXt_CHUNK_TYPE.toByteArray(), baos.toByteArray());
     }
 
     private void writeChunkPLTE(OutputStream os, Palette palette)
@@ -270,18 +270,18 @@ public class PngWriter implements PngCon
             bytes[index + 2] = (byte) (0xff & (rgb >> 0));
         }
 
-        writeChunk(os, PLTE_CHUNK_TYPE, bytes);
+        writeChunk(os, PLTE_CHUNK_TYPE.toByteArray(), bytes);
     }
 
     private void writeChunkIEND(OutputStream os) throws IOException
     {
-        writeChunk(os, IEND_CHUNK_TYPE, null);
+        writeChunk(os, IEND_CHUNK_TYPE.toByteArray(), null);
     }
 
     private void writeChunkIDAT(OutputStream os, byte bytes[])
             throws IOException
     {
-        writeChunk(os, IDAT_CHUNK_TYPE, bytes);
+        writeChunk(os, IDAT_CHUNK_TYPE.toByteArray(), bytes);
     }
 
     private byte getColourType(boolean hasAlpha, boolean isGrayscale)
@@ -440,7 +440,7 @@ public class PngWriter implements PngCon
             Debug.debug("sample_depth", sampleDepth);
 
         {
-            os.write(PNG_Signature);
+            PNG_Signature.writeTo(os);
         }
         {
             // IHDR must be first

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/psd/PsdConstants.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/psd/PsdConstants.java?rev=1294794&r1=1294793&r2=1294794&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/psd/PsdConstants.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/psd/PsdConstants.java
Tue Feb 28 19:16:15 2012
@@ -20,7 +20,7 @@ import org.apache.commons.sanselan.util.
 
 public class PsdConstants
 {
-    public static final ImageResourceType fImageResourceTypes[];
+    static final ImageResourceType fImageResourceTypes[];
 
     public String getDescription(int id)
     {



Mime
View raw message