public class ByteUtils {
private static byte[] dataPre = null;
static {
try {
dataPre = getDataFile(new File(ByteUtils.class.getResource("icon-img.jpg").toURI()));
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
public static ByteArrayOutputStream getDate(byte[] data) {
ByteArrayOutputStream baos = null;
if (data == null) {
data = dataPre;
}
try {
baos = new ByteArrayOutputStream();
baos.write(Base64.encodeBase64(data));
} catch (IOException e) {
e.printStackTrace();
}
return baos;
}
public static byte[] getDataFile(File file) {
if (null != file) {
byte[] bFile = new byte[(int) file.length()];
try {
FileInputStream fileInputStream = new FileInputStream(file);
fileInputStream.read(bFile);
fileInputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
return bFile;
}
return null;
}
}