@Test(expected = AdsWriteFailureLogException.class) public void ローテートされたADS書き込み失敗ログのファイル名書式が正しくない場合にエラーとなること1() throws AdsWriteFailureLogException { final String fileName = String.format("adsWriteFailure_%s.log", PIO_VERSION_DUMMY); File file = new File("./", fileName); try { if (!file.createNewFile()) { fail("Failed to create temporary file. " + file.getAbsolutePath()); } RollingAdsWriteFailureLog.getCreatedTimeFromFileName(PIO_VERSION_DUMMY, file); } 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();  }