Revision 44160 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DALFile.java
DALFile.java | ||
---|---|---|
1 | 1 |
|
2 | 2 |
package org.gvsig.fmap.dal.feature.impl; |
3 | 3 |
|
4 |
import java.io.File; |
|
5 |
import java.io.FileInputStream; |
|
6 |
import java.io.FileOutputStream; |
|
4 |
import java.io.InputStream; |
|
5 |
import java.io.OutputStream; |
|
7 | 6 |
import java.util.ArrayList; |
8 | 7 |
import java.util.HashSet; |
9 | 8 |
import java.util.Iterator; |
... | ... | |
12 | 11 |
import org.apache.commons.collections4.CollectionUtils; |
13 | 12 |
import org.apache.commons.io.IOUtils; |
14 | 13 |
import org.apache.commons.lang3.StringUtils; |
14 |
import org.gvsig.fmap.dal.DataServerExplorer.DataResource; |
|
15 | 15 |
import org.gvsig.fmap.dal.exception.DataException; |
16 | 16 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
17 | 17 |
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
... | ... | |
38 | 38 |
return f; |
39 | 39 |
} |
40 | 40 |
|
41 |
public static DALFile getDALFile(File f) {
|
|
41 |
public static DALFile getDALFile(DataResource resource) {
|
|
42 | 42 |
DALFile df = new DALFile(); |
43 |
df.read(f);
|
|
43 |
df.read(resource);
|
|
44 | 44 |
return df; |
45 | 45 |
} |
46 | 46 |
|
... | ... | |
187 | 187 |
return false; |
188 | 188 |
} |
189 | 189 |
|
190 |
public void write(File f) { |
|
191 |
FileOutputStream out = null; |
|
190 |
public void write(DataResource resource) { |
|
192 | 191 |
try { |
193 | 192 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
194 | 193 |
PersistentState state = manager.getState(this); |
195 |
out = new FileOutputStream(f);
|
|
194 |
OutputStream out = resource.asOutputStream();
|
|
196 | 195 |
manager.saveState(state, out); |
197 | 196 |
} catch(Exception ex) { |
198 |
throw new RuntimeException("Can't write DAL file.",ex);
|
|
197 |
throw new RuntimeException("Can't write DAL resource.",ex);
|
|
199 | 198 |
} finally { |
200 |
IOUtils.closeQuietly(out);
|
|
199 |
IOUtils.closeQuietly(resource);
|
|
201 | 200 |
} |
202 | 201 |
} |
203 | 202 |
|
204 |
public void read(File f) { |
|
205 |
FileInputStream in = null; |
|
203 |
public void read(DataResource resource) { |
|
206 | 204 |
try { |
207 | 205 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
208 |
in = new FileInputStream(f);
|
|
206 |
InputStream in = resource.asInputStream();
|
|
209 | 207 |
DALFile x = (DALFile) manager.getObject(in); |
210 | 208 |
this.attributes.clear(); |
211 | 209 |
this.attributes.addAll(x.attributes); |
212 | 210 |
} catch(Exception ex) { |
213 | 211 |
throw new RuntimeException("Can't read DAL file.",ex); |
214 | 212 |
} finally { |
215 |
IOUtils.closeQuietly(in);
|
|
213 |
IOUtils.closeQuietly(resource);
|
|
216 | 214 |
} |
217 | 215 |
} |
218 | 216 |
|
Also available in: Unified diff