Last active
March 5, 2019 09:12
-
-
Save akultomar17/af7e35e960110d098bd703db99fef211 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void recurseOnFolder(File file) { | |
if (file.isFile() && file.getName().endsWith(".java")) { | |
if (!file.equals(new File("/Users/akultomar/Workspace/A_Shop101/O1Server/O1Server-model/src/main/java/com/localization/ErrorCodeConstants.java"))) { | |
replaceErrorCodes(file); | |
} | |
} else if (file.isDirectory()) { | |
File[] file1 = file.listFiles(); | |
for(File file2: file1) { | |
recurseOnFolder(file2); | |
} | |
} | |
} | |
private static void replaceErrorCodes(File file) { | |
boolean writeFile = false; | |
try(BufferedReader reader = new BufferedReader(new FileReader(file))) { | |
StringBuffer stringBuffer = new StringBuffer(); | |
String line; | |
while((line = reader.readLine()) != null) { | |
try { | |
Pattern p = Pattern.compile("\"ECODE-(.*?)\""); | |
Matcher m = p.matcher(line); | |
if (m.find()) { | |
line = line.replaceAll("\"ECODE-(.*?)\"", "ErrorCodeConstants.ECODE_"+m.group(1)); | |
writeFile = true; | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
stringBuffer.append(line).append("\n"); | |
} | |
stringBuffer = stringBuffer.delete(stringBuffer.length()-1, stringBuffer.length()); | |
if (writeFile) { | |
FileWriter fileWriter = new FileWriter(file); | |
fileWriter.write(new String(stringBuffer)); | |
fileWriter.close(); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment