|
From: Viatcheslav S. <Via...@h-...> - 2025-12-11 16:16:34
|
Hi,
after reader.dispose() the file is still locked in actual version (34.1):
File file = new File("C:\\Projects\\tmp\\tmp2\\qwf_T.tif");
GeoTiffReader reader = new GeoTiffReader(file);
GridCoverage2D grid = reader.read(null);
grid.dispose(true);
reader.dispose();
... file still locked...
Regards, Slava
________________________________
Von: Roar Brænden <roa...@gm...>
Gesendet: Donnerstag, 11. Dezember 2025 16:49
An: Viatcheslav Sysoltsev <Via...@h-...>
Cc: Ian Turton <ijt...@gm...>; geo...@li... <geo...@li...>
Betreff: Re: [Geotools-gt2-users] GeoTiffReader locks the file indefinitely?
Sie erhalten nicht häufig E-Mails von roa...@gm.... Erfahren Sie, warum dies wichtig ist<https://aka.ms/LearnAboutSenderIdentification>
Hi,
The GeoTiffReader will handle the resource management of the file. You can have several calls for read with params referring to different parts of the file. You wouldn't clutter that with calls for opening / closing the file. The code should look more like:
GeoTiffReader reader = new GeoTiffReader(file);
try {
reader.read(null);
} finally {
reader.dispose();
}
// Here you could check if the file is closed
Regards,
Roar Brænden
11. des. 2025 kl. 12:49 skrev Viatcheslav Sysoltsev <Via...@h-...<mailto:Via...@h-...>>:
Hi Ian,
Been debugging, the stream (of type it.geosolutions.imageio.stream.eraf.EnhancedRandomAccessFile) remains not closed after call at org.geotools.gce.geotiff.GeoTiffReader#read():737
> pbjRead.add(maskOvrProvider.getSourceSpiProvider().getStream());
... where it is passed to JaI/ImageN
With best regards, Slava
________________________________
Von: Ian Turton <ijt...@gm...<mailto:ijt...@gm...>>
Gesendet: Donnerstag, 11. Dezember 2025 12:16
An: Viatcheslav Sysoltsev <Via...@h-...<mailto:Via...@h-...>>
Cc: geo...@li...<mailto:geo...@li...> <geo...@li...<mailto:geo...@li...>>
Betreff: Re: [Geotools-gt2-users] GeoTiffReader locks the file indefinitely?
Sie erhalten nicht häufig E-Mails von ijt...@gm...<mailto:ijt...@gm...>. Erfahren Sie, warum dies wichtig ist<https://aka.ms/LearnAboutSenderIdentification>
I think that's the expected behaviour on a windows machine for any file opened in a program. The code clearly closes the input stream created from the file that is passed in so I don't think there is any reason GeoTools would be locking the file.
Ian
On Wed, 10 Dec 2025 at 17:31, Viatcheslav Sysoltsev <Via...@h-...<mailto:Via...@h-...>> wrote:
Hi everyone,
I'd like to ask if it is an intended behavior, that GeoTiffReader locks the file indefinitely? If yes, is there a way to read the file completely and "dispose" the reader and the lock?
A simple program to demonstrate:
import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.gce.geotiff.GeoTiffReader;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.time.Duration;
class GeotiffReaderTest {
@Test
public void read() throws Exception {
File file = new File("C:\\Projects\\tmp\\tmp2\\qwf 2_TH.tif");
GeoTiffReader reader = new GeoTiffReader(file);
GridCoverage2D grid = reader.read(null);
Thread.sleep(Duration.ofSeconds(60));
}
}
when run, it reads the file and sleeps for a minute. Until JVM exits, the tif file cannot be moved or deleted:
C:\Projects\tmp\tmp2>mv "qwf 2_TH.tif" "qwf 2_TH.tif2"
/usr/bin/mv: cannot move 'qwf 2_TH.tif' to 'qwf 2_TH.tif2': Device or resource busy
// the problem is reproducible with geotools 34.1 and 33.0
With best regards,
Viatcheslav Sysoltsev / Slava
_______________________________________________
GeoTools-GT2-Users mailing list
Geo...@li...<mailto:Geo...@li...>
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
--
Ian Turton
_______________________________________________
GeoTools-GT2-Users mailing list
Geo...@li...<mailto:Geo...@li...>
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
|