File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes FilterOutputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "FilterOutputStream" Watch "FilterOutputStream" New topic
Author

FilterOutputStream

sheri
Ranch Hand

Joined: Sep 14, 2000
Posts: 43
hi
what are the possible parameters that can be passed into the construcor of a
FilterInputStream
a.File b.PrintStream c.FileOutputStream d.FileInputStream e.RandomAccessFile

can anybody ans to this Question:
my ans is a:File & b:PrintStream
please help
thanx
sherin
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
FilterInputStream(InputStream in) - This is the only constructor available for this class.
Therefore all those params that can be converted to
InputStream in would be valid.
In your case:
File - It extends Object. So u can't use this.
PrintStream - not a subclass of InputStream, but a subclass of OutputStream. The hierarchy is :
outputStream -> FilterOutputStream->
Therefore, we can't use this as well.
FileInputStream - Subclass of InputStream. so, this is OK.
RandomAccessFile - NO ! Coz it does fall under any of the InputStream hierarchy.
Therefore my ans would just be FileInputStream .
Please let me if there is something wrong with this reasoning.
-sampaths77
geetha
Greenhorn

Joined: Jun 27, 2001
Posts: 15
Hi sampaths77,
have u tried by passing the FileInputStream into FilterInputStream constructor???becz it is saying that there is no constructor matching for FilterInputStream.and moreover FilterInputStream and FileInputStream belongs to the same level of streams.in that case u can not pass one stream into another.
only the ans could be InputStream.
geetha.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Geetha,
please try this:
import java.io.*;
class B extends java.io.FilterInputStream
{
B() throws Exception
{
super (new FileInputStream("yahoo"));
}
public static void main(String[] args)
{
}

}
I am able to compile this piece of code fine.
PLease note that questio just asked:what are the POSSIBLE parameters that can be passed into the construcor of a
FilterInputStream. Since i can do with the above code, I opted for FileInputStream
Plus you say that FileInputStream and FilterInputStream are in the siblings, but this has got nothing to do with the answer coz if u look at the constructor, the i/p param is InputStream. So, the code should compile for all subclasses of imputstream.
Hope this helps
-sampaths77
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FilterOutputStream