-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathFilesUtils.java
More file actions
115 lines (94 loc) · 3.65 KB
/
FilesUtils.java
File metadata and controls
115 lines (94 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package fileutils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import play.Logger;
import org.json.JSONObject;
import org.json.XML;
import org.apache.commons.io.FileUtils;
public class FilesUtils {
public static String getMainFileTypeOfZipFile(File compressedFile, String filename, String containerType){
String mainFileType = "multi/files-zipped";
try {
if(filename.startsWith("CLOWDERZIPPED_"))
return "multi/files-zipped";
ZipFile zipFile = new ZipFile(compressedFile);
Enumeration zipEntries = zipFile.entries();
String allPTMsFlag = "notfound";
while (zipEntries.hasMoreElements()) {
ZipEntry currEntry = ((ZipEntry)zipEntries.nextElement());
if(!currEntry.isDirectory()){
String fileName = currEntry.getName();
if(fileName.toLowerCase().endsWith(".x3d")){
zipFile.close();
mainFileType = "model/x3d-zipped";
return mainFileType;
}
if(fileName.toLowerCase().endsWith(".obj")){
zipFile.close();
mainFileType = "model/obj-zipped";
return mainFileType;
}
if(fileName.toLowerCase().endsWith(".lp")){
zipFile.close();
mainFileType = "imageset/ptmimages-zipped";
return mainFileType;
}
if(fileName.toLowerCase().endsWith(".sfmdataset")){
zipFile.close();
mainFileType = "model/sfm-zipped";
return mainFileType;
}
if(fileName.toLowerCase().contains("__slides")){
zipFile.close();
mainFileType = "multi/video-presentation-zipped";
return mainFileType;
}
if(fileName.toLowerCase().endsWith(".ptm") && allPTMsFlag.equals("notfound")){
allPTMsFlag = "found";
}
else if(!fileName.toLowerCase().endsWith(".ptm")){
allPTMsFlag = "noptm";
}
}
}
zipFile.close();
if(allPTMsFlag.equals("found"))
return "multi/files-ptm-zipped";
} catch (Throwable e) {
Logger.error("Could not read zipfile", e);
return ("ERROR: " + e.getMessage());
}
return mainFileType;
}
public static String readXMLgetJSON(File xmlFile){
try{
FileInputStream fis = new FileInputStream(xmlFile);
byte[] data = new byte[(int)xmlFile.length()];
fis.read(data);
fis.close();
String theXML = new String(data, "UTF-8");
//Remove spaces from XML tags
// int currStart = theXML.indexOf("<");
// int currEnd = -1;
// String xmlNoSpaces = "";
// while(currStart != -1){
// xmlNoSpaces = xmlNoSpaces + theXML.substring(currEnd+1,currStart);
// currEnd = theXML.indexOf(">", currStart+1);
// xmlNoSpaces = xmlNoSpaces + theXML.substring(currStart,currEnd+1).replaceAll(" ", "_");
// currStart = theXML.indexOf("<", currEnd+1);
// }
// xmlNoSpaces = xmlNoSpaces + theXML.substring(currEnd+1);
// theXML = xmlNoSpaces;
Logger.debug("thexml: " + theXML);
JSONObject xmlJSONObj = XML.toJSONObject(theXML);
return xmlJSONObj.toString();
}catch (Exception e) {
// TODO Auto-generated catch block
return ("ERROR: " + e.getMessage());
}
}
}