@Test public void ローテートされたADS書き込み失敗ログのファイル名書式が正しい場合に作成時刻が取得できること() throws AdsWriteFailureLogException { final String fileName = String.format("adsWriteFailure_%s.log.%d", PIO_VERSION_DUMMY, CREATED_TIME_DUMMY); File file = new File("./", fileName); try { if (!file.createNewFile()) { fail("Failed to create temporary file. " + file.getAbsolutePath()); } long createdTime = RollingAdsWriteFailureLog.getCreatedTimeFromFileName(PIO_VERSION_DUMMY, file); assertEquals(CREATED_TIME_DUMMY, createdTime); } catch (IOException e) { e.printStackTrace(); fail(e.getMessage()); } finally { if (null != file) { file.delete(); } } }
public static long getCreatedTimeFromFileName(String pcsVersion, File rotatedAdsWriteFailureLog) throws AdsWriteFailureLogException { final String messageFormat = "Illegal Rotated adsWriteFailureLog file name format. [%s]"; if (!rotatedAdsWriteFailureLog.isFile()) { String message = String.format("Rotated adsWriteFailureLog is not found. [%s]", rotatedAdsWriteFailureLog.getAbsolutePath()); throw new AdsWriteFailureLogException(message); } String fileName = rotatedAdsWriteFailureLog.getName(); String fileFormat = String.format(LOGNAME_FORMAT_ROTATE, pcsVersion, 0); String filePattern = fileFormat.substring(0, fileFormat.length() - 1); long createdTime = -1L; if (fileName.startsWith(filePattern)) { String createdTimeStr = fileName.replace(filePattern, ""); try { createdTime = Long.parseLong(createdTimeStr); } catch (NumberFormatException e) { String message = String.format(messageFormat, rotatedAdsWriteFailureLog.getAbsolutePath()); if (fileName.endsWith(LOGICAL_DELETED_LOGNAME_SUFFIX)) { message = String.format("Logical deleted adsWriteFailureLog file. [%s]", rotatedAdsWriteFailureLog.getAbsolutePath()); } throw new AdsWriteFailureLogException(message); } } else { String message = String.format(messageFormat, rotatedAdsWriteFailureLog.getAbsolutePath()); throw new AdsWriteFailureLogException(message); } return createdTime; }
RollingAdsWriteFailureLog extends AbstractAdsWriteFailureLog { public static long getCreatedTimeFromFileName(String pcsVersion, File rotatedAdsWriteFailureLog) throws AdsWriteFailureLogException { final String messageFormat = "Illegal Rotated adsWriteFailureLog file name format. [%s]"; if (!rotatedAdsWriteFailureLog.isFile()) { String message = String.format("Rotated adsWriteFailureLog is not found. [%s]", rotatedAdsWriteFailureLog.getAbsolutePath()); throw new AdsWriteFailureLogException(message); } String fileName = rotatedAdsWriteFailureLog.getName(); String fileFormat = String.format(LOGNAME_FORMAT_ROTATE, pcsVersion, 0); String filePattern = fileFormat.substring(0, fileFormat.length() - 1); long createdTime = -1L; if (fileName.startsWith(filePattern)) { String createdTimeStr = fileName.replace(filePattern, ""); try { createdTime = Long.parseLong(createdTimeStr); } catch (NumberFormatException e) { String message = String.format(messageFormat, rotatedAdsWriteFailureLog.getAbsolutePath()); if (fileName.endsWith(LOGICAL_DELETED_LOGNAME_SUFFIX)) { message = String.format("Logical deleted adsWriteFailureLog file. [%s]", rotatedAdsWriteFailureLog.getAbsolutePath()); } throw new AdsWriteFailureLogException(message); } } else { String message = String.format(messageFormat, rotatedAdsWriteFailureLog.getAbsolutePath()); throw new AdsWriteFailureLogException(message); } return createdTime; } }
RollingAdsWriteFailureLog extends AbstractAdsWriteFailureLog { public static long getCreatedTimeFromFileName(String pcsVersion, File rotatedAdsWriteFailureLog) throws AdsWriteFailureLogException { final String messageFormat = "Illegal Rotated adsWriteFailureLog file name format. [%s]"; if (!rotatedAdsWriteFailureLog.isFile()) { String message = String.format("Rotated adsWriteFailureLog is not found. [%s]", rotatedAdsWriteFailureLog.getAbsolutePath()); throw new AdsWriteFailureLogException(message); } String fileName = rotatedAdsWriteFailureLog.getName(); String fileFormat = String.format(LOGNAME_FORMAT_ROTATE, pcsVersion, 0); String filePattern = fileFormat.substring(0, fileFormat.length() - 1); long createdTime = -1L; if (fileName.startsWith(filePattern)) { String createdTimeStr = fileName.replace(filePattern, ""); try { createdTime = Long.parseLong(createdTimeStr); } catch (NumberFormatException e) { String message = String.format(messageFormat, rotatedAdsWriteFailureLog.getAbsolutePath()); if (fileName.endsWith(LOGICAL_DELETED_LOGNAME_SUFFIX)) { message = String.format("Logical deleted adsWriteFailureLog file. [%s]", rotatedAdsWriteFailureLog.getAbsolutePath()); } throw new AdsWriteFailureLogException(message); } } else { String message = String.format(messageFormat, rotatedAdsWriteFailureLog.getAbsolutePath()); throw new AdsWriteFailureLogException(message); } return createdTime; } private  RollingAdsWriteFailureLog();  RollingAdsWriteFailureLog(File rotatedAdsWriteFailureLog,
            String baseDir,
            String pcsVersion,
            boolean physicalDelete); }
RollingAdsWriteFailureLog extends AbstractAdsWriteFailureLog { public static long getCreatedTimeFromFileName(String pcsVersion, File rotatedAdsWriteFailureLog) throws AdsWriteFailureLogException { final String messageFormat = "Illegal Rotated adsWriteFailureLog file name format. [%s]"; if (!rotatedAdsWriteFailureLog.isFile()) { String message = String.format("Rotated adsWriteFailureLog is not found. [%s]", rotatedAdsWriteFailureLog.getAbsolutePath()); throw new AdsWriteFailureLogException(message); } String fileName = rotatedAdsWriteFailureLog.getName(); String fileFormat = String.format(LOGNAME_FORMAT_ROTATE, pcsVersion, 0); String filePattern = fileFormat.substring(0, fileFormat.length() - 1); long createdTime = -1L; if (fileName.startsWith(filePattern)) { String createdTimeStr = fileName.replace(filePattern, ""); try { createdTime = Long.parseLong(createdTimeStr); } catch (NumberFormatException e) { String message = String.format(messageFormat, rotatedAdsWriteFailureLog.getAbsolutePath()); if (fileName.endsWith(LOGICAL_DELETED_LOGNAME_SUFFIX)) { message = String.format("Logical deleted adsWriteFailureLog file. [%s]", rotatedAdsWriteFailureLog.getAbsolutePath()); } throw new AdsWriteFailureLogException(message); } } else { String message = String.format(messageFormat, rotatedAdsWriteFailureLog.getAbsolutePath()); throw new AdsWriteFailureLogException(message); } return createdTime; } private  RollingAdsWriteFailureLog();  RollingAdsWriteFailureLog(File rotatedAdsWriteFailureLog,
            String baseDir,
            String pcsVersion,
            boolean physicalDelete); static long getCreatedTimeFromFileName(String pcsVersion, File rotatedAdsWriteFailureLog); void openRotatedFile(); synchronized void closeRotatedFile(); List<String> readAdsFailureLog(int recordNum); synchronized void deleteRotatedLog(); }
RollingAdsWriteFailureLog extends AbstractAdsWriteFailureLog { public static long getCreatedTimeFromFileName(String pcsVersion, File rotatedAdsWriteFailureLog) throws AdsWriteFailureLogException { final String messageFormat = "Illegal Rotated adsWriteFailureLog file name format. [%s]"; if (!rotatedAdsWriteFailureLog.isFile()) { String message = String.format("Rotated adsWriteFailureLog is not found. [%s]", rotatedAdsWriteFailureLog.getAbsolutePath()); throw new AdsWriteFailureLogException(message); } String fileName = rotatedAdsWriteFailureLog.getName(); String fileFormat = String.format(LOGNAME_FORMAT_ROTATE, pcsVersion, 0); String filePattern = fileFormat.substring(0, fileFormat.length() - 1); long createdTime = -1L; if (fileName.startsWith(filePattern)) { String createdTimeStr = fileName.replace(filePattern, ""); try { createdTime = Long.parseLong(createdTimeStr); } catch (NumberFormatException e) { String message = String.format(messageFormat, rotatedAdsWriteFailureLog.getAbsolutePath()); if (fileName.endsWith(LOGICAL_DELETED_LOGNAME_SUFFIX)) { message = String.format("Logical deleted adsWriteFailureLog file. [%s]", rotatedAdsWriteFailureLog.getAbsolutePath()); } throw new AdsWriteFailureLogException(message); } } else { String message = String.format(messageFormat, rotatedAdsWriteFailureLog.getAbsolutePath()); throw new AdsWriteFailureLogException(message); } return createdTime; } private  RollingAdsWriteFailureLog();  RollingAdsWriteFailureLog(File rotatedAdsWriteFailureLog,
            String baseDir,
            String pcsVersion,
            boolean physicalDelete); static long getCreatedTimeFromFileName(String pcsVersion, File rotatedAdsWriteFailureLog); void openRotatedFile(); synchronized void closeRotatedFile(); List<String> readAdsFailureLog(int recordNum); synchronized void deleteRotatedLog();  }