[jetty-dev] [jira] (JETTY-1513) DirectNIOBuffer does not release the file it is constructed from, consequently one cannot delete the file.

"Warren Goldman (JIRA)" <[email protected]>
Newsgroups gmane.comp.java.jetty.general
Message-ID <1175851572.75724.1336139702969.JavaMail.j2ee-jira@codehaus01.managed.contegix.com>
    [ https://jira.codehaus.org/browse/JETTY-1513?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=297814#comment-297814 ] 

Warren Goldman edited comment on JETTY-1513 at 5/4/12 8:54 AM:
---------------------------------------------------------------

This might be fixed, since the DirectNIOBuffer class simply by its' construction is leaving input streams open. 

There are options;
1) provide a mechanism for the caller to cleanup after it, 
2) have DirectNIOBuffer clean up after itself - I realize this is the most difficult
3) provide a constructor that accepts the input stream so the caller can take care of this, if needed

There are various options that could be pursued. Stating this is simply a windows issue, means this class is not really usable for those few of us that are actually using windows.

    public DirectNIOBuffer(File file) throws IOException
    {
        super(READONLY,NON_VOLATILE);
        FileInputStream fis = new FileInputStream(file);
        FileChannel fc = fis.getChannel();
        _buf = fc.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
        setGetIndex(0);
        setPutIndex((int)file.length());
        _access=IMMUTABLE;
    }



                
      was (Author: wgoldman):
    This could be fixed, since the DirectNIOBuffer class simply by its' construction is leaving input streams open. Laying the issue on the operating system is a cop out.

There are numerous options;
1) provide a mechanism for the caller to cleanup after it, 
2) have DirectNIOBuffer clean up after itself - I realize this is the most difficult
3) provide a constructor that accepts the input stream so the caller can take care of this, if needed

There are various options that could be pursued. Stating this is simply a windows issue, means this class is not really usable for those few of us that are actually using windows.

    public DirectNIOBuffer(File file) throws IOException
    {
        super(READONLY,NON_VOLATILE);
        FileInputStream fis = new FileInputStream(file);
        FileChannel fc = fis.getChannel();
        _buf = fc.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
        setGetIndex(0);
        setPutIndex((int)file.length());
        _access=IMMUTABLE;
    }



                  
> DirectNIOBuffer does not release the file it is constructed from, consequently one cannot delete the file.
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: JETTY-1513
>                 URL: https://jira.codehaus.org/browse/JETTY-1513
>             Project: Jetty
>          Issue Type: Bug
>          Components: NIO
>            Reporter: Warren Goldman
>            Assignee: Jan Bartel
>
> 		Path file = Paths.get("C:/Temp/my.test");
> 		DirectNIOBuffer buffer = new DirectNIOBuffer(file.toFile());
> 		Files.deleteIfExists(file);
> 		// the Files.deleteIfExists throws the following exception
> //		java.nio.file.FileSystemException: C:\Temp\my.test: The process cannot access the file because it is being used by another process.
> //		at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:86)
> //		at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
> //		at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
> //		at sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:268)
> //		at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(AbstractFileSystemProvider.java:108)
> //		at java.nio.file.Files.deleteIfExists(Files.java:1110)
> //		at test.MyTest.run(MyTest.java:28)
> //		at test.MyTest.main(MyTest.java:41)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://jira.codehaus.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.