-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GEOT-4279] NADCON grid shift factory does not release channels on gr…
…id files
- Loading branch information
Showing
4 changed files
with
179 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...rc/test/java/org/geotools/referencing/operation/transform/NADCONGridShiftFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.geotools.referencing.operation.transform; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
|
||
import org.geotools.referencing.factory.gridshift.DataUtilities; | ||
import org.geotools.referencing.factory.gridshift.NADCONGridShiftFactory; | ||
import org.geotools.referencing.factory.gridshift.NADConGridShift; | ||
import org.junit.Test; | ||
import org.opengis.referencing.FactoryException; | ||
|
||
public class NADCONGridShiftFactoryTest { | ||
|
||
@Test | ||
public void testReleaseGrids() throws IOException, FactoryException { | ||
File gridShifts = new File("src/test/resources/org/geotools/referencing/factory/gridshift"); | ||
File las = new File(gridShifts, "stpaul.las"); | ||
File los = new File(gridShifts, "stpaul.los"); | ||
|
||
File tlas = new File("./target/stpaul.las"); | ||
File tlos = new File("./target/stpaul.los"); | ||
copyFile(las, tlas); | ||
copyFile(los, tlos); | ||
|
||
NADCONGridShiftFactory factory = new NADCONGridShiftFactory(); | ||
NADConGridShift shift = factory.loadGridShift(DataUtilities.fileToURL(tlas), DataUtilities.fileToURL(tlos)); | ||
// minor checks on the grid | ||
assertNotNull(shift); | ||
|
||
// now the good part, try to delete the files, on windows this will fail | ||
// unless the sources were properly closed | ||
assertTrue(tlas.delete()); | ||
assertTrue(tlos.delete()); | ||
} | ||
|
||
private void copyFile(File src, File dst) throws IOException { | ||
FileInputStream fis = null; | ||
FileOutputStream fos = null; | ||
try { | ||
fis = new FileInputStream(src); | ||
fos = new FileOutputStream(dst); | ||
byte[] buffer = new byte[4096]; | ||
int read = 0; | ||
while((read = fis.read(buffer)) > 0) { | ||
fos.write(buffer, 0, read); | ||
} | ||
} finally { | ||
if(fis != null) { | ||
fis.close(); | ||
} | ||
if(fos != null) { | ||
fos.close(); | ||
} | ||
} | ||
|
||
} | ||
} | ||
|