001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.data.shapefile.indexed;
017:
018: import junit.framework.TestCase;
019: import org.geotools.TestData;
020: import java.io.File;
021: import java.io.FileOutputStream;
022: import java.io.IOException;
023: import java.io.InputStream;
024: import java.io.OutputStream;
025: import java.net.URL;
026:
027: public abstract class FIDTestCase extends TestCase {
028: protected final String TYPE_NAME = "archsites";
029:
030: protected File backshp;
031: protected File backdbf;
032: protected File backshx;
033: protected File backprj;
034: protected File backqix;
035: String filename;
036: protected File fixFile;
037:
038: protected void setUp() throws Exception {
039: backshp = File.createTempFile("FIDTests", ".shp");
040:
041: String name = backshp.getAbsolutePath();
042: filename = name.substring(0, name.lastIndexOf('.'));
043: backdbf = new File(filename + ".dbf");
044: backshx = new File(filename + ".shx");
045: backprj = new File(filename + ".prj");
046: backqix = new File(filename + ".qix");
047:
048: backdbf.deleteOnExit();
049: backshx.deleteOnExit();
050: backprj.deleteOnExit();
051: backshp.deleteOnExit();
052: backqix.deleteOnExit();
053: fixFile = new File(filename + ".fix");
054: fixFile.deleteOnExit();
055:
056: copyFiles();
057: }
058:
059: protected void tearDown() throws Exception {
060: if (backdbf.exists()) {
061: backdbf.delete();
062: }
063:
064: if (backprj.exists()) {
065: backprj.delete();
066: }
067:
068: if (backshp.exists()) {
069: backshp.delete();
070: }
071:
072: if (backshx.exists()) {
073: backshx.delete();
074: }
075:
076: if (backqix.exists()) {
077: backqix.delete();
078: }
079:
080: if (fixFile.exists()) {
081: fixFile.delete();
082: }
083: }
084:
085: private void copyFiles() throws Exception {
086: if (backshp.exists()) {
087: backshp.delete();
088: }
089:
090: if (backshp.exists()) {
091: backshp.delete();
092: }
093:
094: if (backshp.exists()) {
095: backshp.delete();
096: }
097:
098: if (backprj.exists()) {
099: backprj.delete();
100: }
101:
102: if (backqix.exists()) {
103: backqix.delete();
104: }
105:
106: copy(TestData.url("shapes/" + TYPE_NAME + ".shp"), backshp);
107: copy(TestData.url("shapes/" + TYPE_NAME + ".dbf"), backdbf);
108: copy(TestData.url("shapes/" + TYPE_NAME + ".shx"), backshx);
109: copy(TestData.url("shapes/" + TYPE_NAME + ".prj"), backprj);
110: }
111:
112: void copy(URL src, File dst) throws IOException {
113: InputStream in = null;
114: OutputStream out = null;
115:
116: try {
117: in = src.openStream();
118: out = new FileOutputStream(dst);
119:
120: // Transfer bytes from in to out
121: byte[] buf = new byte[1024];
122: int len;
123:
124: while ((len = in.read(buf)) > 0) {
125: out.write(buf, 0, len);
126: }
127: } finally {
128: if (in != null) {
129: in.close();
130: }
131:
132: if (out != null) {
133: out.close();
134: }
135: }
136: }
137: }
|