473,414 Members | 1,667 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Filter Streams in Java

dmjpro
2,476 2GB
I checked out the Source code of Filter Streams in Java.
There i saw there is a corresponding underlying Streams and the methods simply being used of underlying Streams'.
One thing is mentioned chaining is there ... can you explain how it's significant?
May 18 '09 #1
7 2257
r035198x
13,262 8TB
Which classes exactly were you looking at and where is the chaining mentioned?
May 18 '09 #2
dmjpro
2,476 2GB
I am talking about the both Filter Streams (Input and Output). And have a look at this link for chaining ;)
May 18 '09 #3
r035198x
13,262 8TB
So I don't get your question. Chaining (and its benefits) are already explained on that site.
May 18 '09 #4
dmjpro
2,476 2GB
Well.... Then how chaining works? And there is no difference between InputStream and FilterInputStream? Then why the filtering comes in?
May 18 '09 #5
JosAH
11,448 Expert 8TB
@dmjpro
As per the API documentation: the FilterXXXStream classes wrap another XXXStream and do nothing by themselves, i.e. you have to sub-class those classes to make them do anything useful. e.g. the following class doesn't print any vowels:

Expand|Select|Wrap|Line Numbers
  1. public class ConsonantStream extends FilterOutputStream {
  2.  
  3.    public ConsonantStream(OutputStream os) { super(os); }
  4.  
  5.    public void write(int  b) throws IOException {
  6.       if ("aeiouAEIOU".indexOf((char)b) == -1)
  7.          super.write(b);
  8.    }
  9. }
  10.  
According to the documentation all the other write methods use this single argument method so everything ends up at that method for the actual writing.

kind regards,

Jos
May 18 '09 #6
dmjpro
2,476 2GB
Well, so add extra functionality i have to make my own ;)
Now what about chaining? How does it come into these streams ?
May 18 '09 #7
JosAH
11,448 Expert 8TB
@dmjpro
The FileOutputStream's methods all call its write(int b) method which, in turn calls the same method from the encapsulate OutputStream. That is what chaining is all about. You wrote you have read the source code of those filter streams, so you should've read how those classes implement it. Also re-read my little example: it is chained between a target OutputStream and the caller of my stream. That entire process can be repeated at will but chaining doesn't "come into streams"; it is just the decorator/wrapper pattern that does it all.

kind regards,

Jos
May 18 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Oracle3001 | last post by:
Hi All, I am looking to use a kalman filter to predict the motion of a throw ball. I was wondering if anybody knew of a java implementation of the broad outline of the equations involved in...
5
by: Alligator | last post by:
And more specifically what is the difference between an InputStream and a BufferedInputStream? When should I use one and when should I use the other? And why is there besides a...
8
by: noe | last post by:
Hello all devs!! I’m a student and I’m developing my Final Project in the University. I have to develop a driver for Windows XP that work so: I have a file in the HD (NTFS file system) of my PC...
2
by: bonk | last post by:
Hello how do I connect streams in c# ? Imagine the followung scenario: I have a StreamWriter that writes Text to a Stream. How can I tell that Stream to pass that Data to another Stream...
1
by: Chris | last post by:
I'm reading up on streams and I have two articles that seem to conflict with each other. One article describes streams and lists a few of the major ones (FileStream, Memory Stream, Network...
2
by: Jeff Calico | last post by:
Hello everyone I have sucessfully implemented a SAX filter to take a large XML data file, and strip it down to its essential elements, and then pass that on to an XSL transformer. (A bare bones...
3
by: Mr 200 | last post by:
Hi all ive just recently started learning java and was happy to find a forum that may be able to give me a little assistance. I have been set an excersize to create a filter processor that relays...
25
by: tmallen | last post by:
I'm parsing some text files, and I want to strip blank lines in the process. Is there a simpler way to do this than what I have here? lines = filter(lambda line: len(line.strip()) 0, lines) ...
1
by: CatchSandeepVaid | last post by:
Suppose i have one-to-one association between Product and ProductBasic. and we have applied filter on ProductBasic Class. I have applied this filter as in Java side we have one-to-one relationship...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.