You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2019/08/19 16:42:13 UTC

svn commit: r1865484 - /pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/cos/COSString.java

Author: tilman
Date: Mon Aug 19 16:42:13 2019
New Revision: 1865484

URL: http://svn.apache.org/viewvc?rev=1865484&view=rev
Log:
PDFBOX-4071: avoid throwing RuntimeException

Modified:
    pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/cos/COSString.java

Modified: pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/cos/COSString.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/cos/COSString.java?rev=1865484&r1=1865483&r2=1865484&view=diff
==============================================================================
--- pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/cos/COSString.java (original)
+++ pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/cos/COSString.java Mon Aug 19 16:42:13 2019
@@ -92,19 +92,10 @@ public final class COSString extends COS
         {
             // UTF-16BE encoded string with a leading byte order marker
             byte[] data = text.getBytes(Charsets.UTF_16BE);
-            ByteArrayOutputStream out = new ByteArrayOutputStream(data.length + 2);
-            out.write(0xFE); // BOM
-            out.write(0xFF); // BOM
-            try
-            {
-                out.write(data);
-            }
-            catch (IOException e)
-            {
-                // should never happen
-                throw new RuntimeException(e);
-            }
-            bytes = out.toByteArray();
+            bytes = new byte[data.length + 2];
+            bytes[0] = (byte) 0xFE;
+            bytes[1] = (byte) 0xFF;
+            System.arraycopy(data, 0, bytes, 2, data.length);
         }
     }