@Test public void testGetDateStringFromFileNameWhenInvalidFileName() { String absoluteFileName = "/var/log/zxtm/rotated/new-access_log.aggregated"; boolean expectedException = false; try { StaticFileUtils.getDateStringFromFileName(absoluteFileName); } catch (IllegalArgumentException e) { expectedException = true; } Assert.assertEquals(true, expectedException); }
public static String getDateStringFromFileName(String fileName) { int start = fileName.lastIndexOf("/"); fileName = fileName.substring(start + 1, fileName.length()); String arr[] = fileName.split("-"); String dateString = arr[0]; if (!dateString.matches("\\d{10}")) { throw new IllegalArgumentException("File names must be in the following format: 'yyyyMMddHH-access_log.aggregated' eg. 2011021513-access_log.aggregated"); } return dateString; }
StaticFileUtils { public static String getDateStringFromFileName(String fileName) { int start = fileName.lastIndexOf("/"); fileName = fileName.substring(start + 1, fileName.length()); String arr[] = fileName.split("-"); String dateString = arr[0]; if (!dateString.matches("\\d{10}")) { throw new IllegalArgumentException("File names must be in the following format: 'yyyyMMddHH-access_log.aggregated' eg. 2011021513-access_log.aggregated"); } return dateString; } }
StaticFileUtils { public static String getDateStringFromFileName(String fileName) { int start = fileName.lastIndexOf("/"); fileName = fileName.substring(start + 1, fileName.length()); String arr[] = fileName.split("-"); String dateString = arr[0]; if (!dateString.matches("\\d{10}")) { throw new IllegalArgumentException("File names must be in the following format: 'yyyyMMddHH-access_log.aggregated' eg. 2011021513-access_log.aggregated"); } return dateString; }  }
StaticFileUtils { public static String getDateStringFromFileName(String fileName) { int start = fileName.lastIndexOf("/"); fileName = fileName.substring(start + 1, fileName.length()); String arr[] = fileName.split("-"); String dateString = arr[0]; if (!dateString.matches("\\d{10}")) { throw new IllegalArgumentException("File names must be in the following format: 'yyyyMMddHH-access_log.aggregated' eg. 2011021513-access_log.aggregated"); } return dateString; }  static synchronized String generateRandomBase(); static String expandUser(String pathIn); static DataOutputStream openDataOutputStreamFile(String fileName); static DataInputStream openDataInputStreamFile(String fileName); static DataOutputStream openDataOutputStreamFile(String fileName, int buffsize); static DataInputStream openDataInputStreamFile(String fileName, int buffsize); static byte[] readFile(File file); static byte[] readFile(String fileName); static void copyStreams(InputStream is, OutputStream os, PrintStream ps, long isSize, int buffsize); static void copyStreams(InputStream is, OutputStream os, PrintStream ps, int buffsize); static OutputStream openOutputFile(String fileName); static OutputStream openOutputFile(String fileName, int buffsize); static InputStream openInputFile(String fileName); static InputStream openInputFile(String fileName, int buffsize); static String getWorkingDirectory(); static List<String> joinPath(List<String> paths); static List<String> splitPathList(String pathName); static String[] splitPath(String pathName); static String joinPath(String firstPart, String secondPart); static String[] joinPath(String[] firstPart, String[] secondPart); static String splitPathToString(List<String> pathComps); static String splitPathToString(String[] splitPath); static String rebaseSplitPath(String srcBase, String srcPath, String dstBase); static String[] rebaseSplitPath(String[] srcBase, String[] srcPath, String[] dstBase); static String[] stripBeginingPath(String[] splitPath, int nTimes); static String directoryNameFromFullPath(String fullFilePath); static String stripDirectoryFromFileName(String fullFilePath); static String pathTail(String path); static String[] stripEndPath(String[] splitPath, int nTimes); static List<String> listDir(String filePath); static byte[] readInputStream(InputStream fis, int buffSize); static byte[] readInputStream(InputStream fis); static long computeCrc(InputStream fis); static void mkParentDir(String filePath); static Properties loadProperties(String propertiesPath); static String sanitizeDir(String dir); static Map<String, List> getLocalCachedFiles(String cacheLocation); static String getLogFileTime(String absoluteFileName); static void deleteLocalFile(String fileName); static void deleteFilesOlderThanNDays(String location, int nDays); static void delete(String location, long purgeTime); static Date getDateFromFileName(String fileName); static String getDateStringFromFileName(String fileName); static String getNewestFile(List<String> fileNames); static String getTotalTimeTaken(String dateStart); static Date getDate(String dateString, DateFormat format); static String getMonthYearFromFileDate(String dateString); static BufferedReader inputStreamToBufferedReader(InputStream is); static Random getRnd(); static boolean isSymLink(String filePath); static void close(Closeable stream); static BufferedReader inputStreamToBufferedReader(InputStream is, int buffSize); static String mergePathString(String... pathArray); static RandomAccessFile openRandomReadFile(String filePath); static long fileSize(String filePath); static void drainInputStream(InputStream is); }
StaticFileUtils { public static String getDateStringFromFileName(String fileName) { int start = fileName.lastIndexOf("/"); fileName = fileName.substring(start + 1, fileName.length()); String arr[] = fileName.split("-"); String dateString = arr[0]; if (!dateString.matches("\\d{10}")) { throw new IllegalArgumentException("File names must be in the following format: 'yyyyMMddHH-access_log.aggregated' eg. 2011021513-access_log.aggregated"); } return dateString; }  static synchronized String generateRandomBase(); static String expandUser(String pathIn); static DataOutputStream openDataOutputStreamFile(String fileName); static DataInputStream openDataInputStreamFile(String fileName); static DataOutputStream openDataOutputStreamFile(String fileName, int buffsize); static DataInputStream openDataInputStreamFile(String fileName, int buffsize); static byte[] readFile(File file); static byte[] readFile(String fileName); static void copyStreams(InputStream is, OutputStream os, PrintStream ps, long isSize, int buffsize); static void copyStreams(InputStream is, OutputStream os, PrintStream ps, int buffsize); static OutputStream openOutputFile(String fileName); static OutputStream openOutputFile(String fileName, int buffsize); static InputStream openInputFile(String fileName); static InputStream openInputFile(String fileName, int buffsize); static String getWorkingDirectory(); static List<String> joinPath(List<String> paths); static List<String> splitPathList(String pathName); static String[] splitPath(String pathName); static String joinPath(String firstPart, String secondPart); static String[] joinPath(String[] firstPart, String[] secondPart); static String splitPathToString(List<String> pathComps); static String splitPathToString(String[] splitPath); static String rebaseSplitPath(String srcBase, String srcPath, String dstBase); static String[] rebaseSplitPath(String[] srcBase, String[] srcPath, String[] dstBase); static String[] stripBeginingPath(String[] splitPath, int nTimes); static String directoryNameFromFullPath(String fullFilePath); static String stripDirectoryFromFileName(String fullFilePath); static String pathTail(String path); static String[] stripEndPath(String[] splitPath, int nTimes); static List<String> listDir(String filePath); static byte[] readInputStream(InputStream fis, int buffSize); static byte[] readInputStream(InputStream fis); static long computeCrc(InputStream fis); static void mkParentDir(String filePath); static Properties loadProperties(String propertiesPath); static String sanitizeDir(String dir); static Map<String, List> getLocalCachedFiles(String cacheLocation); static String getLogFileTime(String absoluteFileName); static void deleteLocalFile(String fileName); static void deleteFilesOlderThanNDays(String location, int nDays); static void delete(String location, long purgeTime); static Date getDateFromFileName(String fileName); static String getDateStringFromFileName(String fileName); static String getNewestFile(List<String> fileNames); static String getTotalTimeTaken(String dateStart); static Date getDate(String dateString, DateFormat format); static String getMonthYearFromFileDate(String dateString); static BufferedReader inputStreamToBufferedReader(InputStream is); static Random getRnd(); static boolean isSymLink(String filePath); static void close(Closeable stream); static BufferedReader inputStreamToBufferedReader(InputStream is, int buffSize); static String mergePathString(String... pathArray); static RandomAccessFile openRandomReadFile(String filePath); static long fileSize(String filePath); static void drainInputStream(InputStream is); static DateFormat filedf; static DateFormat jobdf; }