use of de.janrufmonitor.service.client.request.handler.GetImageHandler in project janrufmonitor by tbrandt77.
the class HttpImageProvider method getImage.
public File getImage(ICaller caller) {
if (caller.getPhoneNumber().isClired())
return null;
File cacheFile = (File) ImageCache.getInstance().get(caller.getPhoneNumber().getTelephoneNumber());
if (cacheFile != null) {
this.m_logger.info("Taking image file from cache: " + cacheFile.getName());
return cacheFile;
}
try {
IHttpRequest cgh = new GetImageHandler(caller.getPhoneNumber(), this.m_cm);
IRequester r = this.getRequester(cgh);
InputStream in = new BufferedInputStream(r.request().getContentStreamForRead());
File tmpOut = new File(PathResolver.getInstance().getTempDirectory() + "~images" + File.separator + caller.getPhoneNumber().getTelephoneNumber() + this.getExtension("image/jpeg"));
if (!tmpOut.exists()) {
tmpOut.getParentFile().mkdirs();
tmpOut.createNewFile();
}
FileOutputStream fos = new FileOutputStream(tmpOut);
Stream.copy(in, fos);
in.close();
fos.flush();
fos.close();
ImageCache.getInstance().add(caller.getPhoneNumber().getTelephoneNumber(), tmpOut);
return tmpOut;
} catch (MalformedURLException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (NullPointerException e) {
this.m_logger.log(Level.WARNING, e.getMessage(), e);
} catch (Exception e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
return null;
}
use of de.janrufmonitor.service.client.request.handler.GetImageHandler in project janrufmonitor by tbrandt77.
the class HttpImageProvider method getImagePath.
public String getImagePath(ICaller caller) {
if (caller.getPhoneNumber().isClired())
return "";
if (!hasImage(caller))
return "";
try {
IHttpRequest cgh = new GetImageHandler(caller.getPhoneNumber(), this.m_cm);
IRequester r = this.getRequester(cgh);
return "http://" + r.getServer() + ":" + r.getPort() + cgh.getURI().toString();
} catch (MalformedURLException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (Exception e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
return "";
}
Aggregations