use of com.rebuild.core.RebuildException in project rebuild by getrebuild.
the class RebuildConfiguration method getFileOfData.
/**
* 获取数据目录下的文件(或目录)
*
* @param filepath
* @return
*/
public static File getFileOfData(String filepath) {
if (filepath != null && filepath.contains("../")) {
throw new SecurityException("Attack path detected : " + filepath);
}
String d = get(ConfigurationItem.DataDirectory);
File datadir = null;
if (StringUtils.isNotBlank(d)) {
datadir = new File(d);
if (!datadir.exists() && !datadir.mkdirs()) {
log.error("Cannot mkdir for data directory : {}", datadir);
}
}
if (datadir == null || !datadir.exists()) {
datadir = FileUtils.getUserDirectory();
datadir = new File(datadir, ".rebuild");
if (!datadir.exists() && !datadir.mkdirs()) {
log.error("Cannot mkdir for data directory : {}", datadir);
}
}
if (!datadir.exists()) {
throw new RebuildException("No data directory exists!");
}
return filepath == null ? datadir : new File(datadir, filepath);
}
use of com.rebuild.core.RebuildException in project rebuild by getrebuild.
the class BarCodeSupport method createCode.
/**
* @param content
* @param format
* @param height
* @return
*/
public static BitMatrix createCode(String content, BarcodeFormat format, int height) {
Map<EncodeHintType, Object> hints = new HashMap<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.MARGIN, 0);
// 条形码宽度为自适应
int width = format == BarcodeFormat.QR_CODE ? height : 0;
try {
return new MultiFormatWriter().encode(content, format, width, height, hints);
} catch (WriterException ex) {
throw new RebuildException("Encode BarCode error : " + content, ex);
}
}
use of com.rebuild.core.RebuildException in project rebuild by getrebuild.
the class BarCodeSupport method saveCode.
/**
* @param content
* @param format
* @param height
* @return
*/
public static File saveCode(String content, BarcodeFormat format, int height) {
BitMatrix bitMatrix = createCode(content, format, height);
String fileName = String.format("BarCode-%d.png", System.currentTimeMillis());
File dest = RebuildConfiguration.getFileOfTemp(fileName);
try {
MatrixToImageWriter.writeToPath(bitMatrix, "png", dest.toPath());
return dest;
} catch (IOException ex) {
throw new RebuildException("Write BarCode error : " + content, ex);
}
}
use of com.rebuild.core.RebuildException in project rebuild by getrebuild.
the class AES method decrypt.
/**
* @param input
* @param key
* @return
* @throws RebuildException
*/
public static String decrypt(String input, String key) throws RebuildException {
key = StringUtils.leftPad(key, 16, "0").substring(0, 16);
byte[] output;
try {
SecretKeySpec skey = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, skey);
output = cipher.doFinal(Base64.decodeBase64(input));
} catch (Exception ex) {
throw new RebuildException("Decrypting error : " + input, ex);
}
return new String(output, StandardCharsets.UTF_8);
}
use of com.rebuild.core.RebuildException in project rebuild by getrebuild.
the class AES method encrypt.
/**
* @param input
* @param key
* @return
* @throws RebuildException
*/
public static String encrypt(String input, String key) throws RebuildException {
key = StringUtils.leftPad(key, 16, "0").substring(0, 16);
byte[] crypted;
try {
SecretKeySpec skey = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, skey);
crypted = cipher.doFinal(input.getBytes(StandardCharsets.UTF_8));
} catch (Exception ex) {
throw new RebuildException("Encrypting error : " + input, ex);
}
return new String(Base64.encodeBase64(crypted), StandardCharsets.UTF_8);
}
Aggregations