List of usage examples for io.vertx.core.parsetools RecordParser handle
void handle(Buffer buffer);
From source file:examples.ParseToolsExamples.java
License:Open Source License
public void recordParserExample1() { final RecordParser parser = RecordParser.newDelimited("\n", h -> { System.out.println(h.toString()); });//from www . j a v a2 s .com parser.handle(Buffer.buffer("HELLO\nHOW ARE Y")); parser.handle(Buffer.buffer("OU?\nI AM")); parser.handle(Buffer.buffer("DOING OK")); parser.handle(Buffer.buffer("\n")); }
From source file:org.etourdot.vertx.marklogic.http.impl.HttpPart.java
License:Open Source License
public HttpPart(Buffer bodyBuffer) { this.buffer = Buffer.buffer(); List<String> headersList = new ArrayList<>(); // We need to extract headers and content from buffer RecordParser parser = RecordParser.newDelimited("\r\n", new Handler<Buffer>() { int pos = 0; boolean startContent = false; @Override/*ww w . j av a 2s. c o m*/ public void handle(Buffer frame) { if (frame.length() == 0) { if (pos > 0) { startContent = true; } } else { if (!startContent) { headersList.add(frame.toString().trim()); } else { buffer.appendBuffer(frame); } } pos++; } }); parser.handle(bodyBuffer); this.headers = new CaseInsensitiveHeaders(); for (String header : headersList) { int offset = header.indexOf(":"); this.headers.add(header.substring(0, offset), header.substring(offset + 1).trim()); } this.contentType = HttpUtils.extractContentType(headers); this.contentDisposition = HttpUtils.extractContentDisposition(headers); }
From source file:org.etourdot.vertx.marklogic.http.impl.response.DefaultMultiPartResponse.java
License:Open Source License
private void extractParts(HttpClientResponse response, ContentType contentType) { final Map<String, List<HttpPart>> parts = new HashMap<>(); RecordParser parser = RecordParser.newDelimited("--" + contentType.getBoundary(), frame -> { if (frame.length() > 0) { HttpPart httpPart = new HttpPart(frame); if (parts.containsKey(httpPart.getDocumentUri())) { List<HttpPart> httpParts = parts.get(httpPart.getDocumentUri()); List<HttpPart> httpParts2 = new ArrayList<>(httpParts); httpParts2.add(httpPart); parts.put(httpPart.getDocumentUri(), httpParts2); } else { parts.put(httpPart.getDocumentUri(), Collections.singletonList(httpPart)); }//from w ww . java 2s .c o m } }); response.bodyHandler(buffer -> { // multipart if (contentType.getBoundary() != null) { parser.handle(buffer); } else { HttpPart httpPart = new HttpPart(buffer, response.headers()); if (httpPart.getDocumentUri() != null) { if (parts.containsKey(httpPart.getDocumentUri())) { List<HttpPart> httpParts = parts.get(httpPart.getDocumentUri()); httpParts.add(httpPart); } else { parts.put(httpPart.getDocumentUri(), Collections.singletonList(httpPart)); } } } this.documents = transformPartToDocument(parts); this.endHandler.handle(this); }); }