use of com.acgist.snail.context.exception.NetException in project snail by acgist.
the class HlsClient method buildOutput.
/**
* <p>新建{@linkplain #output 输出流}</p>
*
* @throws NetException 网络异常
*/
private void buildOutput() throws NetException {
try {
final int bufferSize = DownloadConfig.getMemoryBufferByte(this.size);
OutputStream outputStream;
if (this.range) {
// 支持断点续传
outputStream = new FileOutputStream(this.path, true);
} else {
// 不支持断点续传
outputStream = new FileOutputStream(this.path);
}
final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream, bufferSize);
this.output = Channels.newChannel(bufferedOutputStream);
} catch (FileNotFoundException e) {
throw new NetException("HLS客户端输出流新建失败", e);
}
}
use of com.acgist.snail.context.exception.NetException in project snail by acgist.
the class HttpClient method responseToBytes.
/**
* <p>获取响应字节数组</p>
*
* @return 响应字节数组
*
* @throws NetException 网络异常
*/
public byte[] responseToBytes() throws NetException {
final var input = this.response();
try {
final int size = input.available();
final var bytes = new byte[size];
final int length = input.read(bytes);
if (length == size) {
return bytes;
} else {
return Arrays.copyOf(bytes, length);
}
} catch (IOException e) {
throw new NetException(e);
} finally {
IoUtils.close(input);
}
}
use of com.acgist.snail.context.exception.NetException in project snail by acgist.
the class MSECipher method newRecver.
/**
* <p>新建接入客户端加解密套件</p>
*
* @param secret DH Secret
* @param infoHash InfoHash
*
* @return MSE加解密套件
*
* @throws NetException 网络异常
*/
public static final MSECipher newRecver(byte[] secret, InfoHash infoHash) throws NetException {
final Key sendKey = buildSendKey(secret, infoHash.infoHash());
final Key recvKey = buildRecvKey(secret, infoHash.infoHash());
try {
return new MSECipher(recvKey, sendKey);
} catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException e) {
throw new NetException("新建加密套件失败", e);
}
}
Aggregations