net.sourceforge.plantuml.telnet.AcceptTelnetClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plantuml-mit Show documentation
Show all versions of plantuml-mit Show documentation
PlantUML is a component that allows to quickly write diagrams from text.
// THIS FILE HAS BEEN GENERATED BY A PREPROCESSOR.
package net.sourceforge.plantuml.telnet;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.SourceStringReader;
import net.sourceforge.plantuml.log.Logme;
import net.sourceforge.plantuml.utils.Log;
class AcceptTelnetClient extends Thread {
final private Socket clientSocket;
final private BufferedReader br;
final private OutputStream os;
AcceptTelnetClient(Socket socket) throws Exception {
clientSocket = socket;
System.out.println("Client Connected ...");
br = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
os = clientSocket.getOutputStream();
start();
}
public String runInternal() throws IOException {
final StringBuilder sb = new StringBuilder();
while (true) {
final String s = br.readLine();
if (s == null) {
return sb.toString();
}
Log.println("S=" + s);
sb.append(s);
sb.append('\n');
if (s.equalsIgnoreCase("@enduml")) {
return sb.toString();
}
}
}
public void run() {
try {
final String uml = runInternal();
Log.println("UML=" + uml);
final SourceStringReader s = new SourceStringReader(uml);
s.outputImage(os, new FileFormatOption(FileFormat.ATXT));
os.close();
br.close();
} catch (IOException e) {
Logme.error(e);
}
}
}