}
final InputStream in = getResourceAsStream(caller);
if (in == null)
{
throw new ResourceLoadingException("Unable to read Stream: No input stream: " + getKey());
}
try
{
if (offset > 0)
{
long toBeSkipped = offset;
long skipResult = in.skip(toBeSkipped);
toBeSkipped -= skipResult;
while (skipResult > 0 && toBeSkipped > 0)
{
skipResult = in.skip(offset);
toBeSkipped -= skipResult;
}
if (toBeSkipped > 0)
{
// failed to read up to the offset ..
throw new ResourceLoadingException
("Unable to read Stream: Skipping content failed: " + getKey());
}
}
int bytesToRead = length;
// the input stream does not supply accurate available() data
// the zip entry does not know the size of the data
int bytesRead = in.read(target, length - bytesToRead, bytesToRead);
while (bytesRead > -1 && bytesToRead > 0)
{
bytesToRead -= bytesRead;
bytesRead = in.read(target, length - bytesToRead, bytesToRead);
}
return length - bytesRead;
}
finally
{
in.close();
}
}
catch (ResourceLoadingException rle)
{
throw rle;
}
catch (IOException e)
{
throw new ResourceLoadingException("Unable to read Stream: ", e);
}
}