Quantcast

Gdal Java - Translate creates indestructible file

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Gdal Java - Translate creates indestructible file

Vlad
Almost indestructable.

Making a .png thumbnail...

public String produceThumbnail(Dataset ds, Path tempPath)
{
        Vector<String> optionsVector = new Vector<>();
        optionsVector.add("-of");
        optionsVector.add("PNG");
        optionsVector.add("-outsize");
        optionsVector.add("128");
        optionsVector.add("128");
        TranslateOptions options = new TranslateOptions(optionsVector);

        try
        {
            String name = tempPath + "/" + String.format("%s.%s", RandomStringUtils.randomAlphanumeric(16), "png");
            org.gdal.gdal.gdal.Translate(name, ds, options);
            tmpFile = new File(name);
            if (tmpFile.exists())
            {
                //read in bytes to Base64 encoded String
                FileUtils.forceDelete(tempPath.toFile());
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return theString;
}

It creates two files, a .png and a .png.aux.xml, and they are in the temp directory passed in by tempPath.
NOTHING I try will delete the .png.  The FileUtils.forceDelete() does remove the .png.aux.xml files, but not the .png, and hence, not the directory.  Any deleteOnExit() does not remove anything.  I think I've tried every way there is to delete a file in Java.

Is it possible the Translate() method is not closing a Stream somewhere?


V
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Gdal Java - Translate creates indestructible file

Even Rouault-2

> Is it possible the Translate() method is not closing a Stream somewhere?

 

Absolutely, it returns a valid Dataset object, and thus (on Windows, you are on Windows I guess), you need to close it with .delete() explicitly to release the file handle it owns.

 

Even

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Gdal Java - Translate creates indestructible file

Vlad
My bad, was trying to save a variable declaration.

Thanks.
Loading...