001: /**
002: * SalomeFile.java
003: *
004: * This file was auto-generated from WSDL
005: * by the Apache Axis 1.4 Nov 19, 2006 (02:31:34 GMT+00:00) WSDL2Java emitter.
006: */package org.objectweb.salome_tmf.api.data;
007:
008: import java.io.BufferedOutputStream;
009: import java.io.ByteArrayInputStream;
010: import java.io.File;
011: import java.io.FileInputStream;
012: import java.io.FileOutputStream;
013: import java.io.IOException;
014: import java.io.InputStream;
015: import java.util.Properties;
016:
017: import org.objectweb.salome_tmf.api.ApiConstants;
018:
019: public class SalomeFileWrapper implements java.io.Serializable {
020:
021: private byte[] content;
022: private long lastModified;
023: private int length;
024: private String name;
025: private String canonicalPath;
026: private String absolutePath;
027:
028: // Pour construire l'Url
029: private String protocol;
030: private String host;
031: private int port;
032: private String fileName;
033:
034: public SalomeFileWrapper() {
035: }
036:
037: public SalomeFileWrapper(File file) throws IOException {
038: if (file == null) {
039: return;
040: }
041: content = new byte[(int) file.length()];
042: length = (int) file.length();
043: lastModified = file.lastModified();
044: name = file.getName();
045: canonicalPath = file.getCanonicalPath().replace(
046: File.separatorChar, '/');
047: absolutePath = file.getAbsolutePath().replace(
048: File.separatorChar, '/');
049: protocol = file.toURL().getProtocol();
050: host = file.toURL().getHost();
051: port = file.toURL().getPort();
052: fileName = file.toURL().getFile();
053:
054: if (file.exists()) {
055: FileInputStream fis = new FileInputStream(file);
056: fis.read(content);
057: }
058: }
059:
060: public File toFile() {
061: return toFile(null);
062: /*
063: File f = null;
064: f = new File(absolutePath);
065: f.setLastModified(lastModified);
066:
067: try {
068: FileOutputStream fos = new FileOutputStream(f);
069: BufferedOutputStream bos = new BufferedOutputStream(fos);
070:
071: // Flux du fichier stocké dans la BdD
072: bos.write(content);
073:
074: // Fermeture des flux de données
075: bos.flush();
076: bos.close();
077: } catch (Exception e) {
078: // TODO Auto-generated catch block
079: e.printStackTrace();
080: }
081:
082: return f;
083: */
084: }
085:
086: public File toFile(String filePath) {
087:
088: String path = filePath;
089: File file = null;
090:
091: String tmpDir;
092: Properties sys = System.getProperties();
093: String fs = sys.getProperty("file.separator");
094:
095: if (path == null || path.equals("")) {
096: // Repertoire temporaire système
097: tmpDir = sys.getProperty("java.io.tmpdir");
098: tmpDir = tmpDir + fs + ApiConstants.PATH_TO_ADD_TO_TEMP
099: + fs;
100: } else {
101: tmpDir = path;
102: if (!path.endsWith(fs)) {
103: tmpDir = tmpDir + fs;
104: }
105:
106: }
107: try {
108: file = new File(tmpDir + getName());
109: File fPath = new File(file.getCanonicalPath().substring(0,
110: file.getCanonicalPath().lastIndexOf(fs) + 1));
111: if (!fPath.exists()) {
112: fPath.mkdirs();
113: }
114: file.createNewFile();
115:
116: // Flux d'écriture sur le fichier
117: FileOutputStream fos = new FileOutputStream(file);
118: BufferedOutputStream bos = new BufferedOutputStream(fos);
119:
120: // Flux du fichier stocké dans la BdD
121: bos.write(getContent());
122:
123: // Fermeture des flux de données
124: bos.flush();
125: bos.close();
126: } catch (Exception e) {
127: // TODO Auto-generated catch block
128: e.printStackTrace();
129: }
130: return file;
131: }
132:
133: /**
134: * Gets the content value for this SalomeFile.
135: *
136: * @return content
137: */
138: public byte[] getContent() {
139: return content;
140: }
141:
142: /**
143: * Gets the inputStream value for this SalomeFile.
144: *
145: * @return inputStream
146: */
147: public InputStream openInputStream() {
148: return new ByteArrayInputStream(content);
149: }
150:
151: /**
152: * Gets the lastModified value for this SalomeFile.
153: *
154: * @return lastModified
155: */
156: public long getLastModified() {
157: return lastModified;
158: }
159:
160: /**
161: * Gets the length value for this SalomeFile.
162: *
163: * @return length
164: */
165: public int getLength() {
166: return length;
167: }
168:
169: /**
170: * Gets the name value for this SalomeFile.
171: *
172: * @return name
173: */
174: public java.lang.String getName() {
175: return name;
176: }
177:
178: public boolean exists() {
179: return (content != null);
180: }
181:
182: public String getCanonicalPath() {
183: return canonicalPath;
184: }
185:
186: public String getAbsolutePath() {
187: return absolutePath;
188: }
189:
190: public String getFileName() {
191: return fileName;
192: }
193:
194: public String getHost() {
195: return host;
196: }
197:
198: public int getPort() {
199: return port;
200: }
201:
202: public String getProtocol() {
203: return protocol;
204: }
205:
206: public void setAbsolutePath(String absolutePath) {
207: this .absolutePath = absolutePath;
208: }
209:
210: public void setCanonicalPath(String canonicalPath) {
211: this .canonicalPath = canonicalPath;
212: }
213:
214: public void setContent(byte[] content) {
215: this .content = content;
216: }
217:
218: public void setFileName(String fileName) {
219: this .fileName = fileName;
220: }
221:
222: public void setHost(String host) {
223: this .host = host;
224: }
225:
226: public void setLastModified(long lastModified) {
227: this .lastModified = lastModified;
228: }
229:
230: public void setLength(int length) {
231: this .length = length;
232: }
233:
234: public void setName(String name) {
235: this .name = name;
236: }
237:
238: public void setPort(int port) {
239: this .port = port;
240: }
241:
242: public void setProtocol(String protocol) {
243: this.protocol = protocol;
244: }
245:
246: }
|