[izpack-devel] Issues while reading data from packs

Michael Scherer mscherer at gis-systemhaus.de
Fri Aug 4 12:35:56 CEST 2006


Hi Klaus, thanks for the quick answer.
Though I have a few points to discuss, see below.

Bartz, Klaus schrieb:

>> While doing this I'm trying to find all filenames by reading them
>>from the packs like the InstallPanel does ...
> 
> ?? The Unpacker reads the pack "files" (entries in the jar file).
Exactly, thats what I "copied".

>> Now when doing "PackFile packFile = 
>> (PackFile)packStream.readObject();" I get
>> java.io.OptionalDataException
>>         at java.io.ObjectInputStream.readObject0(Unknown Source)
>>         at java.io.ObjectInputStream.readObject(Unknown Source)
>>         at 
> 
> The structure of a pack is really specific. There are ints, packs
> and the data in a well (not documented) order. If you would read the
> hole pack file you have to skip the "to be installed part". 
> That's what you NOT DO. 
> Seems so, you think that the pack file only
> contains the information of a pack. No, it contains the hole pack.
Ok, if you say so. :)
Though I still wonder why my source breaks.

Unpacker.java:
for (int i = 0; i < npacks; i++)
{
	// We get the pack stream
	int n = idata.allPacks.indexOf(packs.get(i));

	// Custom action listener stuff --- beforePack ----
	informListeners(customActions, InstallerListener.BEFORE_PACK, packs.get(i),
		new Integer(npacks), handler);
	ObjectInputStream objIn = new ObjectInputStream(getPackAsStream(n));

	// We unpack the files
	int nfiles = objIn.readInt();  // <<<< FIRST ACCESS to stream

	// We get the internationalized name of the pack
	final Pack pack = ((Pack) packs.get(i));
	String stepname = pack.name;// the message to be passed to the
	// installpanel

	[...] Skips langpack stuff [...]

	for (int j = 0; j < nfiles; j++)
	{
		// We read the header
		PackFile pf = (PackFile) objIn.readObject(); // <<<< SECOND ACCESS to stream
	[...]
}

OpenBackupPanel.java
for(int i = 0; i < packs.size(); i++)
{
	// get the pack for later usage
	final Pack p = (Pack)packs.get(i);
	System.err.println(">>> PackName: " + p.name);

	// position of pack in packs
	int n = idata.allPacks.indexOf(packs.get(i));

	ObjectInputStream packStream =
		new ObjectInputStream(getPackAsStream(idata, 	
	// get the number of files in the pack
	int nfiles = packStream.readInt(); // <<<< FIRST ACCESS, works

	// iterate over file entries
	for(int j = 0; j < nfiles; j++)
	{
		PackFile packFile = (PackFile)packStream.readObject(); <<<< SECOND ACCESS, 
same as in the Unpacker.java, though borks with an Exception
	[...]
}

Now if I'm right the Unpacker doesn't skip anything as well.

You are for sure right about the performance stuff but to be honest, I'd 
prefer a backup instead of a faster installer.

> If I have to implement something like this, I think I will implement
> an InstallListener which implements isFileListener and
> beforeFile.
> isFileListener returns true,
> beforeFile makes the backup.
> See as example 
> %IZ_HOME%\sample\src\myCompany\tools\install\listener\ChmodInstallerListener.java
> 
> You conserve about the real hard job to find the files which are
> selected for installation. That's with "selected" is not to much simple,
> the Unpacker needs over 150 lines of code to handle it.
> beforeFile will be called from the Unpacker before a file will be installed. 
Correct, I'd save a load of work but lose the ability to display the backup on 
a separate panel. Though not everyone would need that, I'd prefer it.


Right, hope you can give me a hint for the above code.

Greeetings,
  Michael




More information about the izpack-devel mailing list