Commit f14ff567 authored by Lubomir Bulej's avatar Lubomir Bulej
Browse files

Replace usage of the deprecated ByteString.copyTo methods

parent d7591837
......@@ -181,18 +181,15 @@ final class ConnectionHandler implements Runnable {
case INSTRUMENTATION_DELIVERY: {
final Session session = __server.getSession (request.getSessionId ());
final InstrumentationDelivery instrumentation = request.getInstrumentationDelivery ();
int sourceOffset = 0;
for (int i = 0; i < instrumentation.getSizesCount (); ++i) {
final int jarSize = instrumentation.getSizes (i);
final InstrumentationDelivery delivery = request.getInstrumentationDelivery ();
// Use byte buffer to track the source offset.
final ByteBuffer buffer = delivery.getInstrumentation ().asReadOnlyByteBuffer ();
delivery.getSizesList ().stream ().forEach (jarSize -> {
final byte [] jarBytes = new byte [jarSize];
instrumentation.getInstrumentation ().copyTo (jarBytes, sourceOffset, 0, jarSize);
buffer.get (jarBytes);
session.addJar (jarBytes);
sourceOffset += jarSize;
}
});
session.initialize ();
......
......@@ -3,10 +3,10 @@ package ch.usi.dag.server;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import com.google.protobuf.ByteString;
......@@ -15,7 +15,6 @@ import ch.usi.dag.disl.DiSL;
import ch.usi.dag.disl.DiSLException;
import ch.usi.dag.disl.InitializationException;
import ch.usi.dag.disl.JavaNames;
import ch.usi.dag.dislre.protocol.DiSL.InstrClassInfo;
import ch.usi.dag.dislre.protocol.DiSL.InstrumentClassRequest;
import ch.usi.dag.dislre.protocol.DiSL.InstrumentClassResponse;
......@@ -126,11 +125,11 @@ final class InstrumentationRequestDispatcher {
private static List <byte []> __splitBytes (
final ByteString bytes, final List <Integer> sizes
) {
// The atomic is an overkill, but it has the right interface.
final AtomicInteger sourceOffset = new AtomicInteger (0);
final ByteBuffer buffer = bytes.asReadOnlyByteBuffer ();
return sizes.stream ().map (size -> {
final byte [] chunk = new byte [size];
bytes.copyTo (chunk, sourceOffset.getAndAdd (size), 0, size);
buffer.get (chunk);
return chunk;
}).collect (toList ());
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment