001    // License: GPL. For details, see LICENSE file.
002    package org.openstreetmap.josm.data.projection.datum;
003    
004    import static org.openstreetmap.josm.tools.I18n.tr;
005    
006    import java.io.InputStream;
007    
008    import org.openstreetmap.josm.Main;
009    import org.openstreetmap.josm.io.MirroredInputStream;
010    
011    /**
012     * Wrapper for NTV2GridShiftFile.
013     *
014     * Loads the shift file from disk, when it is first accessed.
015     */
016    public class NTV2GridShiftFileWrapper {
017    
018        public final static NTV2GridShiftFileWrapper BETA2007 = new NTV2GridShiftFileWrapper("resource://data/BETA2007.gsb");
019        public final static NTV2GridShiftFileWrapper ntf_rgf93 = new NTV2GridShiftFileWrapper("resource://data/ntf_r93_b.gsb");
020        
021    
022        private NTV2GridShiftFile instance = null;
023        private String gridFileName;
024    
025        public NTV2GridShiftFileWrapper(String filename) {
026            this.gridFileName = filename;
027        }
028    
029        public NTV2GridShiftFile getShiftFile() {
030            if (instance == null) {
031                try {
032                    InputStream is = new MirroredInputStream(gridFileName);
033                    if (is == null)
034                        throw new RuntimeException(tr("Error: failed to open input stream for resource ''/data/{0}''.", gridFileName));
035                    instance = new NTV2GridShiftFile();
036                    instance.loadGridShiftFile(is, false);
037                } catch (Exception e) {
038                    throw new RuntimeException(e);
039                }
040            }
041            return instance;
042        }
043    
044    }