Code question

In Jalview2XML I see this:

int entryCount = 1;

do
{
jin = jprovider.getJarInputStream();
for (int i = 0; i < entryCount; i++)
{
jarentry = jin.getNextJarEntry();
}

if (jarentry != null && jarentry.getName().endsWith(".xml"))
{
… entryCount++;
}
else if (jarentry != null)
{
// Some other file here.
entryCount++;
}
} while (jarentry != null);

What’s the reason behind doing that instead of:

int entryCount = 1;

jin = jprovider.getJarInputStream();
do
{
jarentry = jin.getNextJarEntry();
if (jarentry != null && jarentry.getName().endsWith(".xml"))
{
… entryCount++;
}
} while (jarentry != null);

Isn’t the first unnecessarily opening and reading completely the jar file as many time as there are jar entries? Why not just read it straight through? So, for example, each URL would be opened and read three times for a standard file.

Also, can you tell me why a Jalview session file has two models, both of which are read, but only one of which is displayed? One has a full path to it. The other does not. One is the original? and the other is the save? Is that it? But why read both?

Bob

···

Robert M. Hanson
Professor of Chemistry
St. Olaf College
Northfield, MN
http://www.stolaf.edu/people/hansonr

If nature does not answer first what we want,
it is better to take what answer we get.

– Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900

Hi Bob. I renamed this thread - ‘Code Question’ isn’t very descriptive.

In Jalview2XML I see this:

int entryCount = 1;

do
{
jin = jprovider.getJarInputStream();
for (int i = 0; i < entryCount; i++)
{
jarentry = jin.getNextJarEntry();
}

if (jarentry != null && jarentry.getName().endsWith(“.xml”))
{
… entryCount++;
}
else if (jarentry != null)
{
// Some other file here.
entryCount++;
}
} while (jarentry != null);

What’s the reason behind doing that instead of:

int entryCount = 1;

jin = jprovider.getJarInputStream();
do
{
jarentry = jin.getNextJarEntry();
if (jarentry != null && jarentry.getName().endsWith(“.xml”))
{
… entryCount++;
}
} while (jarentry != null);

Isn’t the first unnecessarily opening and reading completely the jar file as many time as there are jar entries?

not as far as I can see ? There’s only one call to getJarInputStream (before the first for loop).

Why not just read it straight through? So, for example, each URL would be opened and read three times for a standard file.

Some readers would close the JarInputStream after handling the entry, so we implemented a belt’n’braces mechanism here. Remember these are normally local files, so no harm done…

Also, can you tell me why a Jalview session file has two models, both of which are read, but only one of which is displayed? One has a full path to it. The other does not. One is the original? and the other is the save? Is that it? But why read both?

Jalview has n+1 ‘models’ in a project: the ‘dataset’ (all sequences without gaps, holds features, annotation and coding relationships) - corresponds to the Dataset alignment returned by AlignmentI.getDataSet(). The other ‘n’ are one or more alignment views - which are grouped by Alignment ID to indicate different views on the same alignment.

al is klar ? :wink:

j.

···

On 04/11/2018 20:36, Robert Hanson wrote: