[ONOS-3906],[ONOS-3910] Implementation of YANG module and leaf/leaf-list translator.
Change-Id: If1a8a991ffafa14b51211f97c435176ee1bf856f
diff --git a/src/main/java/org/onosproject/yangutils/utils/io/impl/CopyrightHeader.java b/src/main/java/org/onosproject/yangutils/utils/io/impl/CopyrightHeader.java
index 8b7e732..3ba2fc6 100644
--- a/src/main/java/org/onosproject/yangutils/utils/io/impl/CopyrightHeader.java
+++ b/src/main/java/org/onosproject/yangutils/utils/io/impl/CopyrightHeader.java
@@ -33,9 +33,11 @@
public final class CopyrightHeader {
private static final Logger log = getLogger(CopyrightHeader.class);
- private static final int NULL = -1;
+ private static final int EOF = -1;
private static ClassLoader classLoader = CopyrightHeader.class.getClassLoader();
+ private static String copyrightHeader;
+
/**
* Default constructor.
*/
@@ -43,21 +45,30 @@
}
/**
- * Returns Copyright file header.
+ * Returns copyright file header.
*
- * @return Copyright file header
+ * @return copyright file header
+ * @throws IOException when fails to parse copyright header.
*/
- public static String getCopyrightHeader() {
- return parseOnosHeader();
+ public static String getCopyrightHeader() throws IOException {
+ return copyrightHeader;
+ }
+
+ /**
+ * Sets the copyright header.
+ *
+ * @param header copyright header
+ */
+ private static void setCopyrightHeader(String header) {
+ copyrightHeader = header;
}
/**
* parse Copyright to the temporary file.
*
- * @param file generated file
- * @param stream input stream
+ * @throws IOException when fails to get the copyright header.
*/
- private static String parseOnosHeader() {
+ public static void parseCopyrightHeader() throws IOException {
File temp = new File("temp.txt");
@@ -65,17 +76,18 @@
InputStream stream = classLoader.getResourceAsStream("CopyrightHeader.txt");
OutputStream out = new FileOutputStream(temp);
int index;
- while ((index = stream.read()) != NULL) {
+ while ((index = stream.read()) != EOF) {
out.write(index);
}
out.close();
- return convertToString(temp.toString());
+ stream.close();
+ getStringFileContent(temp);
+ setCopyrightHeader(getStringFileContent(temp));
} catch (IOException e) {
- log.info("Failed to insert onos header in files.");
+ throw new IOException("failed to parse the Copyright header");
} finally {
temp.delete();
}
- return "";
}
/**
@@ -85,7 +97,8 @@
* @return string of file.
* @throws IOException when fails to convert to string
*/
- private static String convertToString(String toAppend) throws IOException {
+ private static String getStringFileContent(File toAppend) throws IOException {
+
BufferedReader bufferReader = new BufferedReader(new FileReader(toAppend));
try {
StringBuilder stringBuilder = new StringBuilder();