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 2016/11/29 18:02:12 UTC

svn commit: r1771934 - in /pdfbox/branches/2.0/fontbox/src: main/java/org/apache/fontbox/ttf/BufferedRandomAccessFile.java test/java/org/apache/fontbox/ttf/BufferedRandomAccessFileTest.java

Author: tilman
Date: Tue Nov 29 18:02:12 2016
New Revision: 1771934

URL: http://svn.apache.org/viewvc?rev=1771934&view=rev
Log:
PDFBOX-3605: return -1 on EOF, as suggested by Cameron Rollheiser

Added:
    pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/ttf/BufferedRandomAccessFileTest.java   (with props)
Modified:
    pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/BufferedRandomAccessFile.java

Modified: pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/BufferedRandomAccessFile.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/BufferedRandomAccessFile.java?rev=1771934&r1=1771933&r2=1771934&view=diff
==============================================================================
--- pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/BufferedRandomAccessFile.java (original)
+++ pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/BufferedRandomAccessFile.java Tue Nov 29 18:02:12 2016
@@ -165,7 +165,7 @@ public class BufferedRandomAccessFile ex
                 leftover += bytesRead;
             }
         }
-        return leftover;
+        return leftover > 0 ? leftover : -1;
     }
 
     /**

Added: pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/ttf/BufferedRandomAccessFileTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/ttf/BufferedRandomAccessFileTest.java?rev=1771934&view=auto
==============================================================================
--- pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/ttf/BufferedRandomAccessFileTest.java (added)
+++ pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/ttf/BufferedRandomAccessFileTest.java Tue Nov 29 18:02:12 2016
@@ -0,0 +1,60 @@
+package org.apache.fontbox.ttf;
+
+/*
+ * Copyright 2016 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Cameron Rollhieser
+ */
+public class BufferedRandomAccessFileTest
+{
+
+    /**
+     * Before solving PDFBOX-3605, this test never ended.
+     * 
+     * @throws IOException
+     */
+    @Test
+    public void ensureReadFinishes() throws IOException
+    {
+        final File file = File.createTempFile("apache-pdfbox", ".dat");
+
+        final OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
+        final String content = "1234567890";
+        outputStream.write(content.getBytes("UTF-8"));
+        outputStream.flush();
+        outputStream.close();
+
+        final byte[] readBuffer = new byte[2];
+        final BufferedRandomAccessFile buffer = new BufferedRandomAccessFile(file, "r", 4);
+
+        int amountRead;
+        int totalAmountRead = 0;
+        while ((amountRead = buffer.read(readBuffer, 0, 2)) != -1)
+        {
+            totalAmountRead += amountRead;
+        }
+        Assert.assertEquals(10, totalAmountRead);
+    }
+}

Propchange: pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/ttf/BufferedRandomAccessFileTest.java
------------------------------------------------------------------------------
    svn:eol-style = native