The keypart is to write the BufferedImage onto a new BufferedImage using an RGB channel with White background. That'll fix the issue of weird colors:
public static InputStream encodeToJpg(String filepath) throws IOException {
System.out.println("Encoding to JPG...");
BufferedImage buffImg;
InputStream origStream = new FileInputStream(new File(filepath));
buffImg = ImageIO.read(origStream);
origStream.close();
// Recreate the BufferedImage to fix channel issues
BufferedImage newBuffImg = new BufferedImage(buffImg.getWidth(), buffImg.getHeight(), BufferedImage.TYPE_INT_RGB);
newBuffImg.createGraphics().drawImage(buffImg, 0, 0, Color.WHITE, null);
buffImg.flush();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
ImageIO.write(newBuffImg, "jpg", outStream);
ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
return inStream;
}