Skip to content

Instantly share code, notes, and snippets.

@ravibharathii
Last active April 26, 2018 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravibharathii/39bb68313e85128b250cf1b68000325f to your computer and use it in GitHub Desktop.
Save ravibharathii/39bb68313e85128b250cf1b68000325f to your computer and use it in GitHub Desktop.
Common Helper
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