1 package spoon.support.builder; 2 3 import java.io.File ; 4 import java.io.FileNotFoundException ; 5 import java.io.IOException ; 6 7 import spoon.support.builder.support.CtFileFile; 8 import spoon.support.builder.support.CtFolderFile; 9 import spoon.support.builder.support.CtFolderZip; 10 11 public class FileFactory { 12 public static boolean isArchive(File f) { 13 return f.getName().endsWith(".jar") || f.getName().endsWith(".zip"); 14 } 15 16 public static boolean isFile(File f) { 17 return f.isFile() && !isArchive(f); 18 } 19 20 public static CtFile createFile(File f) throws FileNotFoundException { 21 if (!f.exists()) 22 throw new FileNotFoundException (f.toString()); 23 return new CtFileFile(f); 24 } 25 26 public static CtResource createResource(File f) 27 throws FileNotFoundException { 28 if (f.isFile()) 29 return createFile(f); 30 else 31 return createFolder(f); 32 } 33 34 public static CtFolder createFolder(File f) throws FileNotFoundException { 35 if (!f.exists()) 36 throw new FileNotFoundException (f.toString() + " not exist"); 37 try { 38 if (f.isDirectory()) 39 return new CtFolderFile(f); 40 if (isArchive(f)) 41 return new CtFolderZip(f); 42 } catch (IOException e) { 43 e.printStackTrace(); 44 } 45 46 return null; 47 } 48 49 } 50 | Popular Tags |