Search in sources :

Example 16 with NetException

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);
    }
}
Also used : NetException(com.acgist.snail.context.exception.NetException) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 17 with NetException

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);
    }
}
Also used : NetException(com.acgist.snail.context.exception.NetException) IOException(java.io.IOException)

Example 18 with NetException

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);
    }
}
Also used : NetException(com.acgist.snail.context.exception.NetException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) Key(java.security.Key)

Aggregations

NetException (com.acgist.snail.context.exception.NetException)18 IOException (java.io.IOException)6 DownloadException (com.acgist.snail.context.exception.DownloadException)3 File (java.io.File)3 InvalidKeyException (java.security.InvalidKeyException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)3 Logger (com.acgist.snail.logger.Logger)2 LoggerFactory (com.acgist.snail.logger.LoggerFactory)2 M3u8 (com.acgist.snail.pojo.bean.M3u8)2 Type (com.acgist.snail.pojo.bean.M3u8.Type)2 StringUtils (com.acgist.snail.utils.StringUtils)2 OutputStream (java.io.OutputStream)2 Key (java.security.Key)2 Cipher (javax.crypto.Cipher)2 Test (org.junit.jupiter.api.Test)2 SymbolConfig (com.acgist.snail.config.SymbolConfig)1 NatContext (com.acgist.snail.context.NatContext)1 UpnpContext (com.acgist.snail.context.UpnpContext)1 JSON (com.acgist.snail.format.JSON)1