Skip to content

Commit ec35556

Browse files
committed
PDFBOX-6235: optimize
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1937079 13f79535-47bb-0310-9956-ffa450edef68
1 parent 7ada890 commit ec35556

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/JPEGFactoryTest.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,15 @@ static void setUp()
8080
void testCreateFromStream() throws IOException
8181
{
8282
try (PDDocument document = new PDDocument();
83-
InputStream is1 = JPEGFactoryTest.class.getResourceAsStream("jpeg.jpg");
84-
InputStream is2 = JPEGFactoryTest.class.getResourceAsStream("jpeg.jpg"))
83+
InputStream is = JPEGFactoryTest.class.getResourceAsStream("jpeg.jpg"))
8584
{
86-
PDImageXObject ximage = JPEGFactory.createFromStream(document, is1);
85+
byte[] ba = is.readAllBytes();
86+
87+
PDImageXObject ximage = JPEGFactory.createFromStream(document, new ByteArrayInputStream(ba));
8788
validate(ximage, 8, 344, 287, "jpg", PDDeviceRGB.INSTANCE.getName());
8889

8990
doWritePDF(document, ximage, TESTRESULTSDIR, "jpegrgbstream.pdf");
90-
checkJpegStream(TESTRESULTSDIR, "jpegrgbstream.pdf", is2);
91+
checkJpegStream(TESTRESULTSDIR, "jpegrgbstream.pdf", new ByteArrayInputStream(ba));
9192
}
9293
}
9394

@@ -98,15 +99,16 @@ void testCreateFromStream() throws IOException
9899
@Test
99100
void testCreateFromStreamCMYK() throws IOException
100101
{
101-
try (InputStream is1 = JPEGFactoryTest.class.getResourceAsStream("jpegcmyk.jpg");
102-
InputStream is2 = JPEGFactoryTest.class.getResourceAsStream("jpegcmyk.jpg"))
102+
try (InputStream is = JPEGFactoryTest.class.getResourceAsStream("jpegcmyk.jpg"))
103103
{
104+
byte[] ba = is.readAllBytes();
105+
104106
PDDocument document = new PDDocument();
105-
PDImageXObject ximage = JPEGFactory.createFromStream(document, is1);
107+
PDImageXObject ximage = JPEGFactory.createFromStream(document, new ByteArrayInputStream(ba));
106108
validate(ximage, 8, 343, 287, "jpg", PDDeviceCMYK.INSTANCE.getName());
107109

108110
doWritePDF(document, ximage, TESTRESULTSDIR, "jpegcmykstream.pdf");
109-
checkJpegStream(TESTRESULTSDIR, "jpegcmykstream.pdf", is2);
111+
checkJpegStream(TESTRESULTSDIR, "jpegcmykstream.pdf", new ByteArrayInputStream(ba));
110112
}
111113
}
112114

@@ -117,15 +119,16 @@ void testCreateFromStreamCMYK() throws IOException
117119
@Test
118120
void testCreateFromStream256() throws IOException
119121
{
120-
try (InputStream is1 = JPEGFactoryTest.class.getResourceAsStream("jpeg256.jpg");
121-
InputStream is2 = JPEGFactoryTest.class.getResourceAsStream("jpeg256.jpg"))
122+
try (InputStream is = JPEGFactoryTest.class.getResourceAsStream("jpeg256.jpg"))
122123
{
124+
byte[] ba = is.readAllBytes();
125+
123126
PDDocument document = new PDDocument();
124-
PDImageXObject ximage = JPEGFactory.createFromStream(document, is1);
127+
PDImageXObject ximage = JPEGFactory.createFromStream(document, new ByteArrayInputStream(ba));
125128
validate(ximage, 8, 344, 287, "jpg", PDDeviceGray.INSTANCE.getName());
126129

127130
doWritePDF(document, ximage, TESTRESULTSDIR, "jpeg256stream.pdf");
128-
checkJpegStream(TESTRESULTSDIR, "jpeg256stream.pdf", is2);
131+
checkJpegStream(TESTRESULTSDIR, "jpeg256stream.pdf", new ByteArrayInputStream(ba));
129132
}
130133
}
131134

0 commit comments

Comments
 (0)