Gets the buffered image from the given byte array quietly.

@param byteArray
the byte array
@return the buffered image or null if the read process failed.
345662
public static BufferedImage readQuietly(final byte[] byteArray)
	{
		BufferedImage img = null;
		try
		{
			img = read(byteArray);
		}
		catch (IOException e)
		{
			log.log(Level.SEVERE, "Reading image failed.", e);
		}
		return img;
	}
952440
public byte[] getContentAsByteArray() {
        if (content == null) {
            try {
                content = IOHelper.byteArrayFromStream(is);
            } catch (IOException e) {
                throw new RuntimeException("IOException buffering binary data",
                        e);
            }
            is = null;
        }
        return content;
    }
526631
public static BufferedImage getUrlBufferedImage(String urlPath) {
		URL url = null;
		BufferedImage bufferImage = null;
		try {
			url = new URL(urlPath);
			bufferImage = ImageIO.read(url);
			return bufferImage;
		} catch (Exception e) {
			logger.error("getUrlBufferedImage error, {}, {}", urlPath, e);
		}
		return null;

	}
90985
public static ByteArrayInputStream toStream(ByteBuffer byteBuffer) {
        if (byteBuffer == null) {
            return new ByteArrayInputStream(new byte[0]);
        }
        return new ByteArrayInputStream(copyBytesFrom(byteBuffer));
    }
406486
private static String byteArrayToHexString(byte[] byteArray) {
		StringBuilder result = new StringBuilder();
		
		for (int i=0; i < byteArray.length; i++) {
			result.append(Integer.toString((byteArray[i] & 0xff) + 0x100, 16).substring(1));
		}
		
		return result.toString();
	}
43873
public BufferedImage getImage() throws IOException {
        if (image == null) {
            // No content, no image
            if (bufferedOut == null) {
                return null;
            }

            // Read from the byte buffer
            InputStream byteStream = bufferedOut.createInputStream();
            ImageInputStream input = null;
            try {
                input = ImageIO.createImageInputStream(byteStream);
                Iterator readers = ImageIO.getImageReaders(input);
                if (readers.hasNext()) {
                    // Get the correct reader
                    ImageReader reader = (ImageReader) readers.next();
                    try {
                        reader.setInput(input);

                        ImageReadParam param = reader.getDefaultReadParam();

                        // Get default size
                        int originalWidth = reader.getWidth(0);
                        int originalHeight = reader.getHeight(0);
//////////////////
// PRE-PROCESS (prepare): param, size, format?, request, response?
                        // TODO: AOI strategy?
                        // Extract AOI from request
                        Rectangle aoi = extractAOIFromRequest(originalWidth, originalHeight, originalRequest);

                        if (aoi != null) {
                            param.setSourceRegion(aoi);
                            originalWidth = aoi.width;
                            originalHeight = aoi.height;
                        }

                        // TODO: Size and subsampling strategy?
                        // If possible, extract size from request
                        Dimension size = extractSizeFromRequest(originalWidth, originalHeight, originalRequest);
                        double readSubSamplingFactor = getReadSubsampleFactorFromRequest(originalRequest);

                        if (size != null) {
                            //System.out.println("Size: " + size);
                            if (param.canSetSourceRenderSize()) {
                                param.setSourceRenderSize(size);
                            }
                            else {
                                int subX = (int) Math.max(originalWidth / (size.width * readSubSamplingFactor), 1.0);
                                int subY = (int) Math.max(originalHeight / (size.height * readSubSamplingFactor), 1.0);

                                if (subX > 1 || subY > 1) {
                                    param.setSourceSubsampling(subX, subY, subX > 1 ? subX / 2 : 0, subY > 1 ? subY / 2 : 0);
                                }
                            }
                        }

                        // Need base URI for SVG with links/stylesheets etc
                        maybeSetBaseURIFromRequest(param);

/////////////////////

                        // Finally, read the image using the supplied parameter
                        BufferedImage image = reader.read(0, param);

                        // TODO: If we sub-sampled, it would be a good idea to blur before resampling,
                        // to avoid jagged lines artifacts

                        // If reader doesn't support dynamic sizing, scale now
                        image = resampleImage(image, size);

                        // Fill bgcolor behind image, if transparent
                        extractAndSetBackgroundColor(image); // TODO: Move to flush/POST-PROCESS

                        // Set image
                        this.image = image;
                    }
                    finally {
                        reader.dispose();
                    }
                }
                else {
                    context.log("ERROR: No suitable image reader found (content-type: " + originalContentType + ").");
                    context.log("ERROR: Available formats: " + getFormatsString());

                    throw new IIOException("Unable to transcode image: No suitable image reader found (content-type: " + originalContentType + ").");
                }

                // Free resources, as the image is now either read, or unreadable
                bufferedOut = null;
            }
            finally {
                if (input != null) {
                    input.close();
                }
            }
        }

        // Image is usually a BufferedImage, but may also be a RenderedImage
        return image != null ? ImageUtil.toBuffered(image) : null;
    }
325977
public byte[] toBytes(@Nullable Object val)
  {
    if (val != null) {
      byte[] bytes = getObjectStrategy().toBytes(val);
      return bytes != null ? bytes : ByteArrays.EMPTY_ARRAY;
    } else {
      return ByteArrays.EMPTY_ARRAY;
    }
  }
825840
public byte[] getRawData() throws IOException
    {
        int contentLength = request.getContentLength();
        if( contentLength<0 ) {
            return null;
        }
        
        byte[] buffer = new byte[contentLength];
        ServletInputStream is = request.getInputStream();
        for (int i = 0; i < contentLength; ) {
            int rLen = is.read(buffer, i, contentLength - i);
            if ( rLen == -1 ) {
                break;
            }
            
            i += rLen;
        }
        
        return buffer;
    }
684754
static public byte[] getBytes(StringBuffer data) {
        if (null == data) {
            return null;
        }
        int len = data.length();
        char[] chars = new char[len];
        data.getChars(0, len, chars, 0);
        byte[] bytes = new byte[len];
        for (int i = 0; i < len; i++) {
            bytes[i] = (byte) chars[i];
        }
        return bytes;
    }
737299
public static final byte[] loadByteArray(final InputStream in) {
		try {
			final ByteArrayOutputStream bOut = new ByteArrayOutputStream();

			final byte buffer[] = new byte[2048];

			int iNbByteRead = -1;

			while ((iNbByteRead = in.read(buffer)) != -1) {
				bOut.write(buffer, 0, iNbByteRead);
			}

			return bOut.toByteArray();
		} catch (final IOException ioe) {
			return null;
		}
	}
737544
public static byte searchMin(byte[] byteArray) {
        if(byteArray.length == 0) {
            throw new IllegalArgumentException("The array you provided does not have any elements");
        }

        byte min = byteArray[0];

        for(int i = 1; i < byteArray.length; i++) {
            if(byteArray[i] < min) {
                min = byteArray[i];
            }
        }

        return min;
    }
1331245
@SneakyThrows
    public static String decodeByteArrayToString(final byte[] bytes) {
        @Cleanup
        val bais = new ByteArrayInputStream(bytes);
        @Cleanup
        val baos = new ByteArrayOutputStream();
        val buf = new byte[bytes.length];
        try (val iis = new InflaterInputStream(bais)) {
            var count = iis.read(buf);
            while (count != -1) {
                baos.write(buf, 0, count);
                count = iis.read(buf);
            }
            return new String(baos.toByteArray(), StandardCharsets.UTF_8);
        } catch (final Exception e) {
            LOGGER.error("Base64 decoding failed", e);
            return null;
        }
    }
360644
function (byteArray) {
            var result = "",
                len = byteArray.byteLength,
                i;

            for (i = 0; i < len; i += 1) {
                result += String.fromCharCode(byteArray[i]);
            }
            return result;
        }
1043968
public static byte[] getBytes(Object o)
    {
        if (o != null)
        {
            return getBytes(o, o.getClass());
        }

        return null;
    }
1129401
public byte[] getDataByteArray() {
        if (exception == null) {
            try {
                if (!setDataByteArray) {
                    dataByteArray = EntityUtils.toByteArray(httpEntity);
                    setDataByteArray = true;
                }
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
            return dataByteArray;
        }
        return null;
    }
83063
public static ByteBuffer toBuffer(byte[] array) {
        if (array == null)
            return EMPTY_BUFFER;
        return toBuffer(array, 0, array.length);
    }
759960
protected static ByteBuffer getRgba(Image image) {
    int w = (int) image.width(), h = (int) image.height(), size = w * h;
    int[] rawPixels = new int[size];
    ByteBuffer pixels = ByteBuffer.allocateDirect(size * 4);
    pixels.order(ByteOrder.nativeOrder());
    IntBuffer rgba = pixels.asIntBuffer();
    image.getRgb(0, 0, w, h, rawPixels, 0, w);

    for (int i = 0; i < size; i++) {
      int argb = rawPixels[i];
      // Order is inverted because this is read as a byte array, and we store intel ints.
      rgba.put(i, ((argb >> 16) & 0x0ff) | (argb & 0x0ff00ff00) | ((argb & 0xff) << 16));
    }
    return pixels;
  }