Revision 1167 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/write/DBFFromSelected.java
DBFFromSelected.java | ||
---|---|---|
66 | 66 |
public class DBFFromSelected { |
67 | 67 |
private IGeometry[] fgs = null; |
68 | 68 |
private boolean hasdbf = false; |
69 |
private URL dbfURL = null;
|
|
69 |
private String dbfPath;
|
|
70 | 70 |
private int temp = 0; |
71 | 71 |
private DbaseFileWriterNIO dbfWrite; |
72 | 72 |
private Integer[] enteros; |
... | ... | |
81 | 81 |
* @param f Fichero. |
82 | 82 |
*/ |
83 | 83 |
public void setFile(File f) { |
84 |
try { |
|
85 |
String strFichDbf = f.getAbsolutePath().replaceAll("\\.shp", ".dbf"); |
|
86 |
strFichDbf = strFichDbf.replaceAll("\\.SHP", ".DBF"); |
|
87 |
dbfURL = new URL("file://" + strFichDbf); |
|
88 |
} catch (MalformedURLException e) { |
|
89 |
e.printStackTrace(); |
|
90 |
} |
|
84 |
String strFichDbf = f.getAbsolutePath().replaceAll("\\.shp", ".dbf"); |
|
85 |
dbfPath = strFichDbf.replaceAll("\\.SHP", ".DBF"); |
|
86 |
|
|
91 | 87 |
} |
92 | 88 |
|
93 | 89 |
/** |
... | ... | |
122 | 118 |
DbaseFileHeaderNIO myHeader = DbaseFileHeaderNIO.createNewDbaseHeader(); |
123 | 119 |
myHeader.setNumRecords(fgs.length); |
124 | 120 |
dbfWrite = new DbaseFileWriterNIO(myHeader, |
125 |
(FileChannel) getWriteChannel(getStorageURL(dbfURL)));
|
|
121 |
(FileChannel) getWriteChannel(dbfPath));
|
|
126 | 122 |
enteros = new Integer[1]; |
127 | 123 |
} else { |
128 | 124 |
//VectorialFileAdapter vfa=(VectorialFileAdapter)((SingleLayer)lv).getSource(); |
... | ... | |
132 | 128 |
|
133 | 129 |
myHeader.setNumRecords(fgs.length); |
134 | 130 |
dbfWrite = new DbaseFileWriterNIO(myHeader, |
135 |
(FileChannel) getWriteChannel(getStorageURL(dbfURL)));
|
|
131 |
(FileChannel) getWriteChannel(dbfPath));
|
|
136 | 132 |
record = new Object[sds.getFieldCount()]; |
137 | 133 |
} |
138 | 134 |
} catch (IOException e) { |
... | ... | |
181 | 177 |
} |
182 | 178 |
|
183 | 179 |
|
184 |
protected URL getStorageURL(URL url) throws java.net.MalformedURLException { |
|
185 |
return (temp == 0) ? url : getStorageFile(url).toURL(); |
|
186 |
} |
|
187 | 180 |
|
188 |
protected File getStorageFile(URL url) { |
|
189 |
String f = url.getFile(); |
|
190 |
f = temp + f.substring(f.lastIndexOf("/") + 1); |
|
191 |
|
|
192 |
File tf = new File(System.getProperty("java.io.tmpdir"), f); |
|
193 |
|
|
194 |
return tf; |
|
195 |
} |
|
196 |
|
|
197 |
private WritableByteChannel getWriteChannel(URL url) |
|
181 |
private WritableByteChannel getWriteChannel(String path) |
|
198 | 182 |
throws IOException { |
199 | 183 |
WritableByteChannel channel; |
200 | 184 |
|
201 |
if (url.getProtocol().equals("file")) { |
|
202 |
File f = new File(url.getFile()); |
|
185 |
File f = new File(path); |
|
203 | 186 |
|
204 | 187 |
if (!f.exists() && !f.createNewFile()) { |
205 | 188 |
throw new IOException("Cannot create file " + f); |
... | ... | |
207 | 190 |
|
208 | 191 |
RandomAccessFile raf = new RandomAccessFile(f, "rw"); |
209 | 192 |
channel = raf.getChannel(); |
210 |
} else { |
|
211 |
OutputStream out = url.openConnection().getOutputStream(); |
|
212 |
channel = Channels.newChannel(out); |
|
213 |
} |
|
214 | 193 |
|
215 | 194 |
return channel; |
216 | 195 |
} |
Also available in: Unified diff