Search in sources :

Example 6 with StorageFile

use of org.geotoolkit.data.shapefile.lock.StorageFile in project geotoolkit by Geomatys.

the class StorageFileTest method testReplaceOriginal.

@Test
public void testReplaceOriginal() throws Exception {
    final ShpFiles files1 = shpFiles1;
    final AccessManager locker = files1.createLocker();
    final ShpFileType type = PRJ;
    StorageFile storagePRJ1 = locker.getStorageFile(type);
    String writtenToStorageFile = "Copy";
    writeData(storagePRJ1, writtenToStorageFile);
    locker.disposeReaderAndWriters();
    locker.replaceStorageFiles();
    assertCorrectData(files1, type, writtenToStorageFile);
}
Also used : AccessManager(org.geotoolkit.data.shapefile.lock.AccessManager) ShpFiles(org.geotoolkit.data.shapefile.lock.ShpFiles) StorageFile(org.geotoolkit.data.shapefile.lock.StorageFile) ShpFileType(org.geotoolkit.data.shapefile.lock.ShpFileType) Test(org.junit.Test)

Example 7 with StorageFile

use of org.geotoolkit.data.shapefile.lock.StorageFile in project geotoolkit by Geomatys.

the class IndexedFidWriter method generate.

/**
 * Generates the FID index file for the shpFiles
 */
public static void generate(final ShpFiles shpFiles) throws IOException {
    LOGGER.log(Level.FINE, "Generating fids for {0}", shpFiles.get(SHP));
    final AccessManager locker = shpFiles.createLocker();
    ShxReader indexFile = null;
    StorageFile file = locker.getStorageFile(FIX);
    try {
        indexFile = locker.getSHXReader(false);
        // writer closes channel for you.
        final IndexedFidWriter writer = locker.getFIXWriter(file);
        for (int i = 0, j = indexFile.getRecordCount(); i < j; i++) {
            writer.next();
        }
    } finally {
        try {
            locker.disposeReaderAndWriters();
            locker.replaceStorageFiles();
        } finally {
            if (indexFile != null) {
                indexFile.close();
            }
        }
    }
}
Also used : AccessManager(org.geotoolkit.data.shapefile.lock.AccessManager) ShxReader(org.geotoolkit.data.shapefile.shx.ShxReader) StorageFile(org.geotoolkit.data.shapefile.lock.StorageFile)

Aggregations

StorageFile (org.geotoolkit.data.shapefile.lock.StorageFile)7 AccessManager (org.geotoolkit.data.shapefile.lock.AccessManager)6 Test (org.junit.Test)4 Closeable (java.io.Closeable)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 DataStoreException (org.apache.sis.storage.DataStoreException)2 MalformedURLException (java.net.MalformedURLException)1 FileChannel (java.nio.channels.FileChannel)1 WritableByteChannel (java.nio.channels.WritableByteChannel)1 AttributeTypeBuilder (org.apache.sis.feature.builder.AttributeTypeBuilder)1 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)1 WKTFormat (org.apache.sis.io.wkt.WKTFormat)1 UnsupportedQueryException (org.apache.sis.storage.UnsupportedQueryException)1 DbaseFileHeader (org.geotoolkit.data.dbf.DbaseFileHeader)1 ShpFileType (org.geotoolkit.data.shapefile.lock.ShpFileType)1 ShpFiles (org.geotoolkit.data.shapefile.lock.ShpFiles)1 ShapeType (org.geotoolkit.data.shapefile.shp.ShapeType)1 ShapefileReader (org.geotoolkit.data.shapefile.shp.ShapefileReader)1 ShapefileWriter (org.geotoolkit.data.shapefile.shp.ShapefileWriter)1