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 2013/05/27 20:01:39 UTC
svn commit: r1486688 -
/pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocument.java
Author: lehmi
Date: Mon May 27 18:01:38 2013
New Revision: 1486688
URL: http://svn.apache.org/r1486688
Log:
PDFBOX-1581: backport of Arrays.copyOfRange to restore java5 compatibility
Modified:
pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocument.java
Modified: pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocument.java?rev=1486688&r1=1486687&r2=1486688&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocument.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocument.java Mon May 27 18:01:38 2013
@@ -22,7 +22,6 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.Arrays;
import org.apache.pdfbox.exceptions.COSVisitorException;
import org.apache.pdfbox.io.IOUtils;
@@ -45,6 +44,14 @@ public class TestPDDocument extends Test
testResultsDir.mkdirs();
}
+ private byte[] copyOfRange(byte[] array, int from, int to)
+ {
+ // java5 backport of java6-only Arrays.copyOfRange
+ int length = to-from;
+ byte[] subArray = new byte[length];
+ System.arraycopy(array, from, subArray, 0, length);
+ return subArray;
+ }
/**
* Test document save/load using a stream.
* @throws IOException if something went wrong
@@ -64,8 +71,8 @@ public class TestPDDocument extends Test
// Verify content
byte[] pdf = baos.toByteArray();
assertTrue(pdf.length > 200);
- assertEquals("%PDF-1.4", new String(Arrays.copyOfRange(pdf, 0, 8), "UTF-8"));
- assertEquals("%%EOF\n", new String(Arrays.copyOfRange(pdf, pdf.length - 6, pdf.length), "UTF-8"));
+ assertEquals("%PDF-1.4", new String(copyOfRange(pdf, 0, 8), "UTF-8"));
+ assertEquals("%%EOF\n", new String(copyOfRange(pdf, pdf.length - 6, pdf.length), "UTF-8"));
// Load
PDDocument loadDoc = PDDocument.load(new ByteArrayInputStream(pdf), new RandomAccessBuffer());
@@ -95,8 +102,8 @@ public class TestPDDocument extends Test
byte[] pdf = IOUtils.toByteArray(in);
in.close();
assertTrue(pdf.length > 200);
- assertEquals("%PDF-1.4", new String(Arrays.copyOfRange(pdf, 0, 8), "UTF-8"));
- assertEquals("%%EOF\n", new String(Arrays.copyOfRange(pdf, pdf.length - 6, pdf.length), "UTF-8"));
+ assertEquals("%PDF-1.4", new String(copyOfRange(pdf, 0, 8), "UTF-8"));
+ assertEquals("%%EOF\n", new String(copyOfRange(pdf, pdf.length - 6, pdf.length), "UTF-8"));
// Load
PDDocument loadDoc = PDDocument.load(targetFile, new RandomAccessBuffer());
@@ -123,8 +130,8 @@ public void testSaveLoadNonSeqStream() t
// Verify content
byte[] pdf = baos.toByteArray();
assertTrue(pdf.length > 200);
- assertEquals("%PDF-1.4", new String(Arrays.copyOfRange(pdf, 0, 8), "UTF-8"));
- assertEquals("%%EOF\n", new String(Arrays.copyOfRange(pdf, pdf.length - 6, pdf.length), "UTF-8"));
+ assertEquals("%PDF-1.4", new String(copyOfRange(pdf, 0, 8), "UTF-8"));
+ assertEquals("%%EOF\n", new String(copyOfRange(pdf, pdf.length - 6, pdf.length), "UTF-8"));
// Load
PDDocument loadDoc = PDDocument.loadNonSeq(new ByteArrayInputStream(pdf), new RandomAccessBuffer());
@@ -154,8 +161,8 @@ public void testSaveLoadNonSeqStream() t
byte[] pdf = IOUtils.toByteArray(in);
in.close();
assertTrue(pdf.length > 200);
- assertEquals("%PDF-1.4", new String(Arrays.copyOfRange(pdf, 0, 8), "UTF-8"));
- assertEquals("%%EOF\n", new String(Arrays.copyOfRange(pdf, pdf.length - 6, pdf.length), "UTF-8"));
+ assertEquals("%PDF-1.4", new String(copyOfRange(pdf, 0, 8), "UTF-8"));
+ assertEquals("%%EOF\n", new String(copyOfRange(pdf, pdf.length - 6, pdf.length), "UTF-8"));
// Load
PDDocument loadDoc = PDDocument.loadNonSeq(targetFile, new RandomAccessBuffer());