とりあえず策
ということでまずは最小限の変更で対応するためにアドホックに。
...snip out.println("set terminal png"); out.println("plot sin(x)"); out.println("set output"); out.flush(); BufferedImage image1 = ImageIO.read(in); System.err.println(image1); //for (int i = 0; i < 16; i++) in.read(); in.skip(16); out.println("set terminal png"); out.println("plot sin(x+pi/10)"); out.println("set output"); out.flush(); BufferedImage image2 = ImageIO.read(in); System.err.println(image2); ...snip
なんのことはない。
一枚目の画像の読み残し16バイト分をスキップしているだけである。
実行すると、
BufferedImage@17599cc: type = 13 IndexColorModel: #pixelBits = 8 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1c45731 transparency = 1 transInd ex = -1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 64 0 height = 480 #numDataElements 1 dataOff[0] = 0 BufferedImage@10613aa: type = 13 IndexColorModel: #pixelBits = 8 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1c45731 transparency = 1 transInd ex = -1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 64 0 height = 480 #numDataElements 1 dataOff[0] = 0
今までnullで返ってきていた二枚目の画像も問題なく読み出せているようである。
もちろんこの方法は16バイト読み残されていることが前提の、その場限りの対応策である。