Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Problems deleting JAR-Archives under Windows when using URIHandlerImpl
Problems deleting JAR-Archives under Windows when using URIHandlerImpl [message #429612] Mon, 27 April 2009 16:04 Go to next message
Sascha Theves is currently offline Sascha ThevesFriend
Messages: 39
Registered: July 2009
Member
Hi all,

the following test fails for me under Windows:

public class URIHandlerTest extends TestCase
{

public void testname() throws Exception
{
// setup - create a jar file to create an input stream from
File jarFile = new File("test.jar");
createJarFile("file.txt", new
ByteArrayInputStream("content".getBytes()), jarFile);
assertTrue(jarFile.exists());
URI uri = URI.createURI("jar:file:////" + jarFile.getAbsolutePath()
+ "!/file.txt");

URIHandlerImpl handler = new URIHandlerImpl();
InputStream in = handler.createInputStream(uri, new HashMap());
in.close();
jarFile.delete();
assertFalse(jarFile.exists());
}

private void createJarFile(String fileName, InputStream content, File
jarFile) throws FileNotFoundException,
IOException, CoreException
{
JarOutputStream jarOut = null;
try
{
jarOut = new JarOutputStream(new FileOutputStream(jarFile));

try
{
jarOut.putNextEntry(new JarEntry(fileName));
IOUtils.copyLarge(content, jarOut);
}
finally
{
jarOut.closeEntry();
}
}
finally
{
if (jarOut != null)
{
jarOut.flush();
jarOut.closeEntry();
jarOut.close();
}
}
}

public static long copyLarge(InputStream input, OutputStream output)
throws IOException
{
byte[] buffer = new byte[1024 * 4];
long count = 0;
int n = 0;
while (-1 != (n = input.read(buffer)))
{
output.write(buffer, 0, n);
count += n;
}
return count;
}

}


The test does not fail if I do not call the URIHandlerImpl. I think the
problem is that the URIHandlerImpl creates a new URLConnection and does
not call URLConnection#setUseCaches(false).

Has anybody an idea how to fix the problem with a workaround?

Thanks in advance,

Sascha
Re: Problems deleting JAR-Archives under Windows when using URIHandlerImpl [message #429616 is a reply to message #429612] Mon, 27 April 2009 16:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Sascha,

Probably you should be using ArchiveURLHandlerImpl. In fact, why not
use a ExtensibleURIConverterImpl which will pick the right kind of
handler depending on the URI...


Sascha Theves wrote:
> Hi all,
>
> the following test fails for me under Windows:
>
> public class URIHandlerTest extends TestCase
> {
>
> public void testname() throws Exception
> {
> // setup - create a jar file to create an input stream from
> File jarFile = new File("test.jar");
> createJarFile("file.txt", new
> ByteArrayInputStream("content".getBytes()), jarFile);
> assertTrue(jarFile.exists());
> URI uri = URI.createURI("jar:file:////" +
> jarFile.getAbsolutePath() + "!/file.txt");
>
> URIHandlerImpl handler = new URIHandlerImpl();
> InputStream in = handler.createInputStream(uri, new HashMap());
> in.close();
> jarFile.delete();
> assertFalse(jarFile.exists());
> }
>
> private void createJarFile(String fileName, InputStream content,
> File jarFile) throws FileNotFoundException,
> IOException, CoreException
> {
> JarOutputStream jarOut = null;
> try
> {
> jarOut = new JarOutputStream(new FileOutputStream(jarFile));
>
> try
> {
> jarOut.putNextEntry(new JarEntry(fileName));
> IOUtils.copyLarge(content, jarOut);
> }
> finally
> {
> jarOut.closeEntry();
> }
> }
> finally
> {
> if (jarOut != null)
> {
> jarOut.flush();
> jarOut.closeEntry();
> jarOut.close();
> }
> }
> }
>
> public static long copyLarge(InputStream input, OutputStream output)
> throws IOException
> {
> byte[] buffer = new byte[1024 * 4];
> long count = 0;
> int n = 0;
> while (-1 != (n = input.read(buffer)))
> {
> output.write(buffer, 0, n);
> count += n;
> }
> return count;
> }
>
> }
>
>
> The test does not fail if I do not call the URIHandlerImpl. I think
> the problem is that the URIHandlerImpl creates a new URLConnection and
> does not call URLConnection#setUseCaches(false).
> Has anybody an idea how to fix the problem with a workaround?
>
> Thanks in advance,
>
> Sascha
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Problems deleting JAR-Archives under Windows when using URIHandlerImpl [message #429627 is a reply to message #429616] Tue, 28 April 2009 06:48 Go to previous messageGo to next message
Sascha Theves is currently offline Sascha ThevesFriend
Messages: 39
Registered: July 2009
Member
Hi Ed,

thanks for the answer. We are using the ExtensibleURIConverterImpl but
thats the problem. When we load an EMF Resource, with Resource#load(uri),
with an jar:// scheme the URIConverter picks up the right URIHandler to
handle the JAR-URI. Now once loaded a EMF resource from the JAR-Archive,
the archive can not be deleted. I only wrote the test for the
URIHandlerImpl to strip up unecessary code.

Kind Regards,

Sascha

Ed Merks wrote:

> Sascha,

> Probably you should be using ArchiveURLHandlerImpl. In fact, why not
> use a ExtensibleURIConverterImpl which will pick the right kind of
> handler depending on the URI...


> Sascha Theves wrote:
>> Hi all,
>>
>> the following test fails for me under Windows:
>>
>> public class URIHandlerTest extends TestCase
>> {
>>
>> public void testname() throws Exception
>> {
>> // setup - create a jar file to create an input stream from
>> File jarFile = new File("test.jar");
>> createJarFile("file.txt", new
>> ByteArrayInputStream("content".getBytes()), jarFile);
>> assertTrue(jarFile.exists());
>> URI uri = URI.createURI("jar:file:////" +
>> jarFile.getAbsolutePath() + "!/file.txt");
>>
>> URIHandlerImpl handler = new URIHandlerImpl();
>> InputStream in = handler.createInputStream(uri, new HashMap());
>> in.close();
>> jarFile.delete();
>> assertFalse(jarFile.exists());
>> }
>>
>> private void createJarFile(String fileName, InputStream content,
>> File jarFile) throws FileNotFoundException,
>> IOException, CoreException
>> {
>> JarOutputStream jarOut = null;
>> try
>> {
>> jarOut = new JarOutputStream(new FileOutputStream(jarFile));
>>
>> try
>> {
>> jarOut.putNextEntry(new JarEntry(fileName));
>> IOUtils.copyLarge(content, jarOut);
>> }
>> finally
>> {
>> jarOut.closeEntry();
>> }
>> }
>> finally
>> {
>> if (jarOut != null)
>> {
>> jarOut.flush();
>> jarOut.closeEntry();
>> jarOut.close();
>> }
>> }
>> }
>>
>> public static long copyLarge(InputStream input, OutputStream output)
>> throws IOException
>> {
>> byte[] buffer = new byte[1024 * 4];
>> long count = 0;
>> int n = 0;
>> while (-1 != (n = input.read(buffer)))
>> {
>> output.write(buffer, 0, n);
>> count += n;
>> }
>> return count;
>> }
>>
>> }
>>
>>
>> The test does not fail if I do not call the URIHandlerImpl. I think
>> the problem is that the URIHandlerImpl creates a new URLConnection and
>> does not call URLConnection#setUseCaches(false).
>> Has anybody an idea how to fix the problem with a workaround?
>>
>> Thanks in advance,
>>
>> Sascha
>>
Re: Problems deleting JAR-Archives under Windows when using URIHandlerImpl [message #429631 is a reply to message #429627] Tue, 28 April 2009 10:46 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Sascha,

Reducing it to a different code path is a bit confusing then. Perhaps
specializing AcrhiveURILHandler.createArchive to create a derived
Archive for which useZipFile is false will help. I suspect that's
what's doing the caching for faster access...


Sascha Theves wrote:
> Hi Ed,
>
> thanks for the answer. We are using the ExtensibleURIConverterImpl but
> thats the problem. When we load an EMF Resource, with
> Resource#load(uri), with an jar:// scheme the URIConverter picks up
> the right URIHandler to handle the JAR-URI. Now once loaded a EMF
> resource from the JAR-Archive, the archive can not be deleted. I only
> wrote the test for the URIHandlerImpl to strip up unecessary code.
>
> Kind Regards,
>
> Sascha
>
> Ed Merks wrote:
>
>> Sascha,
>
>> Probably you should be using ArchiveURLHandlerImpl. In fact, why not
>> use a ExtensibleURIConverterImpl which will pick the right kind of
>> handler depending on the URI...
>
>
>> Sascha Theves wrote:
>>> Hi all,
>>>
>>> the following test fails for me under Windows:
>>>
>>> public class URIHandlerTest extends TestCase
>>> {
>>>
>>> public void testname() throws Exception
>>> {
>>> // setup - create a jar file to create an input stream from
>>> File jarFile = new File("test.jar");
>>> createJarFile("file.txt", new
>>> ByteArrayInputStream("content".getBytes()), jarFile);
>>> assertTrue(jarFile.exists());
>>> URI uri = URI.createURI("jar:file:////" +
>>> jarFile.getAbsolutePath() + "!/file.txt");
>>>
>>> URIHandlerImpl handler = new URIHandlerImpl();
>>> InputStream in = handler.createInputStream(uri, new HashMap());
>>> in.close();
>>> jarFile.delete();
>>> assertFalse(jarFile.exists());
>>> }
>>>
>>> private void createJarFile(String fileName, InputStream content,
>>> File jarFile) throws FileNotFoundException,
>>> IOException, CoreException
>>> {
>>> JarOutputStream jarOut = null;
>>> try
>>> {
>>> jarOut = new JarOutputStream(new FileOutputStream(jarFile));
>>>
>>> try
>>> {
>>> jarOut.putNextEntry(new JarEntry(fileName));
>>> IOUtils.copyLarge(content, jarOut);
>>> }
>>> finally
>>> {
>>> jarOut.closeEntry();
>>> }
>>> }
>>> finally
>>> {
>>> if (jarOut != null)
>>> {
>>> jarOut.flush();
>>> jarOut.closeEntry();
>>> jarOut.close();
>>> }
>>> }
>>> }
>>>
>>> public static long copyLarge(InputStream input, OutputStream
>>> output) throws IOException
>>> {
>>> byte[] buffer = new byte[1024 * 4];
>>> long count = 0;
>>> int n = 0;
>>> while (-1 != (n = input.read(buffer)))
>>> {
>>> output.write(buffer, 0, n);
>>> count += n;
>>> }
>>> return count;
>>> }
>>>
>>> }
>>>
>>>
>>> The test does not fail if I do not call the URIHandlerImpl. I think
>>> the problem is that the URIHandlerImpl creates a new URLConnection
>>> and does not call URLConnection#setUseCaches(false).
>>> Has anybody an idea how to fix the problem with a workaround?
>>>
>>> Thanks in advance,
>>>
>>> Sascha
>>>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Re: [TENEO][EMF] EMFInterceptor + Session in callbacks
Next Topic:Cannot find EMF sources (was Re: Debugging EMF in Eclipse)
Goto Forum:
  


Current Time: Thu Apr 25 14:44:39 GMT 2024

Powered by FUDForum. Page generated in 0.03328 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top