use of io.netty.buffer.ByteBufInputStream in project netty by netty.
the class Lz4FrameEncoderTest method decompress.
@Override
protected ByteBuf decompress(ByteBuf compressed, int originalLength) throws Exception {
InputStream is = new ByteBufInputStream(compressed, true);
LZ4BlockInputStream lz4Is = null;
byte[] decompressed = new byte[originalLength];
try {
lz4Is = new LZ4BlockInputStream(is);
int remaining = originalLength;
while (remaining > 0) {
int read = lz4Is.read(decompressed, originalLength - remaining, remaining);
if (read > 0) {
remaining -= read;
} else {
break;
}
}
assertEquals(-1, lz4Is.read());
} finally {
if (lz4Is != null) {
lz4Is.close();
} else {
is.close();
}
}
return Unpooled.wrappedBuffer(decompressed);
}
use of io.netty.buffer.ByteBufInputStream in project netty by netty.
the class LzmaFrameEncoderTest method decompress.
@Override
protected ByteBuf decompress(ByteBuf compressed, int originalLength) throws Exception {
InputStream is = new ByteBufInputStream(compressed, true);
LzmaInputStream lzmaIs = null;
byte[] decompressed = new byte[originalLength];
try {
lzmaIs = new LzmaInputStream(is, new Decoder());
int remaining = originalLength;
while (remaining > 0) {
int read = lzmaIs.read(decompressed, originalLength - remaining, remaining);
if (read > 0) {
remaining -= read;
} else {
break;
}
}
assertEquals(-1, lzmaIs.read());
} finally {
if (lzmaIs != null) {
lzmaIs.close();
}
// https://github.com/jponge/lzma-java/issues/14
if (is != null) {
is.close();
}
}
return Unpooled.wrappedBuffer(decompressed);
}
use of io.netty.buffer.ByteBufInputStream in project netty by netty.
the class Bzip2EncoderTest method decompress.
@Override
protected ByteBuf decompress(ByteBuf compressed, int originalLength) throws Exception {
InputStream is = new ByteBufInputStream(compressed, true);
BZip2CompressorInputStream bzip2Is = null;
byte[] decompressed = new byte[originalLength];
try {
bzip2Is = new BZip2CompressorInputStream(is);
int remaining = originalLength;
while (remaining > 0) {
int read = bzip2Is.read(decompressed, originalLength - remaining, remaining);
if (read > 0) {
remaining -= read;
} else {
break;
}
}
assertEquals(-1, bzip2Is.read());
} finally {
if (bzip2Is != null) {
bzip2Is.close();
} else {
is.close();
}
}
return Unpooled.wrappedBuffer(decompressed);
}
use of io.netty.buffer.ByteBufInputStream in project netty by netty.
the class LzmaFrameEncoder method encode.
@Override
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
final int length = in.readableBytes();
InputStream bbIn = null;
ByteBufOutputStream bbOut = null;
try {
bbIn = new ByteBufInputStream(in);
bbOut = new ByteBufOutputStream(out);
bbOut.writeByte(properties);
bbOut.writeInt(littleEndianDictionarySize);
bbOut.writeLong(Long.reverseBytes(length));
encoder.code(bbIn, bbOut, -1, -1, null);
} finally {
if (bbIn != null) {
bbIn.close();
}
if (bbOut != null) {
bbOut.close();
}
}
}
use of io.netty.buffer.ByteBufInputStream in project netty by netty.
the class SslContext method getCertificatesFromBuffers.
private static X509Certificate[] getCertificatesFromBuffers(ByteBuf[] certs) throws CertificateException {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate[] x509Certs = new X509Certificate[certs.length];
try {
for (int i = 0; i < certs.length; i++) {
InputStream is = new ByteBufInputStream(certs[i], false);
try {
x509Certs[i] = (X509Certificate) cf.generateCertificate(is);
} finally {
try {
is.close();
} catch (IOException e) {
// This is not expected to happen, but re-throw in case it does.
throw new RuntimeException(e);
}
}
}
} finally {
for (ByteBuf buf : certs) {
buf.release();
}
}
return x509Certs;
}
Aggregations