11 package com.google.scrollview.ui;
13 import org.piccolo2d.nodes.PImage;
15 import java.io.BufferedReader;
16 import java.io.ByteArrayInputStream;
17 import java.io.IOException;
18 import javax.imageio.ImageIO;
19 import javax.xml.bind.DatatypeConverter;
42 public static PImage
readImage(
int size, BufferedReader in) {
43 char[] charbuffer =
new char[size];
45 while (numRead < size) {
48 newRead = in.read(charbuffer, numRead, size - numRead);
49 }
catch (IOException e) {
50 System.out.println(
"Failed to read image data from socket:" + e.getMessage());
58 if (numRead != size) {
59 System.out.println(
"Failed to read image data from socket");
63 byte[] binarydata = DatatypeConverter.parseBase64Binary(
new String(charbuffer));
65 ByteArrayInputStream byteStream =
new ByteArrayInputStream(binarydata);
67 PImage img =
new PImage(ImageIO.read(byteStream));
69 }
catch (IOException e) {
70 System.out.println(
"Failed to decode image data from socket" + e.getMessage());
static PImage readImage(int size, BufferedReader in)