I am trying to read a fileinputstream that then gets passed to a calling function which is then played back in a webserver application viewer. The download works fine but the problem is that if I close the stream (which is recommended) within the same function the calling function receives a null stream for some reason. Someone suggested creating an inputstream wrapper and this will allow me to close the stream, delete the file and still pass the stream to the calling function.
public InputStream exportVideo(Youtube connection, String videoID) {
InputStream is = null;
....//file retrieval code above
is = new FileInputStream(ndirectory + "\\" + this.videoID.toString()
+ ".avi");
return is;
....//trace handling code below
finally{
is.close();
}
}
the calling function:
stream = FetchVideo.exportVideo(econnection, videoID);
what I am thinking the suggestion meant was have some class:
public class StreamConverter extends InputStream {
be the wrapper, but I have no idea how to do this. Any advice or ideas / links on how to do this effectively. Again the problem is closing the stream but being able to pass it on to the calling function.