You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2020/08/16 13:01:10 UTC
svn commit: r1880897 - in /pdfbox/trunk/pdfbox/src:
main/java/org/apache/pdfbox/io/ main/java/org/apache/pdfbox/pdfparser/
test/java/org/apache/pdfbox/io/
Author: lehmi
Date: Sun Aug 16 13:01:09 2020
New Revision: 1880897
URL: http://svn.apache.org/viewvc?rev=1880897&view=rev
Log:
PDFBOX-4836: remove no longer needed InputStream based methods
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessRead.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/RandomAccessReadBufferTest.java
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/RandomAccessReadViewTest.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessRead.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessRead.java?rev=1880897&r1=1880896&r2=1880897&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessRead.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessRead.java Sun Aug 16 13:01:09 2020
@@ -69,32 +69,14 @@ public interface RandomAccessRead extend
/**
* Seek to a position in the data.
*
- * Only supported if {@link #seekSupported()} returns true.
- *
* @param position The position to seek to.
* @throws IOException If there is an error while seeking.
*/
void seek(long position) throws IOException;
/**
- * Indicates if seek operations are supported.
- *
- * @return true if seek operations are supported
- *
- * @see org.apache.pdfbox.io.RandomAccessRead#seek(long)
- * @see org.apache.pdfbox.io.RandomAccessRead#length()
- * @see org.apache.pdfbox.io.RandomAccessRead#rewind(int)
- */
- default boolean seekSupported()
- {
- // default implementation for all non input stream based sources
- return true;
- }
- /**
* The total number of bytes that are available.
*
- * Only supported if {@link #seekSupported()} returns true.
- *
* @return The number of bytes available.
*
* @throws IOException If there is an IO error while determining the length of the data stream.
@@ -126,8 +108,6 @@ public interface RandomAccessRead extend
/**
* Seek backwards the given number of bytes.
*
- * Only supported if {@link #seekSupported()} returns true.
- *
* @param bytes the number of bytes to be seeked backwards
* @throws IOException If there is an error while seeking
*/
@@ -174,44 +154,6 @@ public interface RandomAccessRead extend
}
/**
- * Pushes back a byte.
- *
- * @param b the int to push back.
- * @throws IOException if an I/O error occurs while reading data
- */
- default void unread(int b) throws IOException
- {
- // default implementation for all non input stream based sources
- rewind(1);
- }
-
- /**
- * Pushes back an array of bytes.
- *
- * @param bytes the byte array to push back.
- * @throws IOException if an I/O error occurs while reading data
- */
- default void unread(byte[] bytes) throws IOException
- {
- // default implementation for all non input stream based sources
- rewind(bytes.length);
- }
-
- /**
- * Pushes back a portion of an array of bytes.
- *
- * @param bytes the byte array to push back.
- * @param start the start offset of the data.
- * @param len the number of bytes to push back.
- * @throws IOException if an I/O error occurs while reading data
- */
- default void unread(byte[] bytes, int start, int len) throws IOException
- {
- // default implementation for all non input stream based sources
- rewind(len);
- }
-
- /**
* Creates a random access read view starting at the given position with the given length.
*
* @param startPosition start position within the underlying random access read
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java?rev=1880897&r1=1880896&r2=1880897&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java Sun Aug 16 13:01:09 2020
@@ -275,7 +275,7 @@ public abstract class BaseParser
{
return true;
}
- source.unread(c);
+ source.rewind(1);
return false;
}
@@ -291,7 +291,7 @@ public abstract class BaseParser
String potentialDEF = readString();
if (!potentialDEF.equals(DEF))
{
- source.unread(potentialDEF.getBytes(StandardCharsets.ISO_8859_1));
+ source.rewind(potentialDEF.getBytes(StandardCharsets.ISO_8859_1).length);
}
else
{
@@ -331,7 +331,7 @@ public abstract class BaseParser
whitespace = source.read();
if (ASCII_LF != whitespace)
{
- source.unread(whitespace);
+ source.rewind(1);
//The spec says this is invalid but it happens in the real
//world so we must support it.
}
@@ -341,7 +341,7 @@ public abstract class BaseParser
//we are in an error.
//but again we will do a lenient parsing and just assume that everything
//is fine
- source.unread(whitespace);
+ source.rewind(1);
}
}
@@ -382,7 +382,7 @@ public abstract class BaseParser
}
if (amountRead > 0)
{
- source.unread(nextThreeBytes, 0, amountRead);
+ source.rewind(amountRead);
}
return braces;
}
@@ -542,7 +542,7 @@ public abstract class BaseParser
}
if (c != -1)
{
- source.unread(c);
+ source.rewind(1);
}
return new COSString(out.toByteArray());
}
@@ -668,7 +668,7 @@ public abstract class BaseParser
// This could also be an "endobj" or "endstream" which means we can assume that
// the array has ended.
String isThisTheEnd = readString();
- source.unread(isThisTheEnd.getBytes(StandardCharsets.ISO_8859_1));
+ source.rewind(isThisTheEnd.getBytes(StandardCharsets.ISO_8859_1).length);
if(ENDOBJ_STRING.equals(isThisTheEnd) || ENDSTREAM_STRING.equals(isThisTheEnd))
{
return po;
@@ -741,7 +741,7 @@ public abstract class BaseParser
c = -1;
break;
}
- source.unread(ch2);
+ source.rewind(1);
c = ch1;
buffer.write(ch);
}
@@ -758,7 +758,7 @@ public abstract class BaseParser
}
if (c != -1)
{
- source.unread(c);
+ source.rewind(1);
}
byte[] bytes = buffer.toByteArray();
@@ -807,10 +807,10 @@ public abstract class BaseParser
{
case '<':
// pull off first left bracket
- int leftBracket = source.read();
+ source.read();
// check for second left bracket
c = (char) source.peek();
- source.unread(leftBracket);
+ source.rewind(1);
if(c == '<')
{
@@ -868,7 +868,7 @@ public abstract class BaseParser
// if it's an endstream/endobj, we want to put it back so the caller will see it
if(ENDOBJ_STRING.equals(badString) || ENDSTREAM_STRING.equals(badString))
{
- source.unread(badString.getBytes(StandardCharsets.ISO_8859_1));
+ source.rewind(badString.getBytes(StandardCharsets.ISO_8859_1).length);
}
}
}
@@ -888,7 +888,7 @@ public abstract class BaseParser
}
if (ic != -1)
{
- source.unread(ic);
+ source.rewind(1);
}
return COSNumber.get(buf.toString());
}
@@ -912,7 +912,7 @@ public abstract class BaseParser
}
if (c != -1)
{
- source.unread(c);
+ source.rewind(1);
}
return buffer.toString();
}
@@ -985,7 +985,7 @@ public abstract class BaseParser
}
if (c != -1)
{
- source.unread(c);
+ source.rewind(1);
}
return buffer.toString();
}
@@ -1190,7 +1190,7 @@ public abstract class BaseParser
}
if (c != -1)
{
- source.unread(c);
+ source.rewind(1);
}
}
@@ -1248,7 +1248,7 @@ public abstract class BaseParser
}
catch( NumberFormatException e )
{
- source.unread(intBuffer.toString().getBytes(StandardCharsets.ISO_8859_1));
+ source.rewind(intBuffer.toString().getBytes(StandardCharsets.ISO_8859_1).length);
throw new IOException("Error: Expected an integer type at offset " +
source.getPosition() +
", instead got '" + intBuffer + "'", e);
@@ -1277,7 +1277,7 @@ public abstract class BaseParser
}
catch( NumberFormatException e )
{
- source.unread(longBuffer.toString().getBytes(StandardCharsets.ISO_8859_1));
+ source.rewind(longBuffer.toString().getBytes(StandardCharsets.ISO_8859_1).length);
throw new IOException( "Error: Expected a long type at offset "
+ source.getPosition() + ", instead got '" + longBuffer + "'", e);
}
@@ -1306,7 +1306,7 @@ public abstract class BaseParser
}
if( lastByte != -1 )
{
- source.unread(lastByte);
+ source.rewind(1);
}
return buffer;
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java?rev=1880897&r1=1880896&r2=1880897&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java Sun Aug 16 13:01:09 2020
@@ -108,13 +108,13 @@ public class PDFStreamParser extends Bas
{
case '<':
// pull off first left bracket
- int leftBracket = source.read();
+ source.read();
// check for second left bracket
c = (char) source.peek();
// put back first bracket
- source.unread(leftBracket);
+ source.rewind(1);
if (c == '<')
{
@@ -353,7 +353,7 @@ public class PDFStreamParser extends Bas
noBinData = false;
}
}
- source.unread(binCharTestArr, 0, readBytes);
+ source.rewind(readBytes);
}
if (!noBinData)
{
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/RandomAccessReadBufferTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/RandomAccessReadBufferTest.java?rev=1880897&r1=1880896&r2=1880897&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/RandomAccessReadBufferTest.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/RandomAccessReadBufferTest.java Sun Aug 16 13:01:09 2020
@@ -117,15 +117,15 @@ public class RandomAccessReadBufferTest
randomAccessSource.read();
randomAccessSource.read();
byte[] readBytes = new byte[6];
- randomAccessSource.read(readBytes);
+ assertEquals(readBytes.length, randomAccessSource.read(readBytes));
assertEquals(8, randomAccessSource.getPosition());
- randomAccessSource.unread(readBytes);
+ randomAccessSource.rewind(readBytes.length);
assertEquals(2, randomAccessSource.getPosition());
assertEquals(2, randomAccessSource.read());
assertEquals(3, randomAccessSource.getPosition());
randomAccessSource.read(readBytes, 2, 4);
assertEquals(7, randomAccessSource.getPosition());
- randomAccessSource.unread(readBytes, 2, 4);
+ randomAccessSource.rewind(4);
assertEquals(3, randomAccessSource.getPosition());
randomAccessSource.close();
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/RandomAccessReadViewTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/RandomAccessReadViewTest.java?rev=1880897&r1=1880896&r2=1880897&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/RandomAccessReadViewTest.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/RandomAccessReadViewTest.java Sun Aug 16 13:01:09 2020
@@ -132,9 +132,9 @@ public class RandomAccessReadViewTest
randomAccessReadView.read();
randomAccessReadView.read();
byte[] readBytes = new byte[6];
- randomAccessReadView.read(readBytes);
+ assertEquals(readBytes.length, randomAccessReadView.read(readBytes));
assertEquals(8, randomAccessReadView.getPosition());
- randomAccessReadView.unread(readBytes);
+ randomAccessReadView.rewind(readBytes.length);
assertEquals(2, randomAccessReadView.getPosition());
assertEquals(12, randomAccessReadView.read());
assertEquals(3, randomAccessReadView.getPosition());
@@ -143,7 +143,7 @@ public class RandomAccessReadViewTest
assertEquals(13, readBytes[2]);
assertEquals(16, readBytes[5]);
assertEquals(7, randomAccessReadView.getPosition());
- randomAccessReadView.unread(readBytes, 2, 4);
+ randomAccessReadView.rewind(4);
assertEquals(3, randomAccessReadView.getPosition());
randomAccessReadView.close();