CatalogOutputAdapter { @SuppressWarnings("WeakerAccess") public BinaryContent getBinaryContent(BufferedImage image) throws IOException, MimeTypeParseException { validateArgument(image, "image"); BinaryContent binaryContent = null; try { lock.acquire(); try { BufferedImage rgbImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_3BYTE_BGR); Graphics2D graphics = rgbImage.createGraphics(); graphics.drawImage(image, 0, 0, null); InputStream fis = new ByteArrayInputStream(createJpg(rgbImage)); binaryContent = new BinaryContentImpl(fis, new MimeType(IMAGE_JPG)); } finally { lock.release(); } } catch (InterruptedException e) { LOGGER.debug("Interrupt received while doing image processing.", e); Thread.currentThread().interrupt(); } return binaryContent; } CatalogOutputAdapter(Semaphore lock); @SuppressWarnings("WeakerAccess") BufferedImage getImage(ResourceResponse resourceResponse); @SuppressWarnings("WeakerAccess") BinaryContent getBinaryContent(BufferedImage image); @SuppressWarnings("unused") NitfSegmentsFlow getNitfSegmentsFlow(ResourceResponse resourceResponse); @SuppressWarnings("unused") BinaryContent getNitfBinaryContent(
      BufferedImage chip, NitfSegmentsFlow nitfSegmentsFlow, int sourceX, int sourceY); @SuppressWarnings("unused") void wrapException(Exception exception);  }
@Test(expected = IllegalArgumentException.class) public void testGetBinaryContentNullImage() throws IOException, MimeTypeParseException { catalogOutputAdapter.getBinaryContent(null); }
@Test public void testGetBinaryContent() throws IOException, MimeTypeParseException, InterruptedException { BufferedImage suppliedImage = ImageIO.read(getInputStream(I_3001A)); suppliedImage = new BufferedImage( suppliedImage.getWidth(), suppliedImage.getHeight(), BufferedImage.TYPE_3BYTE_BGR); BinaryContent binaryContent = catalogOutputAdapter.getBinaryContent(suppliedImage); assertThat(binaryContent, is(notNullValue())); assertThat(binaryContent.getInputStream(), is(notNullValue())); BufferedImage returnedImage = ImageIO.read(binaryContent.getInputStream()); assertThat(returnedImage.getWidth(), is(1024)); assertThat(returnedImage.getHeight(), is(1024)); verify(lock).acquire(); verify(lock).release(); }