C
christian.bongiorno
So, I have been working extensively with jar files of late and now we
need to migrate to tar files, and the nagging problem continues to be
LACK OF INTERFACE!
I mean, the use of a jar and a manifest using the API's is really
whacked -- you can't create a Manifest and add entries to it, you have
to create a properly formatted UTF-8 byte sequence. But of course, you
can READ manifest entries all day.
Now we have the issue of the Streams and files. The streams have a
handfull of methods in common, but do things like:
ZipEntry getNextEntry()
JarEntry getNextJarEntry()
Now, the implementation I have found for tar (which the API's do not
have) is that they too have similar method names (close(),
putNextEntry()) etc, but because there isn't a common interface for
archives, I cannot seemlessly process the above mentioned types.
What I have done, to facilitate thise generic behavior is to implement
a combination of adapter interfaces and delegation -- and then I only
have to switch my current code to the new interface.
basically, I have done is
public interface ArchiveInputStream {
public ArchiveEntry nextEntry() throws IOException;
public int read(byte[] outBucket,int start, int amount) throws
IOException;
public void close() throws IOException;
}
public class MyJarInputStream extends JarInputStream implements
ArchiveInputStream {
private static final Log logger =
LogFactory.getLog(DaveJarInputStream.class);
public MyJarInputStream (InputStream in) throws IOException {
super(in);
}
public ArchiveEntry nextEntry() throws IOException {
return new JarArchiveEntry(getNextJarEntry());
}
}
I have done the same trick with the entry types for the archives and
OutputStreams
This seems to me to be exceptionally poor design in the Java libraries
-- a rarity.
Thoughts? Am I just spiking my java with peyote or what?
Christian
http://christian.bongiorno.org
need to migrate to tar files, and the nagging problem continues to be
LACK OF INTERFACE!
I mean, the use of a jar and a manifest using the API's is really
whacked -- you can't create a Manifest and add entries to it, you have
to create a properly formatted UTF-8 byte sequence. But of course, you
can READ manifest entries all day.
Now we have the issue of the Streams and files. The streams have a
handfull of methods in common, but do things like:
ZipEntry getNextEntry()
JarEntry getNextJarEntry()
Now, the implementation I have found for tar (which the API's do not
have) is that they too have similar method names (close(),
putNextEntry()) etc, but because there isn't a common interface for
archives, I cannot seemlessly process the above mentioned types.
What I have done, to facilitate thise generic behavior is to implement
a combination of adapter interfaces and delegation -- and then I only
have to switch my current code to the new interface.
basically, I have done is
public interface ArchiveInputStream {
public ArchiveEntry nextEntry() throws IOException;
public int read(byte[] outBucket,int start, int amount) throws
IOException;
public void close() throws IOException;
}
public class MyJarInputStream extends JarInputStream implements
ArchiveInputStream {
private static final Log logger =
LogFactory.getLog(DaveJarInputStream.class);
public MyJarInputStream (InputStream in) throws IOException {
super(in);
}
public ArchiveEntry nextEntry() throws IOException {
return new JarArchiveEntry(getNextJarEntry());
}
}
I have done the same trick with the entry types for the archives and
OutputStreams
This seems to me to be exceptionally poor design in the Java libraries
-- a rarity.
Thoughts? Am I just spiking my java with peyote or what?
Christian
http://christian.bongiorno.org