pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1614078 - in /pdfbox/trunk/fontbox/src: main/java/org/apache/fontbox/ttf/MemoryTTFDataStream.java test/java/org/apache/fontbox/ttf/TestMemoryTTFDataStream.java
Date Mon, 28 Jul 2014 17:11:29 GMT
Author: lehmi
Date: Mon Jul 28 17:11:29 2014
New Revision: 1614078

URL: http://svn.apache.org/r1614078
Log:
PDFBOX-2212: fixed the EOF-detection as proposed by Tilman Hausherr, added an unit test to
demonstrate the fix

Added:
    pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/TestMemoryTTFDataStream.java
  (with props)
Modified:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/MemoryTTFDataStream.java

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/MemoryTTFDataStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/MemoryTTFDataStream.java?rev=1614078&r1=1614077&r2=1614078&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/MemoryTTFDataStream.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/MemoryTTFDataStream.java Mon
Jul 28 17:11:29 2014
@@ -25,8 +25,8 @@ import java.io.InputStream;
 /**
  * An interface into a data stream.
  * 
- * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.2 $
+ * @author Ben Litchfield
+ * 
  */
 public class MemoryTTFDataStream extends TTFDataStream 
 {
@@ -98,11 +98,11 @@ public class MemoryTTFDataStream extends
      */
     public int read() throws IOException
     {
-        int retval = -1;
-        if( currentPosition < data.length )
+        if (currentPosition >= data.length)
         {
-            retval = data[currentPosition];
+            return -1;
         }
+        int retval = data[currentPosition];
         currentPosition++;
         return (retval+256)%256;
     }

Added: pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/TestMemoryTTFDataStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/TestMemoryTTFDataStream.java?rev=1614078&view=auto
==============================================================================
--- pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/TestMemoryTTFDataStream.java
(added)
+++ pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/TestMemoryTTFDataStream.java
Mon Jul 28 17:11:29 2014
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.fontbox.ttf;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import org.junit.Test;
+
+import junit.framework.TestCase;
+
+public class TestMemoryTTFDataStream extends TestCase
+{
+    @Test
+    public void testEOF() throws IOException
+    {
+        byte[] byteArray = new byte[10];
+        ByteArrayInputStream inputStream = new ByteArrayInputStream(byteArray);
+        MemoryTTFDataStream dataStream = new MemoryTTFDataStream(inputStream);
+        int value = dataStream.read();
+        try
+        {
+            while (value > -1)
+            {
+                value = dataStream.read();
+            }
+        }
+        catch (ArrayIndexOutOfBoundsException exception)
+        {
+            fail("EOF not detected!");
+        }
+        finally
+        {
+            if (dataStream != null)
+            {
+                dataStream.close();
+            }
+        }
+    }
+
+}

Propchange: pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/TestMemoryTTFDataStream.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message