Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with filter

Status
Not open for further replies.

lezhik

Programmer
Oct 21, 2003
20
0
0
RU
I want to write some class which must print some info. It contains an OutputStream to print this info, but I'd like to pass FilterOutputStream as a parameter to print method. How can I realize something like this?
 
>>>> FilterOutputStream as a parameter to print method.

I don't think this is possible - filter streams sit on top of instantiated IO streams to perform "filtering". You cannot pass them to print methods.

Here is an example of creating a FilterOutputStream -

Code:
FileOutputStream fos = new FileOutputStream("afile.txt");
FilterOutputStream fios = new FilterOutputStream(fos);
fios.write(1);
fios.write(2);
fios.flush();
fios.close();
fos.close();
 
I need to pass filter method to print in some way, is it possible? Using of FilterOutputStream isn't necessary.
 
>>>> Using of FilterOutputStream isn't necessary

But in your first post, you said you needed to use the FilterOutputStream ???!!!

>>>>> need to pass filter method to print in some way

What does this mean ?? Filter what ?
 
>>>But in your first post, you said you needed to use the FilterOutputStream ???!!!

It's better to do it with using FilterOutputStream, but the using of FilterOutputStream isn't necessary.

>>>Filter what ?

One of class metods writes some data to OutputStream (the stream is a class member), and want to filter this data. It'll be great if filter could be passed to print method as a parameter.
 
Can you not filter the data before you pass it to the OutputStream ?

As I said earlier, there are no standard methods to pass a "filter" to a print/write method of streams. Your only choice is to write a custom class that extends an OutputStream to do this, and override the print/write methods.
 
Maybe class could be generated by it's name? I have code which using class Class do it. If it so maybe filter class name should be passed to function. But I don't know : is this solution is really good?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top