Created by krishna on 15/10/17.
| 21 | */ |
| 22 | |
| 23 | public class Utils { |
| 24 | |
| 25 | public static Object getObject(File file, Class clazz) { |
| 26 | Object object; |
| 27 | try { |
| 28 | object = deserializeObject(file, clazz); |
| 29 | } catch (IOException | ClassNotFoundException e) { |
| 30 | object = deserializeJson(file, clazz); |
| 31 | } |
| 32 | return object; |
| 33 | } |
| 34 | |
| 35 | private static Object deserializeJson(File file, Class clazz) { |
| 36 | String jsonString = AndroidFileManager.readFileAsString(file); |
| 37 | Gson gson = new Gson(); |
| 38 | return gson.fromJson(jsonString, clazz); |
| 39 | } |
| 40 | |
| 41 | private static Object deserializeObject(File file, Class clazz) throws IOException, ClassNotFoundException { |
| 42 | ObjectInputStream in = new ObjectInputStream(new FileInputStream(file)); |
| 43 | Object object = in.readObject(); |
| 44 | in.close(); |
| 45 | return object; |
| 46 | } |
| 47 | |
| 48 | public static ThreadPoolExecutor getThreadPoolExecutor() { |
| 49 | int mCorePoolSize = 60; |
| 50 | int mMaximumPoolSize = 80; |
| 51 | int mKeepAliveTime = 30; |
| 52 | BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>(mMaximumPoolSize); |
| 53 | return new ThreadPoolExecutor(mCorePoolSize, mMaximumPoolSize, mKeepAliveTime, TimeUnit.SECONDS, workQueue); |
| 54 | } |
| 55 | |
| 56 | public static boolean isValidFileName(String fileName) { |
| 57 | Pattern pattern = Pattern.compile(".*\\..*"); |
| 58 | return pattern.matcher(fileName).matches(); |
| 59 | } |
| 60 | |
| 61 | public static long parseLastModifiedHeader(String lastModified) { |
| 62 | long time = 0; |
| 63 | if (!TextUtils.isEmpty(lastModified)) { |
| 64 | try { |
| 65 | SimpleDateFormat df = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z"); |
| 66 | time = df.parse(lastModified).getTime(); |
| 67 | } catch (ParseException e) { |
| 68 | e.printStackTrace(); |
| 69 | } |
| 70 | } |
| 71 | return time; |
| 72 | } |
| 73 | |
| 74 | public static String getLastModifiedTime(long timeStamp) { |
| 75 | String lastModifiedTime = null; |
| 76 | try { |
| 77 | if (timeStamp > 0) { |
| 78 | SimpleDateFormat df = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z"); |
| 79 | lastModifiedTime = df.format(timeStamp); |
| 80 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…