commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Torsten Curdt <>
Subject [compress] What is the purpose of the reflection usage in ArchiveStreamFactory and CompressorStreamFactory?
Date Sun, 05 Oct 2008 14:27:10 GMT
Hey there

> Out of curiosity why must reflection be used for the create*Stream()  
> methods in the ArchiveStreamFactory and CompressorStreamFactory?  
> There is a cast at the end of each method to a corresponding  
> interface anyway (ex ArchiveInputStream, ArchiveOutputStream, etc)  
> so why cant we use this knowledge ahead of time and execute on the  
> interface?

I think the idea that it makes "dropping in" a new implementation  
easier. But I agree with you.

As the registerArchive*Stream methods need to be called to register  
the implementation this becomes a moo point.

I would change the factory to

     public ArchiveInputStream createArchiveInputStream( final String  
archiverName, final InputStream stream ) throws ArchiveException {

        if ("ar".equals(archiverName)) {
           return new ArAchiveInputStream(stream)


        return null;

and then instead of registering a new implementation you just extend  
the factory and overload the create*Stream methods to add your custom  
impl ...and of course delegate to the super class.

> The current implementation makes it next to impossible to capture  
> errors being thrown by the constructors of new implementations since  
> the reflective methods discard any Exceptions and simply return null.

Hm ... I thought that would be indeed possible:


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message