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


The following commit(s) were added to refs/heads/master by this push:
     new c4dfa227 Use constant instead of magic string
c4dfa227 is described below

commit c4dfa22724a5a792203f53e429d1750a671d33b2
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sun Dec 10 11:00:08 2023 -0500

    Use constant instead of magic string
---
 .../apache/commons/imaging/formats/jpeg/segments/ComSegment.java | 9 +++------
 .../commons/imaging/formats/jpeg/segments/GenericSegment.java    | 8 ++------
 2 files changed, 5 insertions(+), 12 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/ComSegment.java
 
b/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/ComSegment.java
index d897eee3..2b311e90 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/ComSegment.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/ComSegment.java
@@ -19,6 +19,7 @@ package org.apache.commons.imaging.formats.jpeg.segments;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
 
 public class ComSegment extends GenericSegment {
     public ComSegment(final int marker, final byte[] segmentData) {
@@ -31,6 +32,7 @@ public class ComSegment extends GenericSegment {
 
     /**
      * Returns a copy of the comment.
+     * 
      * @return a copy of the comment's bytes
      */
     public byte[] getComment() {
@@ -39,12 +41,7 @@ public class ComSegment extends GenericSegment {
 
     @Override
     public String getDescription() {
-        String commentString = "";
-        try {
-            commentString = getSegmentDataAsString("UTF-8");
-        } catch (final UnsupportedEncodingException cannotHappen) { // NOPMD
-        }
-        return "COM (" + commentString + ")";
+        return "COM (" + getSegmentDataAsString(StandardCharsets.UTF_8) + ")";
     }
 
 }
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/GenericSegment.java
 
b/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/GenericSegment.java
index ea5977a1..bb4ceeae 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/GenericSegment.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/GenericSegment.java
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintWriter;
 import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
 
 public abstract class GenericSegment extends AbstractSegment {
     private final byte[] segmentData;
@@ -75,14 +76,9 @@ public abstract class GenericSegment extends AbstractSegment 
{
      * Convert the bytes to a String
      * @param encoding segment encoding
      * @return the encoded bytes
-     * @throws UnsupportedEncodingException if the encoding provided is not 
supported
      */
-    public String getSegmentDataAsString(final String encoding) throws 
UnsupportedEncodingException {
+    public String getSegmentDataAsString(final Charset encoding) {
         return new String(segmentData, encoding);
     }
 
-    // public String getDescription()
-    // {
-    // return "Unknown";
-    // }
 }

Reply via email to