bacoAlunos
ENGSOFT2019
BlueGrey
calm
Elegant
Català-Valencià - Catalan
中文 - Chinese (Simplified)
中文 - Chinese (Traditional)
Česky - Czech
Dansk - Danish
Nederlands - Dutch
English - English
Suomi - Finnish
Français - French
Deutsch - German
עברית - Hebrew
हिंदी - Hindi
Magyar - Hungarian
Bahasa Indonesia - Indonesian
Italiano - Italian
日本語 - Japanese
한국어 - Korean
मराठी - Marathi
Norsk - Norwegian
Polski - Polish
Português - Portuguese
Português - Portuguese (Brazil)
Русский - Russian
Slovenčina - Slovak
Slovenščina - Slovenian
Español - Spanish
Svenska - Swedish
Türkçe - Turkish
Oëzbekcha - Uzbek
Subversion Repositories
bacoAlunos
(root)
/
branches
/
v3
/
impl
/
src
/
java
/
pt
/
estgp
/
estgweb
/
web
/
ImageStream.java
@ 1844
- Rev 1312
Rev
Rev 1310
|
Blame
|
Compare with Previous
|
Last modification
|
View Log
|
RSS feed
package
pt.estgp.estgweb.web
;
import
jomm.dao.impl.AbstractDao
;
import
jomm.utils.StreamsUtils
;
import
org.apache.log4j.Logger
;
import
pt.estgp.estgweb.domain.ImageImpl
;
import
pt.estgp.estgweb.domain.dao.DaoFactory
;
import
pt.estgp.estgweb.services.data.ImageManager
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServlet
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
/**
* @author Fabio
* @date 4/Abr/2008
* @time 11:03:00
* @see pt.estgp.estgweb.web
*/
public
class
ImageStream
extends
HttpServlet
{
private
static
final
1.
5
.0/docs/api/java/util/logging/Logger.html">
Logger
logger =
1.
5
.0/docs/api/java/util/logging/Logger.html">
Logger
.
getLogger
(
ImageStream.
class
)
;
public
void
doGet
(
HttpServletRequest request, HttpServletResponse response
)
throws
ServletException,
1.
5
.0/docs/api/java/io/IOException.html">
IOException
{
1.
5
.0/docs/api/java/lang/String.html">
String
imageRequarired = request.
getPathInfo
(
)
;
imageRequarired = imageRequarired.
substring
(
1
)
;
long
id =
1.
5
.0/docs/api/java/lang/Long.html">
Long
.
parseLong
(
imageRequarired.
trim
(
)
)
;
AbstractDao.
getCurrentSession
(
)
.
beginTransaction
(
)
;
ImageImpl image =
(
ImageImpl
)
DaoFactory.
getImageDaoImpl
(
)
.
get
(
id
)
;
try
{
response.
setContentType
(
image.
getContentType
(
)
)
;
5+
0
%
2Fdocs
%
2Fapi+OutputStream">
OutputStream
out = response.
getOutputStream
(
)
;
byte
[
]
imagemStream = image.
getImage
(
)
;
if
(
imagemStream ==
null
)
{
5+
0
%
2Fdocs
%
2Fapi+InputStream">
InputStream
stream = ImageManager.
load
(
image
)
;
response.
setContentLength
(
image.
getSize
(
)
)
;
StreamsUtils.
inputStream2OutputStream
(
stream,out
)
;
}
else
{
response.
setContentLength
(
imagemStream.
length
)
;
out.
write
(
imagemStream
)
;
}
out.
flush
(
)
;
out.
close
(
)
;
}
catch
(
1.
5
.0/docs/api/java/lang/Throwable.html">
Throwable
e1
)
{
logger.
error
(
e1
)
;
response.
sendError
(
404
)
;
}
AbstractDao.
getCurrentSession
(
)
.
getTransaction
(
)
.
commit
(
)
;
}
}