@@ -59,9 +59,9 @@ public static <T extends File> boolean createNewFile(T file) {
5959 * successfully created; <code>false</code> if the named file
6060 * already exists
6161 */
62- public static <T extends File > boolean deleteAndCreateNewFile (T file ){
62+ public static <T extends File > boolean deleteAndCreateNewFile (T file ) {
6363 Assert .nonNull (file , NullPointerException ::new );
64- if (file .exists ()){
64+ if (file .exists ()) {
6565 file .delete ();
6666 }
6767 return createNewFile (file );
@@ -77,10 +77,10 @@ public static <T extends File> boolean deleteAndCreateNewFile(T file){
7777 * @param data data to write to file
7878 * @param <T>
7979 */
80- public static <T extends File > void writeToFile (T file , String data ){
80+ public static <T extends File > void writeToFile (T file , String data ) {
8181 Assert .nonNull (file , NullPointerException ::new );
8282 Assert .nonNull (data , NullPointerException ::new );
83- if (!file .exists ()){
83+ if (!file .exists ()) {
8484 createNewFile (file );
8585 }
8686 try {
@@ -96,16 +96,16 @@ public static <T extends File> void writeToFile(T file, String data){
9696 * Note: This method will also creates new <code>file</code> if not exist.
9797 * Exception is logged not thrown.
9898 *
99- * @param file file to write
100- * @param data data to append to file
99+ * @param file file to write
100+ * @param data data to append to file
101101 * @param appendNewLine <code>true</code> to append new line at the end of data
102102 * otherwise <code>false</code>.
103103 * @param <T>
104104 */
105- public static <T extends File > void appendToFile (T file , String data , boolean appendNewLine ){
105+ public static <T extends File > void appendToFile (T file , String data , boolean appendNewLine ) {
106106 Assert .nonNull (file , NullPointerException ::new );
107107 Assert .nonNull (data , NullPointerException ::new );
108- if (!file .exists ()){
108+ if (!file .exists ()) {
109109 createNewFile (file );
110110 }
111111 data = appendNewLine ? (data + "\n " ) : data ;
@@ -125,9 +125,9 @@ public static <T extends File> void appendToFile(T file, String data, boolean ap
125125 * @param <T>
126126 * @return String data of file if exists otherwise <code>null</code>
127127 */
128- public static <T extends File > String readFromFile (T file ){
128+ public static <T extends File > String readFromFile (T file ) {
129129 Assert .nonNull (file , NullPointerException ::new );
130- if (file .exists ()){
130+ if (file .exists ()) {
131131 try {
132132 return new String (java .nio .file .Files .readAllBytes (getPath (file )));
133133 } catch (IOException | InvalidPathException e ) {
@@ -137,24 +137,35 @@ public static <T extends File> String readFromFile(T file){
137137 return null ;
138138 }
139139
140+ /**
141+ * Path of file provided
142+ *
143+ * @param file file to get {@link Path}.
144+ * @param <T>
145+ * @return {@link Path} of file
146+ */
147+ private static <T extends File > Path getPath (T file ) {
148+ return Paths .get (file .getAbsolutePath ());
149+ }
150+
140151 /**
141152 * Read any file from resources folder of project.
142153 * For example, read demo.json from provided path `resources folder` <code>/sample/demo.json</code>
143154 *
144155 * @param path path to resource
145156 * @return String data of file if exists otherwise <code>null</code>
146157 */
147- public String loadResource (String path ){
158+ public String loadResource (String path ) {
148159 Assert .nonNull (path , NullPointerException ::new );
149- if (!path .trim ().isEmpty ()){
150- try (
151- InputStream inputStream = getClass ().getResourceAsStream (path );
152- BufferedReader bufferedReader = new BufferedReader (new InputStreamReader (inputStream ))
153- ){
160+ if (!path .trim ().isEmpty ()) {
161+ try (
162+ InputStream inputStream = getClass ().getResourceAsStream (path );
163+ BufferedReader bufferedReader = new BufferedReader (new InputStreamReader (inputStream ))
164+ ) {
154165 String fileLine ;
155166 StringBuilder stringBuilder = new StringBuilder ();
156167
157- while ((fileLine = bufferedReader .readLine ())!= null ){
168+ while ((fileLine = bufferedReader .readLine ()) != null ) {
158169 stringBuilder .append (fileLine );
159170 }
160171 return stringBuilder .toString ();
@@ -164,15 +175,4 @@ public String loadResource(String path){
164175 }
165176 return null ;
166177 }
167-
168- /**
169- * Path of file provided
170- *
171- * @param file file to get {@link Path}.
172- * @param <T>
173- * @return {@link Path} of file
174- */
175- private static <T extends File > Path getPath (T file ){
176- return Paths .get (file .getAbsolutePath ());
177- }
178178}
0 commit comments