Java Web Code specification:

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.