View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.imaging.bytesource;
18  
19  import static org.junit.jupiter.api.Assertions.assertEquals;
20  
21  import java.awt.image.BufferedImage;
22  import java.io.BufferedInputStream;
23  import java.io.File;
24  import java.io.FileInputStream;
25  import java.io.IOException;
26  
27  import org.apache.commons.imaging.Imaging;
28  import org.apache.commons.imaging.ImagingException;
29  import org.apache.commons.imaging.ImagingTestConstants;
30  import org.apache.commons.io.FilenameUtils;
31  import org.junit.jupiter.api.Test;
32  
33  final class ByteSourceInputStreamTest {
34  
35      public static final String ICO_IMAGE_FILE = "ico\\1\\Oregon Scientific DS6639 - DSC_0307 - small.ico";
36      public static final int ICO_IMAGE_WIDTH = 300;
37      public static final int ICO_IMAGE_HEIGHT = 225;
38  
39      @Test
40      public void testReadFromStream() throws IOException, ImagingException {
41  
42          final String imagePath = FilenameUtils.separatorsToSystem(ICO_IMAGE_FILE);
43          final File imageFile = new File(ImagingTestConstants.TEST_IMAGE_FOLDER, imagePath);
44          try (BufferedInputStream imageStream = new BufferedInputStream(new FileInputStream(imageFile))) {
45              // InputStreamByteSource is created inside of following method
46              final BufferedImage bufferedImage = Imaging.getBufferedImage(imageStream, ICO_IMAGE_FILE);
47  
48              assertEquals(bufferedImage.getWidth(), ICO_IMAGE_WIDTH);
49              assertEquals(bufferedImage.getHeight(), ICO_IMAGE_HEIGHT);
50          }
51      }
52  
53  }