package com.test.util;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class CheckYaml {
public void checkYaml(String fileName) {
BufferedReader read = null;
try {
read = new BufferedReader(new InputStreamReader(new FileInputStream("locator/" + fileName)));
String temp = read.readLine();
List<String> list = new ArrayList<String>();
while(temp != null){
if(!temp.startsWith(" ") && !temp.trim().startsWith("#")){
String key = temp.substring(0, temp.length()-1);
if(list.contains(key)){
System.out.println("duplicate key: "+key);
}else{
list.add(key);
}
}
temp = read.readLine();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
if(read != null){
read.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
CheckYaml cy = new CheckYaml();
cy.checkYaml("TestBaidu.yaml");
}
}