use of net.jpountz.lz4.LZ4BlockInputStream in project sonarqube by SonarSource.
the class FileSourceDto method decodeHugeSourceData.
private static DbFileSources.Data decodeHugeSourceData(byte[] binaryData) throws IOException {
try (LZ4BlockInputStream lz4Input = new LZ4BlockInputStream(new ByteArrayInputStream(binaryData))) {
CodedInputStream input = CodedInputStream.newInstance(lz4Input);
input.setSizeLimit(Integer.MAX_VALUE);
return DbFileSources.Data.parseFrom(input);
}
}
use of net.jpountz.lz4.LZ4BlockInputStream in project cassandra by apache.
the class IncomingTcpConnection method receiveMessages.
// Not closing constructed DataInputPlus's as the stream needs to remain open.
@SuppressWarnings("resource")
private void receiveMessages() throws IOException {
// handshake (true) endpoint versions
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
// if this version is < the MS version the other node is trying
// to connect with, the other node will disconnect
out.writeInt(MessagingService.current_version);
out.flush();
DataInputPlus in = new DataInputStreamPlus(socket.getInputStream());
int maxVersion = in.readInt();
// outbound side will reconnect if necessary to upgrade version
assert version <= MessagingService.current_version;
from = CompactEndpointSerializationHelper.deserialize(in);
// record the (true) version of the endpoint
MessagingService.instance().setVersion(from, maxVersion);
logger.trace("Set version for {} to {} (will use {})", from, maxVersion, MessagingService.instance().getVersion(from));
if (compressed) {
logger.trace("Upgrading incoming connection to be compressed");
LZ4FastDecompressor decompressor = LZ4Factory.fastestInstance().fastDecompressor();
Checksum checksum = XXHashFactory.fastestInstance().newStreamingHash32(OutboundTcpConnection.LZ4_HASH_SEED).asChecksum();
in = new DataInputStreamPlus(new LZ4BlockInputStream(socket.getInputStream(), decompressor, checksum));
} else {
ReadableByteChannel channel = socket.getChannel();
in = new NIODataInputStream(channel != null ? channel : Channels.newChannel(socket.getInputStream()), BUFFER_SIZE);
}
while (true) {
MessagingService.validateMagic(in.readInt());
receiveMessage(in, version);
}
}
use of net.jpountz.lz4.LZ4BlockInputStream 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 net.jpountz.lz4.LZ4BlockInputStream in project sonarqube by SonarSource.
the class FileSourceDto method decodeTestData.
/**
* Decompress and deserialize content of column FILE_SOURCES.BINARY_DATA.
* The parameter "input" is always closed by this method.
*/
public static List<DbFileSources.Test> decodeTestData(InputStream binaryInput) {
LZ4BlockInputStream lz4Input = null;
List<DbFileSources.Test> tests = new ArrayList<>();
try {
lz4Input = new LZ4BlockInputStream(binaryInput);
DbFileSources.Test currentTest;
do {
currentTest = DbFileSources.Test.parseDelimitedFrom(lz4Input);
if (currentTest != null) {
tests.add(currentTest);
}
} while (currentTest != null);
return tests;
} catch (IOException e) {
throw new IllegalStateException("Fail to decompress and deserialize source data", e);
} finally {
IOUtils.closeQuietly(lz4Input);
}
}
Aggregations