
de.rub.nds.tls.subject.docker.FrameHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tls-docker-library Show documentation
Show all versions of tls-docker-library Show documentation
Bill of Materials POM for the entire protocol attacker ecosystem used to keep dependencies in sync.
The newest version!
/*
* TLS-Docker-Library - A collection of open source TLS clients and servers
*
* Copyright 2017-2022 Ruhr University Bochum, Paderborn University, and Hackmanit GmbH
*
* Licensed under Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0.txt
*/
package de.rub.nds.tls.subject.docker;
import com.github.dockerjava.api.async.ResultCallbackTemplate;
import com.github.dockerjava.api.model.Frame;
import java.util.Collection;
import java.util.LinkedList;
public class FrameHandler extends ResultCallbackTemplate {
private static String[] EMPTY_STR_ARR = new String[] {};
private Collection frames;
public FrameHandler() {
frames = new LinkedList<>();
}
@Override
public void onNext(Frame object) {
synchronized (frames) {
frames.add(object);
}
}
public String[] getLines() {
Collection ret = new LinkedList<>();
boolean pending_newline = false;
StringBuilder current_line = new StringBuilder();
for (Frame frame : frames) {
for (byte b : frame.getPayload()) {
if (b == '\r') {
pending_newline = true;
} else if (b == '\n' || pending_newline) {
// handle newline
pending_newline = false;
ret.add(current_line.toString());
current_line = new StringBuilder();
if (b != '\n') {
current_line.append((char) b);
}
} else {
current_line.append((char) b);
}
}
}
if (current_line.length() > 0) {
ret.add(current_line.toString());
}
return ret.toArray(EMPTY_STR_ARR);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy