use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class HttpParserImpl method processUntilRead.
/**
* Returns true if we split the buffers up or else false
*/
private boolean processUntilRead(MementoImpl memento, int i) {
DataWrapper dataToRead = memento.getLeftOverData();
byte firstByte = dataToRead.readByteAt(i);
byte secondByte = dataToRead.readByteAt(i + 1);
byte thirdByte = dataToRead.readByteAt(i + 2);
byte fourthByte = dataToRead.readByteAt(i + 3);
//For debugging to see the 4 bytes that we are processing easier
// log.error("This should be commented out, don't forget or we log this error");
// byte[] data = dataToRead.createByteArray();
// String fourBytesAre = conversion.convertToReadableForm(data, i, 4);
boolean isFirstCr = conversion.isCarriageReturn(firstByte);
boolean isSecondLineFeed = conversion.isLineFeed(secondByte);
boolean isThirdCr = conversion.isCarriageReturn(thirdByte);
boolean isFourthLineField = conversion.isLineFeed(fourthByte);
if (isFirstCr && isSecondLineFeed && isThirdCr && isFourthLineField) {
//Found end of http headers...
processHttpMessageAndMaybeBody(memento, dataToRead, i);
memento.setReadingHttpMessagePointer(0);
return true;
}
//mark any positions for \r\n
if (isFirstCr && isSecondLineFeed) {
memento.addDemarcation(i);
}
return false;
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class HttpParserImpl method createHttpChunk.
private HttpChunk createHttpChunk(MementoImpl memento, int i) {
DataWrapper dataToRead = memento.getLeftOverData();
//split off the header AND /r/n (ie. the +2)
List<? extends DataWrapper> split = dataGen.split(dataToRead, i + 2);
DataWrapper chunkMetaData = split.get(0);
memento.setLeftOverData(split.get(1));
List<HttpChunkExtension> extensions = new ArrayList<>();
String chunkMetaStr = chunkMetaData.createStringFrom(0, chunkMetaData.getReadableSize(), iso8859_1);
String hexSize = chunkMetaStr.trim();
if (chunkMetaStr.contains(";")) {
String[] extensionsArray = chunkMetaStr.split(";");
hexSize = extensionsArray[0];
for (int n = 1; n < extensionsArray.length; n++) {
HttpChunkExtension ext = createExtension(extensionsArray[n]);
extensions.add(ext);
}
}
int chunkSize = Integer.parseInt(hexSize, 16);
HttpChunk chunk = new HttpChunk();
if (chunkSize == 0)
chunk = new HttpLastChunk();
//must read in all the data of the chunk AND /r/n
int size = 2 + chunkSize;
memento.setNumBytesLeftToReadOnChunk(size);
return chunk;
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class MockHttp1Channel method write.
@SuppressWarnings("unchecked")
@Override
public CompletableFuture<Channel> write(ByteBuffer b) {
DataWrapper data = dataGen.wrapByteBuffer(b);
parser.parse(memento, data);
List<HttpPayload> payloads = memento.getParsedMessages();
return (CompletableFuture<Channel>) super.calledMethod(Method.INCOMING_FRAME, payloads);
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class MockHttp2Channel method sendPrefaceAndSettings.
public void sendPrefaceAndSettings(SettingsFrame settings) {
String preface = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n";
byte[] bytes = preface.getBytes(StandardCharsets.UTF_8);
DataWrapper data = parser.marshal(marshalState, settings);
DataWrapper prefaceWrapper = dataGen.wrapByteArray(bytes);
DataWrapper all = dataGen.chainDataWrappers(prefaceWrapper, data);
ByteBuffer buf = ByteBuffer.wrap(all.createByteArray());
listener.incomingData(mockHttp2Channel, buf);
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class MockHttp2Channel method send.
public void send(Http2Msg msg) {
if (listener == null)
throw new IllegalStateException("Not connected so we cannot write back");
DataWrapper data = parser.marshal(marshalState, msg);
byte[] bytes = data.createByteArray();
if (bytes.length == 0)
throw new IllegalArgumentException("how do you marshal to 0 bytes...WTF");
ByteBuffer buf = ByteBuffer.wrap(bytes);
listener.incomingData(mockHttp2Channel, buf);
}
Aggregations