Revision 46655 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.ByteArrayOutputStream; |
|
4 | 5 |
import java.io.File; |
5 | 6 |
import java.io.FileOutputStream; |
6 | 7 |
import java.io.InputStream; |
7 | 8 |
import java.io.OutputStream; |
9 |
import java.nio.charset.StandardCharsets; |
|
8 | 10 |
import java.util.ArrayList; |
9 | 11 |
import java.util.List; |
10 | 12 |
import java.util.Objects; |
13 |
import org.apache.commons.codec.binary.Hex; |
|
11 | 14 |
import org.apache.commons.collections4.CollectionUtils; |
15 |
import org.apache.commons.io.FileUtils; |
|
12 | 16 |
import org.apache.commons.io.IOUtils; |
13 | 17 |
import org.apache.commons.lang3.StringUtils; |
14 | 18 |
import org.gvsig.fmap.dal.exception.DataException; |
... | ... | |
84 | 88 |
} |
85 | 89 |
|
86 | 90 |
public void write(File outfile) { |
87 |
OutputStream out = null; |
|
88 |
try { |
|
89 |
out = new FileOutputStream(outfile); |
|
90 |
this.write(out); |
|
91 |
} catch(Throwable ex) { |
|
92 |
throw new RuntimeException("Can't write DAL file.",ex); |
|
93 |
} finally { |
|
94 |
IOUtils.closeQuietly(out); |
|
91 |
this.write(outfile, "bin"); |
|
92 |
} |
|
93 |
|
|
94 |
public void write(File outfile, String format) { |
|
95 |
switch(StringUtils.upperCase(format) ) { |
|
96 |
case "HEX": |
|
97 |
ByteArrayOutputStream buffer = new ByteArrayOutputStream(); |
|
98 |
try { |
|
99 |
this.write(buffer); |
|
100 |
FileUtils.write( |
|
101 |
outfile, |
|
102 |
Hex.encodeHexString(buffer.toByteArray()), |
|
103 |
StandardCharsets.UTF_8 |
|
104 |
); |
|
105 |
} catch(Throwable ex) { |
|
106 |
throw new RuntimeException("Can't write DAL file.",ex); |
|
107 |
} finally { |
|
108 |
IOUtils.closeQuietly(buffer); |
|
109 |
} |
|
110 |
break; |
|
111 |
|
|
112 |
case "BIN": |
|
113 |
default: |
|
114 |
OutputStream out = null; |
|
115 |
try { |
|
116 |
out = new FileOutputStream(outfile); |
|
117 |
this.write(out); |
|
118 |
} catch(Throwable ex) { |
|
119 |
throw new RuntimeException("Can't write DAL file.",ex); |
|
120 |
} finally { |
|
121 |
IOUtils.closeQuietly(out); |
|
122 |
} |
|
123 |
break; |
|
95 | 124 |
} |
96 | 125 |
} |
97 | 126 |
|
Also available in: Unified diff