RLPark 1.0.0
Reinforcement Learning Framework in Java
|
00001 package zephyr.plugin.core.api.internal.monitoring.helpers; 00002 00003 import java.io.File; 00004 import java.io.FileInputStream; 00005 import java.io.FileOutputStream; 00006 import java.io.IOException; 00007 import java.lang.reflect.Field; 00008 import java.text.SimpleDateFormat; 00009 import java.util.Date; 00010 import zephyr.plugin.core.api.internal.monitoring.fileloggers.FileLogger; 00011 import zephyr.plugin.core.api.internal.monitoring.fileloggers.LoggerRow; 00012 import zephyr.plugin.core.api.internal.monitoring.fileloggers.TimedFileLogger; 00013 import zephyr.plugin.core.api.monitoring.annotations.Monitor; 00014 00015 public class Loggers { 00016 static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm"); 00017 00018 public static String fileNameTimeStamp() { 00019 synchronized (dateFormat) { 00020 return dateFormat.format(new Date()); 00021 } 00022 } 00023 00024 public static boolean isIndexIncluded(Field field) { 00025 return isIndexIncluded(field.getAnnotation(Monitor.class)); 00026 } 00027 00028 public static boolean isIndexIncluded(Class<?> objectClass) { 00029 return isIndexIncluded(objectClass.getAnnotation(Monitor.class)); 00030 } 00031 00032 private static boolean isIndexIncluded(Monitor dataLogged) { 00033 if (dataLogged == null) 00034 return true; 00035 return dataLogged.arrayDecoration(); 00036 } 00037 00038 static public TimedFileLogger newLoggerWithTime(String filepath) { 00039 return newLoggerWithTime(filepath, false); 00040 } 00041 00042 public static FileLogger newLogger(String filepath) { 00043 try { 00044 return new FileLogger(filepath); 00045 } catch (IOException e) { 00046 e.printStackTrace(); 00047 } 00048 return null; 00049 } 00050 00051 public static LoggerRow newLoggerRow(String filepath) { 00052 try { 00053 return new LoggerRow(filepath); 00054 } catch (IOException e) { 00055 e.printStackTrace(); 00056 } 00057 return null; 00058 } 00059 00060 public static TimedFileLogger newLoggerWithTime(String filepath, boolean compress) { 00061 try { 00062 return new TimedFileLogger(filepath, false); 00063 } catch (IOException e) { 00064 e.printStackTrace(); 00065 } 00066 return null; 00067 } 00068 00069 public static void copyFile(File sourceFile, File destFile) throws IOException { 00070 if (!destFile.exists() && !destFile.createNewFile()) 00071 throw new RuntimeException("Error creating the new file: " + destFile.getAbsolutePath()); 00072 FileInputStream source = null; 00073 FileOutputStream destination = null; 00074 try { 00075 source = new FileInputStream(sourceFile); 00076 destination = new FileOutputStream(destFile); 00077 destination.getChannel().transferFrom(source.getChannel(), 0, source.getChannel().size()); 00078 } finally { 00079 if (source != null) 00080 source.close(); 00081 if (destination != null) 00082 destination.close(); 00083 } 00084 } 00085 00086 public static void checkParentFolder(String filepath) { 00087 checkFolder(new File(filepath).getParentFile().getAbsolutePath()); 00088 } 00089 00090 public static void checkFolder(String folderPath) { 00091 File folder = new File(folderPath); 00092 if (!folder.canRead()) 00093 if (!folder.mkdirs()) 00094 throw new RuntimeException("Error creating the folder: " + folder.getAbsolutePath()); 00095 } 00096 }