You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-user@hadoop.apache.org by Miguel Ángel Álvarez de la Concepción <ma...@us.es> on 2010/05/15 13:48:46 UTC
BufferStream from Hadoop file
Hi,
I develop an application that receive a stream file from Hadoop.
The client code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Prueba video</title>
</head>
<body>
<object id="video" width="320" height="240"
classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6"
type="application/x-oleobject">
<param name="url" value="GetVideo">
<param name="SendPlayStateChangeEvents" value="true">
<param name="AutoStart" VALUE="true">
<param name="uiMode" value="none">
<param name="PlayCount" value="9999">
</object>
</body>
</html>
The server code from servlet:
protected void processRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ServletContext sc = getServletContext();
try {
response.reset();
response.setBufferSize(10240);
response.setContentType("video/avi");
Configuration config = new Configuration();
config.set("fs.default.name", HADOOP_DIR + ":" + HADOOP_PORT);
config.set("hadoop.job.ugi", "root, supergroup");
FileSystem hadoopFileSystem = FileSystem.get(config);
Path ficheroOrigen = new Path(hadoopFileSystem.getWorkingDirectory()
+ "/test/prueba.avi");
FSDataInputStream in = hadoopFileSystem.open(ficheroOrigen);
ServletOutputStream os = response.getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(os, 10240);
int read = 0;
byte[] bytes = new byte[512];
while((read = in.read(bytes)) != -1) {
bos.write(bytes, 0, read);
}
sc.log("Fin de la lectura del video.");
bos.close();
in.close();
hadoopFileSystem.close();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
I get a SocketException from client, because I need a BufferedFSInputStream
from Hadoop file. The BufferedFSInputStream class have a construct like
this:
BufferedFSInputStream(FSInputStream in, int size)
How do I obtain a buffer stream from hadoop file?
Miguel Ángel Álvarez de la Concepción
Departamento de Lenguajes y Sistemas Informáticos
Escuela Técnica Superior de Ingeniería Informática
Universidad de Sevilla
Teléfono: 954.556.086
Email: maalvarez@us.es