Last active
April 26, 2018 12:31
-
-
Save ravibharathii/39bb68313e85128b250cf1b68000325f to your computer and use it in GitHub Desktop.
Common Helper
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
package com.webtrixs.healthcheck.helper; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileNotFoundException; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import org.apache.commons.io.FileUtils; | |
import org.apache.commons.io.IOUtils; | |
import org.springframework.util.ResourceUtils; | |
public class CommonHelper { | |
public static String readRequestFileAsStr(String filePath) throws IOException{ | |
File file = ResourceUtils.getFile("classpath:"+filePath); | |
String json = FileUtils.readFileToString(file); | |
return json; | |
} | |
public static byte[] readRequestFileAsByte(String filePath) { | |
File file = null; | |
try { | |
file = ResourceUtils.getFile("classpath:"+filePath); | |
} catch (FileNotFoundException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
InputStream is = null; | |
try { | |
is = new FileInputStream(file); | |
} catch (FileNotFoundException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
byte[] bytes = null; | |
try { | |
bytes = IOUtils.toByteArray(is); | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
}finally { | |
IOUtils.closeQuietly(is); | |
} | |
return bytes; | |
} | |
public static InputStream readRequestFileAsInputStream(String filePath) { | |
File file = null; | |
try { | |
file = ResourceUtils.getFile("classpath:"+filePath); | |
} catch (FileNotFoundException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
InputStream is = null; | |
try { | |
is = new FileInputStream(file); | |
} catch (FileNotFoundException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
return is; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment