解码base64不能处理收到的照片(通过MQTT)

时间:2017-02-13 16:02:05

标签: java base64

我通过MQTT发送照片,并尝试保存该照片的副本。 这就是接收者所做的事情:

connectMQTTAsReceiver("Controller", "tcp://m2m.eclipse.org:1883", "robot");
byte[] photoByte=receiveMQTT.getBytes();
File photo=new File("image2.jpg");
photo.createNewFile();
FileOutputStream outputStream=new FileOutputStream(photo);
outputStream.write(photoByte);
outputStream.close();

这样,照片就会保存,但它完全是白色的。 然后我尝试这样做:

connectMQTTAsReceiver("Controller", "tcp://m2m.eclipse.org:1883", "robot");
byte[] photoByte=Base64.getDecoder().decode(receiveMQTT().getBytes(StandardCharsets.UTF_8));
InputStream in = new ByteArrayInputStream(photoByte);
System.out.println("Received");
BufferedImage bufferedImage;
try {
    bufferedImage = ImageIO.read(in);
    File outputfile = new File("image3.jpg");
    ImageIO.write(bufferedImage, "jpg", outputfile);
} catch (IOException e) {
    e.printStackTrace();
}

它给了我这个错误:

java.lang.IllegalArgumentException: Illegal base64 character -1e

0 个答案:

没有答案