}, DEFAULT_PERIOD, DEFAULT_PERIOD, TimeUnit.MILLISECONDS);
}
protected EncryptedData encryptFile(File file) {
// 构造校验对象,这里考虑性能只将file path做为加密源
EncryptedData encryptedData = null;
try {
encryptedData = EncryptUtils.encrypt(file.getPath().getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
// ignore
}
// 写入校验信息
RandomAccessFile raf = null;
try {
raf = new RandomAccessFile(file, "rw");
long origLength = file.length();
int keyLength = ByteUtils.stringToBytes(encryptedData.getKey()).length;
int crcLength = ByteUtils.stringToBytes(encryptedData.getCrc()).length;
long totalLength = origLength + crcLength + keyLength;
raf.setLength(totalLength);
raf.seek(origLength);
raf.write(ByteUtils.stringToBytes(encryptedData.getKey()), 0, keyLength);
raf.seek(origLength + keyLength);
raf.write(ByteUtils.stringToBytes(encryptedData.getCrc()), 0, crcLength);
} catch (Exception e) {
throw new PipeException("write_encrypted_error", e);
} finally {
IOUtils.closeQuietly(raf);
}