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 2024/02/10 13:15:47 UTC

svn commit: r1915710 - in /pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf: RandomAccessReadDataStream.java TTFDataStream.java

Author: tilman
Date: Sat Feb 10 13:15:46 2024
New Revision: 1915710

URL: http://svn.apache.org/viewvc?rev=1915710&view=rev
Log:
PDFBOX-5660: improve javadoc, as suggested by Dieter von Holten

Modified:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/RandomAccessReadDataStream.java
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFDataStream.java

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/RandomAccessReadDataStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/RandomAccessReadDataStream.java?rev=1915710&r1=1915709&r2=1915710&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/RandomAccessReadDataStream.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/RandomAccessReadDataStream.java Sat Feb 10 13:15:46 2024
@@ -24,7 +24,8 @@ import org.apache.pdfbox.io.RandomAccess
 
 /**
  * An implementation of the TTFDataStream using RandomAccessRead as source.
- * 
+ * The underlying RandomAccessRead can be any length, but this implementation supports
+ * only bufferLengths upto Integer.MAX_VALUE.
  */
 class RandomAccessReadDataStream extends TTFDataStream
 {
@@ -34,9 +35,9 @@ class RandomAccessReadDataStream extends
 
     /**
      * Constructor.
-     * 
+     *
      * @param randomAccessRead source to be read from
-     * 
+     *
      * @throws IOException If there is a problem reading the source data.
      */
     RandomAccessReadDataStream(RandomAccessRead randomAccessRead) throws IOException
@@ -51,12 +52,12 @@ class RandomAccessReadDataStream extends
             remainingBytes -= amountRead;
         }
     }
-    
+
     /**
      * Constructor.
-     * 
+     *
      * @param inputStream source to be read from
-     * 
+     *
      * @throws IOException If there is a problem reading the source data.
      */
     RandomAccessReadDataStream(InputStream inputStream) throws IOException
@@ -75,10 +76,10 @@ class RandomAccessReadDataStream extends
     {
         return currentPosition;
     }
-    
+
     /**
      * Close the underlying resources.
-     * 
+     *
      * @throws IOException If there is an error closing the resources.
      */
     @Override
@@ -86,10 +87,10 @@ class RandomAccessReadDataStream extends
     {
         // nothing to do
     }
-    
+
     /**
      * Read an unsigned byte.
-     * @return An unsigned byte.
+     * @return An unsigned byte, or -1, signalling 'no more data'
      * @throws IOException If there is an error reading the data.
      */
     @Override
@@ -101,10 +102,10 @@ class RandomAccessReadDataStream extends
         }
         return data[currentPosition++] & 0xff;
     }
-    
+
     /**
      * Read a signed 64-bit integer.
-     * 
+     *
      * @return eight bytes interpreted as a long.
      * @throws IOException If there is an error reading the data.
      */
@@ -116,8 +117,8 @@ class RandomAccessReadDataStream extends
 
     /**
      * Read a signed 32-bit integer.
-     * 
-     * @return 4 bytes interpreted as a int.
+     *
+     * @return 4 bytes interpreted as an int.
      * @throws IOException If there is an error reading the data.
      */
     private int readInt() throws IOException
@@ -130,7 +131,10 @@ class RandomAccessReadDataStream extends
     }
     /**
      * Seek into the datasource.
-     * 
+     * When the requested <code>pos</code> is &lt; 0, an IOException() is fired.
+     * When the requested <code>pos</code> is &ge; {@link #length}, the {@link #currentPosition}
+     * is set to the first byte <i>after</i> the {@link #data}!
+     *
      * @param pos The position to seek to.
      * @throws IOException If there is an error seeking to that position.
      */
@@ -143,16 +147,16 @@ class RandomAccessReadDataStream extends
         }
         currentPosition = pos < length ? (int) pos : (int) length;
     }
-    
+
     /**
      * @see java.io.InputStream#read( byte[], int, int )
-     * 
+     *
      * @param b The buffer to write to.
      * @param off The offset into the buffer.
      * @param len The length into the buffer.
-     * 
-     * @return The number of bytes read.
-     * 
+     *
+     * @return The number of bytes read or -1, signalling 'no more data'
+     *
      * @throws IOException If there is an error reading from the stream.
      */
     @Override
@@ -168,7 +172,7 @@ class RandomAccessReadDataStream extends
         currentPosition += bytesToRead;
         return bytesToRead;
     }
-    
+
     /**
      * {@inheritDoc}
      */

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFDataStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFDataStream.java?rev=1915710&r1=1915709&r2=1915710&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFDataStream.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFDataStream.java Sat Feb 10 13:15:46 2024
@@ -27,7 +27,7 @@ import java.util.TimeZone;
 
 /**
  * An abstract class to read a data stream.
- * 
+ *
  * @author Ben Litchfield
  */
 abstract class TTFDataStream implements Closeable
@@ -37,10 +37,10 @@ abstract class TTFDataStream implements
     TTFDataStream()
     {
     }
-    
+
     /**
      * Read a 16.16 fixed value, where the first 16 bits are the decimal and the last 16 bits are the fraction.
-     * 
+     *
      * @return A 32 bit value.
      * @throws IOException If there is an error reading the data.
      */
@@ -53,7 +53,7 @@ abstract class TTFDataStream implements
 
     /**
      * Read a fixed length ascii string.
-     * 
+     *
      * @param length The length of the string to read.
      * @return A string of the desired length.
      * @throws IOException If there is an error reading the data.
@@ -65,7 +65,7 @@ abstract class TTFDataStream implements
 
     /**
      * Read a fixed length string.
-     * 
+     *
      * @param length The length of the string to read in bytes.
      * @param charset The expected character set of the string.
      * @return A string of the desired length.
@@ -78,7 +78,7 @@ abstract class TTFDataStream implements
 
     /**
      * Read an unsigned byte.
-     * 
+     *
      * @return An unsigned byte.
      * @throws IOException If there is an error reading the data.
      */
@@ -86,7 +86,7 @@ abstract class TTFDataStream implements
 
     /**
      * Read an unsigned byte.
-     * 
+     *
      * @return An unsigned byte.
      * @throws IOException If there is an error reading the data.
      */
@@ -94,7 +94,7 @@ abstract class TTFDataStream implements
 
     /**
      * Read a signed byte.
-     * 
+     *
      * @return A signed byte.
      * @throws IOException If there is an error reading the data.
      */
@@ -105,9 +105,9 @@ abstract class TTFDataStream implements
     }
 
     /**
-     * Read a unsigned byte. Similar to {@link #read()}, but throws an exception if EOF is unexpectedly reached.
-     * 
-     * @return A unsigned byte.
+     * Read an unsigned byte. Similar to {@link #read()}, but throws an exception if EOF is unexpectedly reached.
+     *
+     * @return An unsigned byte.
      * @throws IOException If there is an error reading the data.
      */
     public int readUnsignedByte() throws IOException
@@ -122,7 +122,7 @@ abstract class TTFDataStream implements
 
     /**
      * Read an unsigned integer.
-     * 
+     *
      * @return An unsigned integer.
      * @throws IOException If there is an error reading the data.
      */
@@ -141,7 +141,7 @@ abstract class TTFDataStream implements
 
     /**
      * Read an unsigned short.
-     * 
+     *
      * @return An unsigned short.
      * @throws IOException If there is an error reading the data.
      */
@@ -158,7 +158,7 @@ abstract class TTFDataStream implements
 
     /**
      * Read an unsigned byte array.
-     * 
+     *
      * @param length the length of the array to be read
      * @return An unsigned byte array.
      * @throws IOException If there is an error reading the data.
@@ -175,7 +175,7 @@ abstract class TTFDataStream implements
 
     /**
      * Read an unsigned short array.
-     * 
+     *
      * @param length The length of the array to read.
      * @return An unsigned short array.
      * @throws IOException If there is an error reading the data.
@@ -191,9 +191,9 @@ abstract class TTFDataStream implements
     }
 
     /**
-     * Read an signed short.
-     * 
-     * @return An signed short.
+     * Read a signed short.
+     *
+     * @return A signed short.
      * @throws IOException If there is an error reading the data.
      */
     public short readSignedShort() throws IOException
@@ -203,8 +203,8 @@ abstract class TTFDataStream implements
 
     /**
      * Read an eight byte international date.
-     * 
-     * @return An signed short.
+     *
+     * @return A signed short.
      * @throws IOException If there is an error reading the data.
      */
     public Calendar readInternationalDate() throws IOException
@@ -230,7 +230,7 @@ abstract class TTFDataStream implements
 
     /**
      * Seek into the datasource.
-     * 
+     *
      * @param pos The position to seek to.
      * @throws IOException If there is an error seeking to that position.
      */
@@ -238,7 +238,7 @@ abstract class TTFDataStream implements
 
     /**
      * Read a specific number of bytes from the stream.
-     * 
+     *
      * @param numberOfBytes The number of bytes to read.
      * @return The byte buffer.
      * @throws IOException If there is an error while reading.
@@ -266,20 +266,20 @@ abstract class TTFDataStream implements
 
     /**
      * @see java.io.InputStream#read(byte[], int, int )
-     * 
+     *
      * @param b The buffer to write to.
      * @param off The offset into the buffer.
      * @param len The length into the buffer.
-     * 
+     *
      * @return The number of bytes read, or -1 at the end of the stream
-     * 
+     *
      * @throws IOException If there is an error reading from the stream.
      */
     public abstract int read(byte[] b, int off, int len) throws IOException;
 
     /**
      * Get the current position in the stream.
-     * 
+     *
      * @return The current position in the stream.
      * @throws IOException If an error occurs while reading the stream.
      */
@@ -287,7 +287,7 @@ abstract class TTFDataStream implements
 
     /**
      * This will get the original data file that was used for this stream.
-     * 
+     *
      * @return The data that was read from.
      * @throws IOException If there is an issue reading the data.
      */
@@ -295,7 +295,7 @@ abstract class TTFDataStream implements
 
     /**
      * This will get the original data size that was used for this stream.
-     * 
+     *
      * @return The size of the original data.
      */
     public abstract long getOriginalDataSize();