E
Edward
I have created a class that extends ServletOutputStream. Right now it
does not do anything but my plan is to use this to capture and
manipulate data (byte[] b) sent to the output stream for my own
devices. The class is below:
package testPkg;
import java.io.IOException;
import javax.servlet.ServletOutputStream;
public class TestOutputStream extends ServletOutputStream{
public TestOutputStream(){
super();
}
public void write(byte[] b, int off, int len) throws IOException {
super.write(b,off,len);
}
public void write(int b){
}
}
<<<<<<<<<<<<<<<<<<<<<<<
I also have a simple servlet that I am trying to call this class in:
package testPkg;
import java.io.FileInputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class OutImageTest extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
FileInputStream fis = new FileInputStream("C:\\test.gif");
TestOutputStream sos =
(TestOutputStream)response.getOutputStream();
byte [] buffer = new byte [1024];
int len = 0;
while ((len = fis.read(buffer))>=0) {
sos.write(buffer, 0, len);
}
fis.close();
}
}
<<<<<<<<<<<<<<<<<<<<<<<
If I replace the line above:
TestOutputStream sos =
(TestOutputStream)response.getOutputStream();
with:
ServletOutputStream sos = response.getOutputStream();
the servlet works no problem but with the original line I get the
error: "java.lang.ClassCastException". Apparently it is having trouble
casting the ServletOutputStream to my class TestOutputStream even
though TestOutputStream extends ServletOutputStream although the
compiler (WebSphere, J2EE level 1.3) is requiring that I cast sos.
Anybody know what I am doing wrong?
Thanks.
Edward
does not do anything but my plan is to use this to capture and
manipulate data (byte[] b) sent to the output stream for my own
devices. The class is below:
package testPkg;
import java.io.IOException;
import javax.servlet.ServletOutputStream;
public class TestOutputStream extends ServletOutputStream{
public TestOutputStream(){
super();
}
public void write(byte[] b, int off, int len) throws IOException {
super.write(b,off,len);
}
public void write(int b){
}
}
<<<<<<<<<<<<<<<<<<<<<<<
I also have a simple servlet that I am trying to call this class in:
package testPkg;
import java.io.FileInputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class OutImageTest extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
FileInputStream fis = new FileInputStream("C:\\test.gif");
TestOutputStream sos =
(TestOutputStream)response.getOutputStream();
byte [] buffer = new byte [1024];
int len = 0;
while ((len = fis.read(buffer))>=0) {
sos.write(buffer, 0, len);
}
fis.close();
}
}
<<<<<<<<<<<<<<<<<<<<<<<
If I replace the line above:
TestOutputStream sos =
(TestOutputStream)response.getOutputStream();
with:
ServletOutputStream sos = response.getOutputStream();
the servlet works no problem but with the original line I get the
error: "java.lang.ClassCastException". Apparently it is having trouble
casting the ServletOutputStream to my class TestOutputStream even
though TestOutputStream extends ServletOutputStream although the
compiler (WebSphere, J2EE level 1.3) is requiring that I cast sos.
Anybody know what I am doing wrong?
Thanks.
Edward