Skip to content

Instantly share code, notes, and snippets.

@degree
Created November 8, 2013 13:13
Show Gist options
  • Save degree/7370872 to your computer and use it in GitHub Desktop.
Save degree/7370872 to your computer and use it in GitHub Desktop.
import java.io.File;
/**
* User: Eugene Dubrovka Date: 11/8/13 Time: 1:48 PM
*/
public class JS {
private File hotfolder;
public JS(File dir) throws Exception {
init(dir);
}
private void init(File dir) throws Exception {
// check for all required folder or complain with exception
hotfolder = dir;
// test environment
// smth's wrong -- shut the light
// throw heavy thoughts outside
}
public void doGood() {
// 6 * 9 = 42
}
// for spring as a factory method, bean creation
public static JS factory(String path) throws Exception {
File dir = new File(path);
createFileStructure(dir);
return new JS(dir);
}
public static void createFileStructure(File dir) {
// all the code that creates all necessary folders
dir.mkdirs();
}
// usage samples
public static void main(String[] args) {
// somewhere in the context
JS js = null;
// kind of spring way
{
try {
js = JS.factory(args[0]); // get it from factory
} catch (Exception e) {
// ouch!
e.printStackTrace();
System.exit(42);
}
js.doGood();
}
// with boostrap
{
File dir = new File(args[0]);
JS.createFileStructure(dir); // bootstrap
try {
js = new JS(dir);
} catch (Exception e) {
// oh, no!
e.printStackTrace();
System.exit(42);
}
js.doGood();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment