Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private List<String> readRequest(PushbackInputStream pis)
- throws IOException {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- int state = 0;
- l: while (true) {
- int b = pis.read();
- if (b == -1)
- return null;
- if (b != 13) {
- bos.write(b);
- }
- switch (state) {
- case 0:
- if (b == 13) {
- state = 1;
- } else if (b == 10)
- state = 4;
- break;
- case 1:
- if (b == 10) {
- state = 2;
- } else
- state = 0;
- break;
- case 2:
- if (b == 13) {
- state = 3;
- } else
- state = 0;
- break;
- case 3:
- if (b == 10) {
- break l;
- } else
- state = 0;
- break;
- case 4:
- if (b == 10) {
- break l;
- } else
- state = 0;
- break;
- }
- }
- byte[] request = bos.toByteArray();
- String requestStr = new String(request, StandardCharsets.US_ASCII);
- String[] split = requestStr.split("\n");
- ArrayList<String> lines = new ArrayList<>();
- for (String line : split) {
- lines.add(line);
- }
- return lines;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement