00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 package org.openmobileis.synchro.openmsp.server.util;
00030
00031 import java.io.*;
00032
00033 import org.openmobileis.common.util.file.FileUtilities;
00034
00042 public class MemoryFile implements OpenMISFile {
00043 static final long serialVersionUID = 5521257935120563452L;
00044 protected String fileName;
00045
00049 protected String filePath;
00050 protected byte[] fileData;
00051 protected long filedate;
00052
00053
00054 public MemoryFile() {
00055 }
00056
00062 protected MemoryFile(InputStream data) throws IOException {
00063 filedate = System.currentTimeMillis();
00064
00065 byte[] buffer = new byte[512];
00066 ByteArrayOutputStream stream = new ByteArrayOutputStream(buffer.length);
00067 int bytes_read;
00068 try {
00069 while(( bytes_read = data.read(buffer)) != -1)
00070 stream.write(buffer, 0, bytes_read);
00071 } finally {
00072 stream.flush();
00073 stream.close();
00074 data.close();
00075 }
00076 fileData = stream.toByteArray();
00077 }
00078
00085 public MemoryFile(String completeName, InputStream data) throws IOException {
00086 this(data);
00087 completeName = FileUtilities.convertFileNameToSystem(completeName);
00088 fileName = FileUtilities.getNameFromCompleteFileName(completeName);
00089 filePath = FileUtilities.getPathFromCompleteFileName(completeName);
00090 }
00091
00092 public MemoryFile(String completeName, byte[] data) throws IOException {
00093 fileData = data;
00094 completeName = FileUtilities.convertFileNameToSystem(completeName);
00095 fileName = FileUtilities.getNameFromCompleteFileName(completeName);
00096 filePath = FileUtilities.getPathFromCompleteFileName(completeName);
00097 }
00098
00099 public MemoryFile(String name, String path, InputStream data) throws IOException {
00100 this(data);
00101 fileName = name;
00102 filePath = path;
00103 }
00104
00105
00109 public String getFileName() {
00110 return fileName;
00111 }
00112
00116 public java.io.InputStream getFileDataStream() throws IOException {
00117 return new ByteArrayInputStream(fileData);
00118 }
00119
00123 public String getFilePath() {
00124 return filePath;
00125 }
00126
00127 public long getFileDate() {
00128 return filedate;
00129 }
00130
00131 public void setFileDate(java.util.Date date) {
00132 filedate = date.getTime();
00133 }
00134
00138 public String getFileCompleteName() {
00139 return filePath+fileName;
00140 }
00141
00142
00146 public long getFileLength() {
00147 return fileData.length;
00148 }
00149
00153 public byte[] getFileData() throws IOException {
00154 return fileData;
00155 }
00156
00157 public int hashCode() {
00158 return getFileCompleteName().hashCode();
00159 }
00160
00161 public boolean equals(Object obj) {
00162 if (obj instanceof MemoryFile) {
00163 return ((MemoryFile)obj).getFileCompleteName().equals(this.getFileCompleteName());
00164 }
00165 return false;
00166 }
00167
00168
00169
00170 }