There is a comment before each class, and the comment format before the class is:
/**
* What is a class?
* @author Write the author of this class
*/
There are also comments before each method in the class:
/**
* What does the method do?
* @param the parameters passed in the method
* @return
*/
/**
* Directory service class
* @author X
*
*/
@Component ("Project.docm.catalog.CatalogService")
@SuppressWarnings ("All")
public class CatalogService {
@Autowired
Platparamitemservice Paramitemservice;
/**
* Get root directory
* @return
*/
Private String Getrootpath () {
Return Paramitemservice.getparam ("File_folder"). Getevalue ();
}
Private String Getindexpath () {
Return Paramitemservice.getparam ("Index_folder"). Getevalue ();
}
/**
* Query Directory
* @param path
* @return
*/
Public List getcatalogs (String path) throws exception{
File File = new file (path);
List result = new ArrayList ();
if (File.isdirectory ()) {
root directory
Map m = new HashMap ();
M.put ("id", Uuid.randomuuid (). toString ());
M.put ("Name", File.getname ());
M.put ("Len", File.list (). length);
M.put ("Path", Ziputils.gzip (File.getpath ()));
M.put ("Size", file.length ());
M.put ("Iconcls", "FA Fa-laptop");
M.put ("Date", New SimpleDateFormat ("Yyyy/mm/dd HH:mm:ss"). Format (new date (file.lastmodified ())));
M.put ("Children", Eachcatalog (file));
Result.add (m);
}else{
throw new Exception ("Not a Directory");
}
return result;
}
Public List getFiles (File catalog) {
List result = new ArrayList ();
if (Catalog.isdirectory () && catalog.exists ()) {
file[] files = catalog.listfiles ();
for (File file:files) {
if (File.isfile ()) {
Map m = new HashMap ();
M.put ("id", Uuid.randomuuid (). toString ());
M.put ("Name", File.getname ());
M.put ("Path", Ziputils.gzip (File.getpath ()));
M.put ("Size", file.length ());
M.put ("Iconcls", "FA Fa-laptop");
M.put ("Date", New SimpleDateFormat ("Yyyy/mm/dd HH:mm:ss"). Format (new date (file.lastmodified ())));
Result.add (m);
}
}
}
return result;
}
Public List Eachcatalog (File path) {
if (Path.isdirectory ()) {
file[] files = path.listfiles ();
List dirs = new ArrayList ();
for (File file:files) {
if (File.isdirectory ()) {
Map m = new HashMap ();
M.put ("id", Uuid.randomuuid (). toString ());
M.put ("Path", Ziputils.gzip (File.getpath ()));
M.put ("Name", File.getname ());
M.put ("Len", File.list (). length);
M.put ("Size", file.length ());
M.put ("Iconcls", "FA Fa-folder");
M.put ("Date", New SimpleDateFormat ("Yyyy/mm/dd HH:mm:ss"). Format (new date (file.lastmodified ())));
M.put ("Children", Eachcatalog (file));
Dirs.add (m);
}
}
return dirs;
}
return null;
}
New Catalog
@Transactional
Public Object savecatalogs (file file) {
if (!file.exists ()) {
if (File.mkdir ()) {
Map m = new HashMap ();
M.put ("id", Uuid.randomuuid (). toString ());
M.put ("Name", File.getname ());
M.put ("Len", File.list (). length);
M.put ("Path", Ziputils.gzip (File.getpath ()));
M.put ("Size", file.length ());
M.put ("Iconcls", "FA Fa-folder");
M.put ("Date", New SimpleDateFormat ("Yyyy/mm/dd HH:mm:ss"). Format (new date (file.lastmodified ())));
M.put ("Children", Eachcatalog (file));
return m;
}
}
return false;
}
Delete Directory
public boolean deletecatalogs (file file) {
if (file.exists () && file.isdirectory ()) {
if (File.delete ()) {
Delete Index
try {
Indexhelper.deleteindex (file, Getindexpath (), Getrootpath ());
} catch (IOException e) {
E.printstacktrace ();
}
return true;
}
}
return false;
}
/**
* Delete Files
* @param file
* @return
*/
public boolean deletefile (file file) {
if (file.exists ()) {
return File.delete ();
}
return false;
}
}
Java Web Code specification: