How do I go about downloading the image generated at Leaflet easyPrint button using HtmlUnit?
I am trying it like this:
public static void main(String[] args) {
try{
WebClient webClient = new WebClient();
HtmlPage test = webClient.getPage("http://rowanwins.github.io/leaflet-easyPrint/");
webClient.waitForBackgroundJavaScript(5000);
final DomElement button = test.getFirstByXPath("/html/body/button");
final InputStream image = button.click().getWebResponse().getContentAsStream();
System.out.println(image);
File file = new File("/home/josue/Basis/STS4/map.png");
copyInputStreamToFile(image, file);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void copyInputStreamToFile(InputStream inputStream, File file)
throws IOException {
try (FileOutputStream outputStream = new FileOutputStream(file)) {
int read;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
}
}
And getting a blank PNG file with about 3Kb. What is the proper way to get it working?
EDIT: The reason I want to accomplish it, is to get a simple alternative for Google Maps static API, which I currently have deployed in a running project.