String не выводится полностью
В чем может быть причина получаю String от сервера в таком виде var text ="HTTP/1.1 3 OK\r\nConnection: close\r\ntemperature=18" хочу вывести его так System.out.println(text) но вместо целой строки выводится только HTTP/1.1 3 OK по разному пробовал не хочет выводится .
public class PoohServer {
private final HashMap<String, Service> modes = new HashMap<>();
public void start() {
modes.put("queue", new QueueService());
modes.put("topic", new TopicService());
ExecutorService pool = Executors.newFixedThreadPool(
Runtime.getRuntime().availableProcessors()
);
try (ServerSocket server = new ServerSocket(9000)) {
while (!server.isClosed()) {
Socket socket = server.accept();
pool.execute(() -> {
try (OutputStream out = socket.getOutputStream();
InputStream input = socket.getInputStream()) {
byte[] buff = new byte[1_000_000];
Thread.sleep(2000);
var total = input.read(buff);
var text = new String(Arrays.copyOfRange(buff, 0, total), StandardCharsets.UTF_8);
System.out.println(text);
var req = Req.of(text);
Resp resp = modes.get(req.method()).process(req);
String temp = ("HTTP/1.1 " + resp.status() + " OK");
out.write((temp +
System.getProperty("line.separator")).getBytes(StandardCharsets.UTF_8));
String header = "Connection: close";
out.write((header +
System.getProperty("line.separator")).getBytes(StandardCharsets.UTF_8));
String temp2 = resp.text();
out.write(temp2.getBytes());
out.flush();
System.out.println("server");
System.out.println();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
});
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new PoohServer().start();
}
}
public class PoohClient {
private static List<String> list;
private static int count;
private static void fillList() {
list = List.of("POST/queue/weather -d temperature=18", "POST/queue/dayTemperature -d temperature=28",
"POST/queue/weatherInMidNight -d temperature=8", "POST/topic/weather -d temperature=18",
"POST/queue/weatherInEvening -d temperature=10", "POST/topic/weatherDay -d temperature=28",
"POST/queue/weatherInMorning -d temperature=128", "GET/queue/weather", "GET/queue/dayTemperature",
"GET/queue/weatherInMidNight", "GET/queue/weatherInEvening", "GET/queue/weatherInMorning",
"GET/topic/weather/1", "GET/topic/weatherDay/2") ;
}
public static void main(String[] args) throws InterruptedException {
try (Socket client = new Socket("127.0.0.1", 9000)) {
fillList();
while (!client.isClosed()) {
try (OutputStream out = client.getOutputStream();
InputStream input = client.getInputStream()) {
out.write("HTTP/1.1 200 OK\r\n".getBytes());
String header = "Connection: close";
out.write(header.getBytes(StandardCharsets.UTF_8));
out.write("\r\n\r\n".getBytes());
String result = list.get(count);
if (++count > list.size()) {
count = 0;
}
out.write(result.getBytes());
out.flush();
byte[] buff = new byte[1_000_000];
//Thread.sleep(1000);
var total = input.read(buff);
var text = new String(Arrays.copyOfRange(buff, 0, total), StandardCharsets.UTF_8);
System.out.println(text);
System.out.println("client");
System.out.println();
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}