javax.imageio.IIOException:不是 JPEG 流(开始于:0x0003,预期 SOI:0xffd8)

javax.imageio.IIOException: Not a JPEG stream (starts with: 0x0003, expected SOI: 0xffd8)

在将 inputStream 转换为 bufferImage 时遇到问题。 BufferedImage crfPersonImg 始终为 null,异常发生在行 Raster raster = reader1.readRaster(0, null);。到目前为止,这是我的代码

//code for getting ByteArray From Blob column in Oracle DB.
    List<Object[]> userRoleList = commonDao.findByNativeSQL(selectSQL
            , new Object[] {examCd, examPeriod, fromMemNo, toMemNo});
    for(Object[] row : userRoleList){
        CertificateDtlsVO cdObj = new CertificateDtlsVO();          
        cdObj.setExmCd(Integer.parseInt(row[0].toString()));
        cdObj.setExmDsc(row[1].toString());
        cdObj.setMemNo(row[2].toString());
        cdObj.setMemNm(row[3].toString());
        cdObj.setCertNo(row[4].toString());
        cdObj.setCertDt(row[5].toString());
        cdObj.setPrtNo(row[6].toString());
        cdObj.setSylCd(row[7].toString());
        cdObj.setNumOfTime(Integer.parseInt(row[8].toString()));
        cdObj.setMemType(row[9].toString());
        cdObj.setClassGrade(row[10].toString());

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(row[11]);           
        cdObj.setPhoto(baos.toByteArray());
        baos = new ByteArrayOutputStream();
        oos = new ObjectOutputStream(baos);
        oos.writeObject(row[12]);
        cdObj.setSign(baos.toByteArray());
        cdObj.setPhotoBuffImg(ImageIO.read(new ByteArrayInputStream(baos.toByteArray())));
        oos.flush();
        oos.close();
        memCertfDtlsList.add(cdObj);
    }

//字节数组转BufferImage的代码

InputStream in = new ByteArrayInputStream(photo);       
    Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("JPEG");
    ImageReader reader1 = null;
    while (readers.hasNext()) {
        reader1 = readers.next();
        if (reader1.canReadRaster()) {
            break;
        }
    }

    //Stream the image file
    ImageInputStream input =   ImageIO.createImageInputStream(in); 
    reader1.setInput(input); 

    //Read the image raster
    Raster raster = reader1.readRaster(0, null); 

    //Create a new RGB image
    BufferedImage bi = new BufferedImage(raster.getWidth(), raster.getHeight(), 
            BufferedImage.TYPE_4BYTE_ABGR); 

    //Fill the new image with the old raster
    bi.getRaster().setRect(raster);

    BufferedImage crfPersonImg = ImageIO.read(in);

javax.imageio.IIOException: Not a JPEG stream (starts with: 0x0003, expected SOI: 0xffd8) at com.twelvemonkeys.imageio.plugins.jpeg.JPEGSegmentImageInputStream.streamInit(JPEGSegmentImageInputStream.java:247) at com.twelvemonkeys.imageio.plugins.jpeg.JPEGSegmentImageInputStream.fetchSegment(JPEGSegmentImageInputStream.java:71) at com.twelvemonkeys.imageio.plugins.jpeg.JPEGSegmentImageInputStream.repositionAsNecessary(JPEGSegmentImageInputStream.java:267)

示例图片

感谢@haraldK,通过更改从 blob 列获取字节数组的代码解决了我的问题。

List<Object[]> userRoleList = commonDao.findByNativeSQL(selectSQL
            , new Object[] {examCd, examPeriod, fromMemNo, toMemNo});
    for(Object[] row : userRoleList){
        CertificateDtlsVO cdObj = new CertificateDtlsVO();          
        cdObj.setExmCd(Integer.parseInt(row[0].toString()));
        cdObj.setExmDsc(row[1].toString());
        cdObj.setMemNo(row[2].toString());
        cdObj.setMemNm(row[3].toString());
        cdObj.setCertNo(row[4].toString());
        cdObj.setCertDt(row[5].toString());
        cdObj.setPrtNo(row[6].toString());
        cdObj.setSylCd(row[7].toString());
        cdObj.setNumOfTime(Integer.parseInt(row[8].toString()));
        cdObj.setMemType(row[9].toString());
        cdObj.setClassGrade(row[10].toString());
        InputStream photoBlob = ((Blob) row[11]).getBinaryStream();
        InputStream signBlob = ((Blob) row[12]).getBinaryStream();
        cdObj.setPhoto(IOUtils.toByteArray(photoBlob));
        cdObj.setSign(IOUtils.toByteArray(signBlob));
        memCertfDtlsList.add(cdObj);
    }