//game template logo
if (entity.equals("gameTemplate")) {
//Session hibernateSession=HibernateSessions.startTransactionSilently();
Session hibernateSession = HibernateSessions.getSessionFactory().openSession();
try {
GameTemplate gt=GameTemplateDao.findGameTemplate(id,hibernateSession);
if (gt.getLogo()==null) {
try {
res.setContentType("image/png");
OutputStream os = res.getOutputStream();
ImageIO.write(getNullImage(), "png", os);
os.close();
} catch (Exception e) {
}
} else {
res.setContentType(gt.getLogoType());
try {
InputStream in=gt.getLogo().getBinaryStream();
OutputStream out = res.getOutputStream();
byte[] buf = new byte[1024];
int count = 0;
while((count = in.read(buf)) >= 0) {
out.write(buf, 0, count);
}
out.close();
} catch (Exception e) {
}
}
} catch (Exception e) {
} finally {
//HibernateSessions.finishTransactionSilently(hibernateSession);
hibernateSession.close();
}
}
//TODO refactor this - extract method
//game logo
if (entity.equals("game")) {
// Session hibernateSession=HibernateSessions.startTransactionSilently();
Session hibernateSession = HibernateSessions.getSessionFactory().openSession();
try {
Game gt=GameDao.findGame(id,hibernateSession);
if (gt.getLogo()==null) {
try {
res.setContentType("image/png");
OutputStream os = res.getOutputStream();
ImageIO.write(getNullImage(), "png", os);
os.close();
} catch (Exception e) {
}
} else {
res.setContentType(gt.getLogoType());
try {
InputStream in=gt.getLogo().getBinaryStream();
OutputStream out = res.getOutputStream();
byte[] buf = new byte[1024];
int count = 0;
while((count = in.read(buf)) >= 0) {
out.write(buf, 0, count);