import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;

import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.awt.image.ColorConvertOp;
import java.awt.image.ColorModel;

import javax.imageio.ImageIO;

public class ColorConvertTest {

    public static void main(String[] args) throws Exception {
        BufferedImage source = ImageIO.read(openStream("cmyk.jpg.base64.txt"));
        ColorModel sourceModel = source.getColorModel();
        System.out.append("< cmyk.jpg: ").println(sourceModel);

        ColorConvertOp convertOp = new ColorConvertOp(
                ColorSpace.getInstance(ColorSpace.CS_sRGB), null);
        BufferedImage rgb = convertOp.filter(source, null);
        ImageIO.write(rgb, "png", new File("rgb.png"));
        System.out.println("> rgb.png");
    }

    private static ByteArrayInputStream openStream(String name) throws IOException {
        try (InputStream input = ColorConvertTest.class.getResourceAsStream(name)) {
            return new ByteArrayInputStream(Base64
                    .getMimeDecoder().decode(readAllBytes(input)));
        }
    }

    public static byte[] readAllBytes(InputStream inputStream) throws IOException {
    final int bufLen = 1024;
    byte[] buf = new byte[bufLen];
    int readLen;
    IOException exception = null;

    try {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        while ((readLen = inputStream.read(buf, 0, bufLen)) != -1)
            outputStream.write(buf, 0, readLen);

        return outputStream.toByteArray();
    } catch (IOException e) {
        exception = e;
        throw e;
    } finally {
        if (exception == null) inputStream.close();
        else try {
            inputStream.close();
        } catch (IOException e) {
            exception.addSuppressed(e);
        }
    }
}

} 