pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1834047 - in /pdfbox/branches/1.8/fontbox/src: main/java/org/apache/fontbox/afm/AFMParser.java test/java/org/apache/fontbox/afm/ test/java/org/apache/fontbox/afm/AFMParserTest.java
Date Thu, 21 Jun 2018 19:45:11 GMT
Author: tilman
Date: Thu Jun 21 19:45:11 2018
New Revision: 1834047

URL: http://svn.apache.org/viewvc?rev=1834047&view=rev
Log:
PDFBOX-4071: clarify code + test

Added:
    pdfbox/branches/1.8/fontbox/src/test/java/org/apache/fontbox/afm/
    pdfbox/branches/1.8/fontbox/src/test/java/org/apache/fontbox/afm/AFMParserTest.java  
(with props)
Modified:
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/afm/AFMParser.java

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/afm/AFMParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/afm/AFMParser.java?rev=1834047&r1=1834046&r2=1834047&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/afm/AFMParser.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/afm/AFMParser.java Thu Jun
21 19:45:11 2018
@@ -998,9 +998,11 @@ public class AFMParser
         buf.append( (char)nextByte );
 
         //now read the data
-        while( !isEOL(nextByte = input.read()) )
+        nextByte = input.read();
+        while (nextByte != -1 && !isEOL(nextByte))
         {
-            buf.append( (char)nextByte );
+            buf.append((char) nextByte);
+            nextByte = input.read();
         }
         return buf.toString();
     }
@@ -1025,9 +1027,11 @@ public class AFMParser
         buf.append( (char)nextByte );
 
         //now read the data
-        while( !isWhitespace(nextByte = input.read()) )
+        nextByte = input.read();
+        while (nextByte != -1 && !isWhitespace(nextByte))
         {
-            buf.append( (char)nextByte );
+            buf.append((char) nextByte);
+            nextByte = input.read();
         }
         return buf.toString();
     }

Added: pdfbox/branches/1.8/fontbox/src/test/java/org/apache/fontbox/afm/AFMParserTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/test/java/org/apache/fontbox/afm/AFMParserTest.java?rev=1834047&view=auto
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/test/java/org/apache/fontbox/afm/AFMParserTest.java (added)
+++ pdfbox/branches/1.8/fontbox/src/test/java/org/apache/fontbox/afm/AFMParserTest.java Thu
Jun 21 19:45:11 2018
@@ -0,0 +1,43 @@
+/*
+ * 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.afm;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ * @author Tilman Hausherr
+ */
+public class AFMParserTest
+{
+    @Test
+    public void testEof() throws IOException
+    {
+        try
+        {
+            new AFMParser(new ByteArrayInputStream("huhu".getBytes())).parse();
+        }
+        catch (IOException ex)
+        {
+            Assert.assertEquals("Error: The AFM file should start with StartFontMetrics and
not 'huhu'", ex.getMessage());
+        }
+    }
+}

Propchange: pdfbox/branches/1.8/fontbox/src/test/java/org/apache/fontbox/afm/AFMParserTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message